Skip to content

Commit db26a8b

Browse files
committed
MAGETWO-61962: Pagination broken in the storefront category page when Flat Category is enabled
1 parent 30dc698 commit db26a8b

File tree

5 files changed

+192
-26
lines changed

5 files changed

+192
-26
lines changed

dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Product/ListProduct.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ public function getProductNames()
7070
return $productNames;
7171
}
7272

73+
/**
74+
* Get products count on page
75+
*
76+
* @return int
77+
*/
78+
public function getProductsCount()
79+
{
80+
return count($this->_rootElement->getElements($this->productItemLink));
81+
}
82+
7383
/**
7484
* Get all terms used in sort.
7585
*

dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Product/ProductList/BottomToolbar.php

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\Catalog\Test\Block\Product\ProductList;
88

99
use Magento\Mtf\Block\Block;
10+
use Magento\Mtf\Client\Locator;
1011

1112
/**
1213
* Class BottomToolbar
@@ -21,6 +22,27 @@ class BottomToolbar extends Block
2122
*/
2223
protected $nextPageSelector = '.item.current + .item a';
2324

25+
/**
26+
* Selector previous element
27+
*
28+
* @var string
29+
*/
30+
protected $previousPageSelector = '.item.pages-item-previous';
31+
32+
/**
33+
* Selector limiter block
34+
*
35+
* @var string
36+
*/
37+
protected $optionBlockSelector = '.control';
38+
39+
/**
40+
* Selector option element
41+
*
42+
* @var string
43+
*/
44+
protected $optionSelector = './/option';
45+
2446
/**
2547
* Go to the next page
2648
*
@@ -29,11 +51,55 @@ class BottomToolbar extends Block
2951
public function nextPage()
3052
{
3153
$nextPageItem = $this->_rootElement->find($this->nextPageSelector);
32-
3354
if ($nextPageItem->isVisible()) {
3455
$nextPageItem->click();
3556
return true;
3657
}
3758
return false;
3859
}
60+
61+
/**
62+
* Go to the previous page
63+
*
64+
* @return bool
65+
*/
66+
public function previousPage()
67+
{
68+
$previousPageItem = $this->_rootElement->find($this->previousPageSelector);
69+
if ($previousPageItem->isVisible()) {
70+
$previousPageItem->click();
71+
return true;
72+
}
73+
return false;
74+
}
75+
76+
/**
77+
* Set value for limiter element by index
78+
*
79+
* @param int $index
80+
* @return $this
81+
*/
82+
public function setLimiterValueByIndex($index)
83+
{
84+
$options = $this->_rootElement->getElements($this->optionSelector, Locator::SELECTOR_XPATH);
85+
if (isset($options[$index])) {
86+
$options[$index]->click();
87+
}
88+
return $this;
89+
}
90+
91+
/**
92+
* Get value for limiter element by index
93+
*
94+
* @param int $index
95+
* @return int|null
96+
*/
97+
public function getLimitedValueByIndex($index)
98+
{
99+
$options = $this->_rootElement->getElements($this->optionSelector, Locator::SELECTOR_XPATH);
100+
if (isset($options[$index])) {
101+
return $options[$index]->getValue();
102+
}
103+
return null;
104+
}
39105
}

dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertPaginationCorrectOnStoreFront.php

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,86 @@
66

77
namespace Magento\Catalog\Test\Constraint;
88

9+
use Magento\Catalog\Test\Page\Category\CatalogCategoryView;
910
use Magento\Mtf\Client\BrowserInterface;
1011
use Magento\Mtf\Constraint\AbstractConstraint;
1112
use Magento\Catalog\Test\Fixture\Category;
1213

14+
/**
15+
* Checks pagination of storefront for correct pagination and list of products
16+
*/
1317
class AssertPaginationCorrectOnStoreFront extends AbstractConstraint
1418
{
1519
/* tags */
1620
const SEVERITY = 'low';
1721
/* end tags */
1822

1923
/**
24+
* Checks pagination of storefront for correct pagination and list of products
25+
*
2026
* @param BrowserInterface $browser
2127
* @param Category $category
28+
* @param CatalogCategoryView $catalogCategoryView
29+
* @param int $productsCount
30+
* @return void
2231
*/
23-
public function processAssert(BrowserInterface $browser, Category $category)
24-
{
32+
public function processAssert(
33+
BrowserInterface $browser,
34+
Category $category,
35+
CatalogCategoryView $catalogCategoryView,
36+
$productsCount
37+
) {
2538
$browser->open($_ENV['app_frontend_url'] . $category->getUrlKey() . '.html');
39+
\PHPUnit_Framework_Assert::assertEquals(
40+
true,
41+
$catalogCategoryView->getBottomToolbar()->isVisible(),
42+
'Pagination is not visible'
43+
);
44+
\PHPUnit_Framework_Assert::assertEquals(
45+
$catalogCategoryView->getBottomToolbar()->getLimitedValueByIndex(0),
46+
$catalogCategoryView->getListProductBlock()->getProductsCount(),
47+
'Count of products on 1 page does not equivalent with declared in pagination (default value)'
48+
);
49+
$catalogCategoryView->getBottomToolbar()->nextPage();
50+
\PHPUnit_Framework_Assert::assertEquals(
51+
$this->calculateExpectedProductsCountOnPage(
52+
$catalogCategoryView->getBottomToolbar()->getLimitedValueByIndex(0),
53+
2,
54+
$productsCount
55+
),
56+
$catalogCategoryView->getListProductBlock()->getProductsCount(),
57+
'Count of products on 2 page does not equivalent with declared in pagination (default value)'
58+
);
59+
$catalogCategoryView->getBottomToolbar()->previousPage();
60+
$catalogCategoryView->getBottomToolbar()->setLimiterValueByIndex(1);
61+
\PHPUnit_Framework_Assert::assertEquals(
62+
$catalogCategoryView->getBottomToolbar()->getLimitedValueByIndex(1),
63+
$catalogCategoryView->getListProductBlock()->getProductsCount(),
64+
'Count of products on 1 page does not equivalent with declared in pagination(custom value)'
65+
);
66+
$catalogCategoryView->getBottomToolbar()->nextPage();
67+
\PHPUnit_Framework_Assert::assertEquals(
68+
$this->calculateExpectedProductsCountOnPage(
69+
$catalogCategoryView->getBottomToolbar()->getLimitedValueByIndex(1),
70+
2,
71+
$productsCount
72+
),
73+
$catalogCategoryView->getListProductBlock()->getProductsCount(),
74+
'Count of products on 2 page does not equivalent with declared in pagination(custom value)'
75+
);
76+
}
77+
78+
/**
79+
* Calculate expected count of products on current page
80+
*
81+
* @param int $productsPerPage
82+
* @param int $numberOfPage
83+
* @param int $totalProductsCount
84+
* @return int
85+
*/
86+
private function calculateExpectedProductsCountOnPage($productsPerPage, $numberOfPage, $totalProductsCount)
87+
{
88+
return min($productsPerPage, $totalProductsCount - $productsPerPage * ($numberOfPage - 1));
2689
}
2790

2891
/**
@@ -32,6 +95,6 @@ public function processAssert(BrowserInterface $browser, Category $category)
3295
*/
3396
public function toString()
3497
{
35-
return 'Attribute is visible with HTML tags on frontend.';
98+
return 'Pagination is correct on frontend.';
3699
}
37100
}

dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/CreateFlatCatalogProduct.php

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,26 @@
66

77
namespace Magento\Catalog\Test\TestCase\Product;
88

9+
use Magento\Config\Test\TestStep\SetupConfigurationStep;
10+
use Magento\Catalog\Test\Page\Category\CatalogCategoryView;
911
use Magento\Mtf\Fixture\FixtureFactory;
1012
use Magento\Mtf\TestCase\Injectable;
1113
use Magento\Catalog\Test\Fixture\Category;
1214

15+
/**
16+
* Preconditions:
17+
* 1. Use Flat Catalog Category & Use Flat Catalog Product are enabled (Store/Configuration/Catalog/Catalog/Storefront)
18+
*
19+
* Steps:
20+
* 1. Assign 16 or more products to the same category (e.g. 20 products)
21+
* 2. Go to Storefront and navigate to this category
22+
* 3. Click on Page 2 or any further page
23+
* 4. Go back to page 1 and change № of products per page from 9 to any number (e.g 12)
24+
* 5. Click on Page 2 or any further page
25+
* 5. Perform assertions.
26+
*
27+
* @ZephyrId MAGETWO-67570
28+
*/
1329
class CreateFlatCatalogProduct extends Injectable
1430
{
1531
/* tags */
@@ -37,6 +53,13 @@ class CreateFlatCatalogProduct extends Injectable
3753
*/
3854
protected $category;
3955

56+
/**
57+
* CatalogCategoryView page
58+
*
59+
* @var CatalogCategoryView
60+
*/
61+
protected $catalogCategoryView;
62+
4063
/**
4164
* Prepare data
4265
*
@@ -56,28 +79,32 @@ public function __prepare(Category $category)
5679
*
5780
* @param Category $category
5881
* @param FixtureFactory $fixtureFactory
82+
* @param CatalogCategoryView $catalogCategoryView
5983
* @return void
6084
*/
6185
public function __inject(
6286
Category $category,
63-
FixtureFactory $fixtureFactory
87+
FixtureFactory $fixtureFactory,
88+
CatalogCategoryView $catalogCategoryView
6489
) {
6590
$this->category = $category;
6691
$this->fixtureFactory = $fixtureFactory;
92+
$this->catalogCategoryView = $catalogCategoryView;
6793
}
6894

6995
/**
70-
* Run mass update product simple entity test.
96+
* Run create flat catalog product
7197
*
7298
* @param string $configData
7399
* @param string $productsCount
74100
* @return array
75101
*/
76102
public function test($configData, $productsCount)
77103
{
104+
$this->objectManager->create(SetupConfigurationStep::class, ['configData' => $this->configData])->run();
78105
$this->createBulkOfProducts($productsCount);
79106
$this->configData = $configData;
80-
return ['category' => $this->category];
107+
return ['category' => $this->category, 'catalogCategoryView' => $this->catalogCategoryView];
81108
}
82109

83110
/**
@@ -88,20 +115,20 @@ public function test($configData, $productsCount)
88115
public function tearDown()
89116
{
90117
$this->objectManager->create(
91-
\Magento\Config\Test\TestStep\SetupConfigurationStep::class,
118+
SetupConfigurationStep::class,
92119
['configData' => $this->configData, 'rollback' => true]
93120
)->run();
94121
}
95122

96123
/**
124+
* Create products for tests
125+
*
97126
* @param $productsCount
127+
* @return void
98128
*/
99129
private function createBulkOfProducts($productsCount)
100130
{
101131
foreach (range(1, $productsCount) as $element) {
102-
/**
103-
* @product FixtureInterface
104-
*/
105132
$product = $this->fixtureFactory->createByCode(
106133
'catalogProductSimple',
107134
[
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<!--
3-
/**
4-
* Copyright © Magento, Inc. All rights reserved.
5-
* See COPYING.txt for license details.
6-
*/
7-
-->
8-
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../vendor/magento/mtf/etc/variations.xsd">
9-
<testCase name="Magento\Catalog\Test\TestCase\Product\CreateFlatCatalogProduct" summary="Create flat catalog Product" ticketId="MAGETWO-67570">
10-
<variation name="CheckPaginationInStorefront">
11-
<data name="configData" xsi:type="string">category_flat,product_flat</data>
12-
<data name="productsCount" xsi:type="number">2</data>
13-
<constraint name="Magento\Catalog\Test\Constraint\AssertPaginationCorrectOnStoreFront" />
14-
</variation>
15-
</testCase>
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../vendor/magento/mtf/etc/variations.xsd">
9+
<testCase name="Magento\Catalog\Test\TestCase\Product\CreateFlatCatalogProduct" summary="Create flat catalog Product" ticketId="MAGETWO-67570">
10+
<variation name="CheckPaginationInStorefront">
11+
<data name="configData" xsi:type="string">category_flat,product_flat</data>
12+
<data name="productsCount" xsi:type="number">19</data>
13+
<constraint name="Magento\Catalog\Test\Constraint\AssertPaginationCorrectOnStoreFront" />
14+
</variation>
15+
</testCase>
1616
</config>

0 commit comments

Comments
 (0)