Skip to content

Commit c052e22

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-61962' into NORD-PR-INTERNAL
2 parents e0bd129 + eebda3b commit c052e22

File tree

6 files changed

+341
-3
lines changed

6 files changed

+341
-3
lines changed

app/code/Magento/Bundle/Model/ResourceModel/Selection/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ public function addPriceFilter($product, $searchMin, $useRegularPrice = false)
295295
if ($product->getPriceType() == \Magento\Bundle\Model\Product\Price::PRICE_TYPE_DYNAMIC) {
296296
$this->addPriceData();
297297
if ($useRegularPrice) {
298-
$minimalPriceExpression = 'price';
298+
$minimalPriceExpression = self::INDEX_TABLE_ALIAS . '.price';
299299
} else {
300300
$this->getCatalogRuleProcessor()->addPriceData($this, 'selection.product_id');
301301
$minimalPriceExpression = 'LEAST(minimal_price, IFNULL(catalog_rule_price, minimal_price))';

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: 68 additions & 2 deletions
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
@@ -19,7 +20,28 @@ class BottomToolbar extends Block
1920
*
2021
* @var string
2122
*/
22-
protected $nextPageSelector = '.item.current + .item a';
23+
private $nextPageSelector = '.item.current + .item a';
24+
25+
/**
26+
* Selector previous element
27+
*
28+
* @var string
29+
*/
30+
private $previousPageSelector = '.item.pages-item-previous';
31+
32+
/**
33+
* Selector limiter block
34+
*
35+
* @var string
36+
*/
37+
private $optionBlockSelector = '.control';
38+
39+
/**
40+
* Selector option element
41+
*
42+
* @var string
43+
*/
44+
private $optionSelector = './/option';
2345

2446
/**
2547
* Go to the next page
@@ -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
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Test\Constraint;
8+
9+
use Magento\Catalog\Test\Page\Category\CatalogCategoryView;
10+
use Magento\Mtf\Client\BrowserInterface;
11+
use Magento\Mtf\Constraint\AbstractConstraint;
12+
use Magento\Catalog\Test\Fixture\Category;
13+
14+
/**
15+
* Checks pagination of storefront for correct pagination and list of products
16+
*/
17+
class AssertPaginationCorrectOnStoreFront extends AbstractConstraint
18+
{
19+
/* tags */
20+
const SEVERITY = 'low';
21+
/* end tags */
22+
23+
/**
24+
* Checks pagination of storefront for correct pagination and list of products
25+
*
26+
* @param BrowserInterface $browser
27+
* @param Category $category
28+
* @param CatalogCategoryView $catalogCategoryView
29+
* @param int $productsCount
30+
* @return void
31+
*/
32+
public function processAssert(
33+
BrowserInterface $browser,
34+
Category $category,
35+
CatalogCategoryView $catalogCategoryView,
36+
$productsCount
37+
) {
38+
$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));
89+
}
90+
91+
/**
92+
* Return string representation of object.
93+
*
94+
* @return string
95+
*/
96+
public function toString()
97+
{
98+
return 'Pagination is correct on frontend.';
99+
}
100+
}
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Test\TestCase\Product;
8+
9+
use Magento\Config\Test\TestStep\SetupConfigurationStep;
10+
use Magento\Catalog\Test\Page\Category\CatalogCategoryView;
11+
use Magento\Mtf\Fixture\FixtureFactory;
12+
use Magento\Mtf\TestCase\Injectable;
13+
use Magento\Catalog\Test\Fixture\Category;
14+
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+
*/
29+
class CreateFlatCatalogProduct extends Injectable
30+
{
31+
/* tags */
32+
const MVP = 'yes';
33+
/* end tags */
34+
35+
/**
36+
* Configuration data
37+
*
38+
* @var string
39+
*/
40+
private $configData;
41+
42+
/**
43+
* Factory for Fixtures
44+
*
45+
* @var FixtureFactory
46+
*/
47+
private $fixtureFactory;
48+
49+
/**
50+
* Category fixture
51+
*
52+
* @var Category
53+
*/
54+
private $category;
55+
56+
/**
57+
* CatalogCategoryView page
58+
*
59+
* @var CatalogCategoryView
60+
*/
61+
private $catalogCategoryView;
62+
63+
/**
64+
* Prepare data
65+
*
66+
* @param Category $category
67+
* @return array
68+
*/
69+
public function __prepare(Category $category)
70+
{
71+
$category->persist();
72+
return [
73+
'category' => $category
74+
];
75+
}
76+
77+
/**
78+
* Injection data
79+
*
80+
* @param Category $category
81+
* @param FixtureFactory $fixtureFactory
82+
* @param CatalogCategoryView $catalogCategoryView
83+
* @return void
84+
*/
85+
public function __inject(
86+
Category $category,
87+
FixtureFactory $fixtureFactory,
88+
CatalogCategoryView $catalogCategoryView
89+
) {
90+
$this->category = $category;
91+
$this->fixtureFactory = $fixtureFactory;
92+
$this->catalogCategoryView = $catalogCategoryView;
93+
}
94+
95+
/**
96+
* Run create flat catalog product
97+
*
98+
* @param string $configData
99+
* @param string $productsCount
100+
* @return array
101+
*/
102+
public function test($configData, $productsCount)
103+
{
104+
$this->objectManager->create(SetupConfigurationStep::class, ['configData' => $this->configData])->run();
105+
$this->createBulkOfProducts($productsCount);
106+
$this->configData = $configData;
107+
return ['category' => $this->category, 'catalogCategoryView' => $this->catalogCategoryView];
108+
}
109+
110+
/**
111+
* Clear data after test
112+
*
113+
* @return void
114+
*/
115+
public function tearDown()
116+
{
117+
$this->objectManager->create(
118+
SetupConfigurationStep::class,
119+
['configData' => $this->configData, 'rollback' => true]
120+
)->run();
121+
}
122+
123+
/**
124+
* Create products for tests
125+
*
126+
* @param $productsCount
127+
* @return void
128+
*/
129+
private function createBulkOfProducts($productsCount)
130+
{
131+
for ($counter = 1; $counter <= $productsCount; $counter++) {
132+
$product = $this->fixtureFactory->createByCode(
133+
'catalogProductSimple',
134+
[
135+
'dataset' => 'default',
136+
'data' => [
137+
'category_ids' => [
138+
'category' => $this->category
139+
]
140+
]
141+
]
142+
);
143+
$product->persist();
144+
}
145+
}
146+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +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" ticketId="MAGETWO-67570">
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>
16+
</config>

0 commit comments

Comments
 (0)