Skip to content

Commit 82c4da0

Browse files
committed
ACQE-7447: Apply Catalog Storefront configuration settings
- New automation testfile has been added
1 parent 2433855 commit 82c4da0

File tree

3 files changed

+224
-3
lines changed

3 files changed

+224
-3
lines changed

app/code/Magento/Catalog/Test/Mftf/Helper/ProductApiHelper.php

Lines changed: 117 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@
77

88
namespace Magento\Catalog\Test\Mftf\Helper;
99

10+
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\DataObjectHandler;
11+
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\PersistedObjectHandler;
1012
use Magento\FunctionalTestingFramework\DataGenerator\Persist\CurlHandler;
1113
use Magento\FunctionalTestingFramework\DataGenerator\Objects\EntityDataObject;
14+
use Magento\FunctionalTestingFramework\DataGenerator\Persist\DataPersistenceHandler;
1215
use Magento\FunctionalTestingFramework\Helper\Helper;
1316
use Magento\FunctionalTestingFramework\ObjectManagerFactory;
1417

1518
/**
16-
* This helper use to delete all available products:
19+
* This helper use to create/delete products:
1720
*
1821
* - CurlHandler::executeRequest() for all API calls
1922
* - Operation definitions from ProductMeta.xml
@@ -23,6 +26,117 @@
2326
*/
2427
class ProductApiHelper extends Helper
2528
{
29+
/**
30+
* Create products using the ACTUAL category entity object as dependent object.
31+
*
32+
* @param string $categoryStepKey
33+
* @param int $count
34+
* @param int $quantity
35+
* @param string $entityType
36+
* @return array
37+
* @throws \Exception
38+
*/
39+
public function createProduct(
40+
string $categoryStepKey,
41+
int $count = 1,
42+
int $quantity = 100,
43+
string $entityType = 'ApiSimpleProduct'
44+
): array {
45+
$createdSkus = [];
46+
$timestamp = time();
47+
48+
for ($i = 1; $i <= $count; $i++) {
49+
try {
50+
// Get the predefined product entity from MFTF (now dynamic!)
51+
$apiProductEntity = DataObjectHandler::getInstance()->getObject($entityType);
52+
53+
if ($apiProductEntity === null) {
54+
continue; // Skip this iteration if entity not found
55+
}
56+
57+
// Create unique SKU and name for this product
58+
$uniqueSku = strtolower(str_replace('Api', '', $entityType)). '-' . $timestamp . '_' . $i;
59+
$uniqueName = str_replace('Api', '', $entityType) . $timestamp . '_' . $i;
60+
61+
// Override fields - this is how MFTF handles custom values
62+
$overrideFields = [
63+
'sku' => $uniqueSku,
64+
'name' => $uniqueName,
65+
'quantity' => $quantity // Override the default quantity (100) with our value
66+
];
67+
68+
// THIS IS YOUR VISION: Use actual entity object as dependent object!
69+
$dependentObjects = [];
70+
$categoryEntityObject = $this->getCategoryEntity($categoryStepKey);
71+
if ($categoryEntityObject !== null) {
72+
$dependentObjects[] = $categoryEntityObject;
73+
}
74+
75+
// Use MFTF's native DataPersistenceHandler with ACTUAL entity object
76+
$persistenceHandler = new DataPersistenceHandler(
77+
$apiProductEntity,
78+
$dependentObjects, // Pass the ACTUAL category entity object
79+
$overrideFields
80+
);
81+
82+
// Create the entity using MFTF's native mechanism
83+
$persistenceHandler->createEntity();
84+
85+
// Get the created object to extract the SKU
86+
$createdObject = $persistenceHandler->getCreatedObject();
87+
if ($createdObject && isset($createdObject->getAllData()['sku'])) {
88+
$createdSkus[] = $createdObject->getAllData()['sku'];
89+
} else {
90+
$createdSkus[] = $uniqueSku; // Fallback to our generated SKU
91+
}
92+
93+
usleep(100000);
94+
95+
} catch (\Exception $e) {
96+
// Log error and continue with fallback SKU
97+
error_log("Product creation failed : " . $e->getMessage());
98+
}
99+
}
100+
return $createdSkus;
101+
}
102+
103+
/**
104+
* Create products using MFTF's native product entities with ACTUAL category entity object.
105+
*
106+
* @param string $categoryStepKey
107+
* @return DataPersistenceHandler|null
108+
*/
109+
private function getCategoryEntity(string $categoryStepKey): DataPersistenceHandler
110+
{
111+
$actualCategoryEntityObject = null;
112+
113+
// Try to get the actual category entity object using reflection
114+
if ($categoryStepKey) {
115+
try {
116+
$persistedHandler = PersistedObjectHandler::getInstance();
117+
118+
// Use reflection to access the private retrieveEntity method
119+
$reflection = new \ReflectionClass($persistedHandler);
120+
$retrieveEntityMethod = $reflection->getMethod('retrieveEntity');
121+
$retrieveEntityMethod->setAccessible(true);
122+
123+
// Call the private method to get the actual DataPersistenceHandler object
124+
$actualCategoryEntityObject = $retrieveEntityMethod->invoke(
125+
$persistedHandler,
126+
$categoryStepKey,
127+
'test'
128+
);
129+
} catch (\Exception $e) {
130+
// Exception in retrieving category entity object, continue without category
131+
error_log(
132+
"Failed to retrieve category entity while creating product for stepKey '{$categoryStepKey}': " .
133+
$e->getMessage()
134+
);
135+
}
136+
}
137+
return $actualCategoryEntityObject;
138+
}
139+
26140
/**
27141
* Delete all products using ONLY MFTF CurlHandler
28142
*
@@ -193,8 +307,8 @@ private function validateStringResponse(string $response): bool
193307
$jsonData = json_decode($response, true);
194308
if (json_last_error() === JSON_ERROR_NONE) {
195309
return ($jsonData === true ||
196-
($jsonData['success'] ?? false) ||
197-
($jsonData['status'] ?? '') === 'success');
310+
($jsonData['success'] ?? false) ||
311+
($jsonData['status'] ?? '') === 'success');
198312
}
199313

200314
// Plain text fallback

app/code/Magento/Catalog/Test/Mftf/Section/AdminCatalogStorefrontConfigSection.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@
1212
<element name="sectionHeader" type="button" selector="#catalog_frontend-head"/>
1313
<element name="productsPerPageAllowedValues" type="input" selector="#catalog_frontend_grid_per_page_values"/>
1414
<element name="productsPerPageDefaultValue" type="input" selector="#catalog_frontend_grid_per_page"/>
15+
<element name="productsPerPageAllowedValuesForList" type="input" selector="#catalog_frontend_list_per_page_values"/>
16+
<element name="productsPerPageDefaultValueForList" type="input" selector="#catalog_frontend_list_per_page"/>
17+
<element name="advancedInventoryBtn" type="button" selector="//li[contains(@aria-labelledby, 'attributes_update_tabs_inventory')]"/>
1518
</section>
1619
</sections>
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright 2025 Adobe
5+
* All Rights Reserved.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="StorefrontAssertProductCountInListAndGridViewTest">
12+
<annotations>
13+
<features value="Catalog"/>
14+
<stories value="Apply catalog storefront configuration settings"/>
15+
<title value="Verify Product Count Display in List and Grid Views After Storefront Catalog Configuration Changes"/>
16+
<description value="Admin should apply catalog storefront configuration settings and verify the products in storefront based on configuration"/>
17+
<severity value="BLOCKER"/>
18+
<testCaseId value="AC-5027"/>
19+
<group value="Catalog"/>
20+
</annotations>
21+
<before>
22+
<createData entity="SimpleSubCategory" stepKey="createCategory"/>
23+
24+
<helper class="\Magento\Catalog\Test\Mftf\Helper\ProductApiHelper" method="createProduct" stepKey="createProducts">
25+
<argument name="categoryStepKey">createCategory</argument>
26+
<argument name="count">12</argument>
27+
</helper>
28+
<!-- Login as admin -->
29+
<actionGroup ref="AdminLoginActionGroup" stepKey="login"/>
30+
</before>
31+
<after>
32+
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
33+
<!-- Set Default Values in Configuration -->
34+
<magentoCLI command="config:set {{DefaultListMode.path}} {{DefaultListMode.value}}" stepKey="setListMode1"/>
35+
<magentoCLI command="config:set {{DefaultGridPerPageValuesConfigData.path}} {{DefaultGridPerPageValuesConfigData.value}}" stepKey="setDefaultGridPerPageValues"/>
36+
<magentoCLI command="config:set {{DefaultGridPerPageDefaultConfigData.path}} {{DefaultGridPerPageDefaultConfigData.value}}" stepKey="setDefaultGridPerPage"/>
37+
<magentoCLI command="config:set {{DefaultStoreFrontListPerPageValuesConfigData.path}} {{DefaultStoreFrontListPerPageValuesConfigData.value}}" stepKey="setDefaultListPerPageValues"/>
38+
<magentoCLI command="config:set {{DefaultStoreFrontListPerPageConfigData.path}} {{DefaultStoreFrontListPerPageConfigData.value}}" stepKey="setDefaultListPerPage"/>
39+
<magentoCLI command="config:set {{DefaultStoreFrontProductsSortBy.path}} {{DefaultStoreFrontProductsSortBy.value}}" stepKey="setDefaultProductSortBy"/>
40+
<magentoCLI command="config:set {{DefaultStoreFrontAllProductsPerPage.path}} {{DefaultStoreFrontAllProductsPerPage.value}}" stepKey="setDefaultAllProductsPerPage"/>
41+
<!-- Delete simple product created via API -->
42+
<helper class="Magento\Catalog\Test\Mftf\Helper\ProductApiHelper" method="deleteAllProductsApi" stepKey="deleteAllProductsViaApi"/>
43+
<!-- Log out -->
44+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
45+
</after>
46+
<!-- Step 1&2: Open Admin > Stores > Configuration > Catalog > Catalog > Storefront & Save the following settings -->
47+
<magentoCLI command="config:set {{CustomListMode.path}} {{CustomListMode.value}}" stepKey="setListMode"/>
48+
<magentoCLI command="config:set {{CustomStoreFrontGridPerPageValuesConfigData.path}} {{CustomStoreFrontGridPerPageValuesConfigData.value}}" stepKey="setCustomGridPerPageValues"/>
49+
<magentoCLI command="config:set {{CustomStoreFrontGridPerPageConfigData.path}} {{CustomStoreFrontGridPerPageConfigData.value}}" stepKey="setCustomGridPerPage"/>
50+
<magentoCLI command="config:set {{CustomStoreFrontListPerPageValuesConfigData.path}} {{CustomStoreFrontListPerPageValuesConfigData.value}}" stepKey="setCustomListPerPageValues"/>
51+
<magentoCLI command="config:set {{CustomStoreFrontListPerPageConfigData.path}} {{CustomStoreFrontListPerPageConfigData.value}}" stepKey="setCustomListPerPage"/>
52+
<magentoCLI command="config:set {{CustomStoreFrontProductsSortBy.path}} {{CustomStoreFrontProductsSortBy.value}}" stepKey="setProductSortBy"/>
53+
<magentoCLI command="config:set {{CustomStoreFrontAllProductsPerPage.path}} {{CustomStoreFrontAllProductsPerPage.value}}" stepKey="setAllProductsPerPage"/>
54+
<!-- Step 3: Open a category page on Storefront that has more than 10 products -->
55+
<actionGroup ref="StorefrontNavigateCategoryPageActionGroup" stepKey="navigateToCategoryPage1">
56+
<argument name="category" value="$$createCategory$$"/>
57+
</actionGroup>
58+
<!-- Step 4&5: Select All products & Switch to Grid view -->
59+
<waitForElementVisible selector="{{AdminChecksListAndGridModeSection.listView}}" stepKey="seePageInListView"/>
60+
<scrollTo selector="{{AdminChecksListAndGridModeSection.gridMode}}" stepKey="scrollToGridMode"/>
61+
<waitForElementClickable selector="{{AdminChecksListAndGridModeSection.gridMode}}" stepKey="waitToClickGridMode"/>
62+
<click selector="{{AdminChecksListAndGridModeSection.gridMode}}" stepKey="clickGridMode"/>
63+
<waitForPageLoad stepKey="waitForGridMode"/>
64+
<waitForElementVisible selector="{{AdminChecksListAndGridModeSection.listView}}" stepKey="seePageInGridView"/>
65+
<waitForElementClickable selector="{{AdminChecksListAndGridModeSection.listView}}" stepKey="waitToClickListMode"/>
66+
<click selector="{{AdminChecksListAndGridModeSection.listView}}" stepKey="clickListMode"/>
67+
<waitForPageLoad stepKey="waitForListMode"/>
68+
<seeElement selector="{{StorefrontCategoryMainSection.productLink}}" stepKey="seeAnyProductOnPage"/>
69+
<seeOptionIsSelected userInput="{{CustomStoreFrontProductsSortBy.value}}" selector="{{StorefrontCategoryTopToolbarSection.sortByDropdown}}" after="seeAnyProductOnPage" stepKey="selectSortBy"/>
70+
<waitForElementClickable selector="{{AdminChecksListAndGridModeSection.productsPerPage}}" stepKey="waitToClickProductsPerPageButtonInListMode"/>
71+
<click selector="{{AdminChecksListAndGridModeSection.productsPerPage}}" stepKey="clickProductsPerPageButtonInListMode"/>
72+
<waitForPageLoad stepKey="waitForProductsPerPage"/>
73+
<seeElement selector="{{AdminChecksListAndGridModeSection.pageOptions('1')}}" stepKey="seeLimiterOption1"/>
74+
<seeElement selector="{{AdminChecksListAndGridModeSection.pageOptions('2')}}" stepKey="seeLimiterOption2"/>
75+
<seeElement selector="{{AdminChecksListAndGridModeSection.pageOptions('3')}}" stepKey="seeLimiterOption3"/>
76+
<waitForElementVisible selector="{{AdminChecksListAndGridModeSection.allButton}}" stepKey="seeAllButton"/>
77+
<click selector="{{AdminChecksListAndGridModeSection.allButton}}" stepKey="selectAllButton"/>
78+
<waitForPageLoad stepKey="waitForSelectAll"/>
79+
<waitForElementVisible selector="{{AdminChecksListAndGridModeSection.allProducts}}" stepKey="seeAllProducts"/>
80+
<waitForElementClickable selector="{{AdminChecksListAndGridModeSection.gridMode}}" stepKey="waitToSwitchToGridMode"/>
81+
<click selector="{{AdminChecksListAndGridModeSection.gridMode}}" stepKey="switchToGridMode"/>
82+
<waitForElementVisible selector="{{AdminChecksListAndGridModeSection.gridView}}" stepKey="seePageInGridView2"/>
83+
<waitForElementClickable selector="{{StorefrontCategoryProductSection.categoryListView}}" stepKey="waitToSwitchToListMode1"/>
84+
<click selector="{{StorefrontCategoryProductSection.categoryListView}}" stepKey="switchToListMode1"/>
85+
<waitForElementVisible selector="{{AdminChecksListAndGridModeSection.listView}}" stepKey="seePageInListView1"/>
86+
<waitForElementClickable selector="{{AdminChecksListAndGridModeSection.gridMode}}" stepKey="waitToSwitchToGridMode1"/>
87+
<click selector="{{AdminChecksListAndGridModeSection.gridMode}}" stepKey="switchToGridMode1"/>
88+
<seeOptionIsSelected userInput="{{CustomStoreFrontProductsSortBy.value}}" selector="{{StorefrontCategoryTopToolbarSection.sortByDropdown}}" after="switchToGridMode1" stepKey="selectSortByPrice"/>
89+
<waitForElementClickable selector="{{AdminChecksListAndGridModeSection.productsPerPage}}" stepKey="waitToClickProductsPerPageButtonInGridMode"/>
90+
<click selector="{{AdminChecksListAndGridModeSection.productsPerPage}}" stepKey="clickProductsPerPageButtonInGridMode"/>
91+
<waitForPageLoad stepKey="waitForProductsPerPageOpen"/>
92+
<seeElement selector="{{AdminChecksListAndGridModeSection.pageOptions('1')}}" stepKey="seeLimiterOption1Grid"/>
93+
<seeElement selector="{{AdminChecksListAndGridModeSection.pageOptions('2')}}" stepKey="seeLimiterOption2Grid"/>
94+
<seeElement selector="{{AdminChecksListAndGridModeSection.pageOptions('3')}}" stepKey="seeLimiterOption3Grid"/>
95+
<waitForElementVisible selector="{{AdminChecksListAndGridModeSection.allButton}}" stepKey="seeAllBtn"/>
96+
<!-- Step 6: Open the same category again from navigation menu. Switch to Grid mode. -->
97+
<actionGroup ref="StorefrontNavigateCategoryPageActionGroup" stepKey="navigateToCategoryPage2">
98+
<argument name="category" value="$$createCategory$$"/>
99+
</actionGroup>
100+
<waitForElementClickable selector="{{AdminChecksListAndGridModeSection.gridMode}}" stepKey="waitToSwitchToGridMode4"/>
101+
<click selector="{{AdminChecksListAndGridModeSection.gridMode}}" stepKey="switchAgainToGridMode"/>
102+
<seeNumberOfElements selector="{{AdminChecksListAndGridModeSection.productCount}}" userInput="10" stepKey="seeNumberOfProductsDisplayed"/>
103+
</test>
104+
</tests>

0 commit comments

Comments
 (0)