Skip to content

Commit 84dc9ff

Browse files
authored
Merge pull request #5566 from magento-chaika/PR-Chaika-2020-04-08
[chaika] MC-32335: MFTF Test- Customer Review Grid Filter Not working
2 parents 1d6b296 + 8c424e8 commit 84dc9ff

File tree

26 files changed

+520
-171
lines changed

26 files changed

+520
-171
lines changed

app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontAssertProductInWidgetActionGroup.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,18 @@
3333
<waitForElementVisible selector="{{StorefrontWidgetsSection.widgetRecentlyComparedProductsGrid}}" stepKey="waitWidgetRecentlyComparedProductsGrid"/>
3434
<see selector="{{StorefrontWidgetsSection.widgetRecentlyComparedProductsGrid}}" userInput="{{product.name}}" stepKey="seeProductInRecentlyComparedWidget"/>
3535
</actionGroup>
36+
<!-- Check the product not exist in recently compared widget -->
37+
<actionGroup name="StorefrontAssertNotExistProductInRecentlyComparedWidgetActionGroup">
38+
<annotations>
39+
<description>Validate that the provided Product does not appear in the Recently Compared Products widget.</description>
40+
</annotations>
41+
<arguments>
42+
<argument name="product"/>
43+
</arguments>
3644

45+
<waitForElementVisible selector="{{StorefrontWidgetsSection.widgetRecentlyComparedProductsGrid}}" stepKey="waitLoadingRecentlyComparedProductsGrid"/>
46+
<dontSee selector="{{StorefrontWidgetsSection.widgetRecentlyComparedProductsGrid}}" userInput="{{product.name}}" stepKey="dontSeeProductInRecentlyComparedWidget"/>
47+
</actionGroup>
3748
<!-- Check the product in recently ordered widget -->
3849
<actionGroup name="StorefrontAssertProductInRecentlyOrderedWidgetActionGroup">
3950
<annotations>
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
10+
<test name="StoreFrontRecentlyComparedAtWebsiteLevelTest">
11+
<annotations>
12+
<stories value="Recently Compared Product"/>
13+
<title value="Recently Compared Product at website level"/>
14+
<description value="Recently Compared Products widget appears on a page immediately after adding product to compare"/>
15+
<useCaseId value="MC-32751"/>
16+
<testCaseId value="MC-32887"/>
17+
<severity value="MAJOR"/>
18+
<group value="catalog"/>
19+
<group value="widget"/>
20+
</annotations>
21+
<before>
22+
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
23+
<!--Create Simple Product and Category -->
24+
<createData entity="SimpleSubCategory" stepKey="createCategory"/>
25+
<createData entity="SimpleProduct" stepKey="createSimpleProduct1">
26+
<requiredEntity createDataKey="createCategory"/>
27+
</createData>
28+
<createData entity="SimpleProduct" stepKey="createSimpleProduct2">
29+
<requiredEntity createDataKey="createCategory"/>
30+
</createData>
31+
<createData entity="SimpleProduct" stepKey="createSimpleProduct3">
32+
<requiredEntity createDataKey="createCategory"/>
33+
</createData>
34+
<createData entity="SimpleProduct" stepKey="createSimpleProduct4">
35+
<requiredEntity createDataKey="createCategory"/>
36+
</createData>
37+
<createData entity="Simple_US_Customer" stepKey="createCustomer"/>
38+
<actionGroup ref="AdminCreateRecentlyProductsWidgetActionGroup" stepKey="createRecentlyComparedProductsWidget">
39+
<argument name="widget" value="RecentlyComparedProductsWidget"/>
40+
</actionGroup>
41+
<!-- Set Stores > Configurations > Catalog > Recently Viewed/Compared Products > Show for Current = Website -->
42+
<magentoCLI command="config:set {{RecentlyViewedProductScopeWebsite.path}} {{RecentlyViewedProductScopeWebsite.value}}" stepKey="RecentlyViewedProductScopeWebsiteGroup"/>
43+
</before>
44+
<after>
45+
<!-- Delete Product and Category -->
46+
<deleteData createDataKey="createSimpleProduct1" stepKey="deleteSimpleProduct1"/>
47+
<deleteData createDataKey="createSimpleProduct2" stepKey="deleteSimpleProduct2"/>
48+
<deleteData createDataKey="createSimpleProduct3" stepKey="deleteSimpleProduct3"/>
49+
<deleteData createDataKey="createSimpleProduct4" stepKey="deleteSimpleProduct4"/>
50+
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
51+
<deleteData createDataKey="createCustomer" stepKey="deleteCustomer"/>
52+
<actionGroup ref="StorefrontCustomerLogoutActionGroup" stepKey="logoutFromCustomer"/>
53+
<actionGroup ref="AdminDeleteWidgetActionGroup" stepKey="deleteRecentlyComparedProductsWidget">
54+
<argument name="widget" value="RecentlyComparedProductsWidget"/>
55+
</actionGroup>
56+
<!--Reset Stores > Configurations > Catalog > Recently Viewed/Compared Products > Show for Current = Website-->
57+
<magentoCLI command="config:set {{RecentlyViewedProductScopeWebsite.path}} {{RecentlyViewedProductScopeWebsite.value}}" stepKey="RecentlyViewedProductScopeWebsite"/>
58+
59+
<!-- Logout Admin -->
60+
<actionGroup ref="logout" stepKey="logout"/>
61+
</after>
62+
<!--Login to storefront from customer-->
63+
<actionGroup ref="LoginToStorefrontActionGroup" stepKey="loginCustomer">
64+
<argument name="Customer" value="$$createCustomer$$"/>
65+
</actionGroup>
66+
<see userInput="Welcome, $$createCustomer.firstname$$ $$createCustomer.lastname$$!" selector="{{StorefrontPanelHeaderSection.WelcomeMessage}}" stepKey="checkWelcomeMessage"/>
67+
<amOnPage url="{{StorefrontCategoryPage.url($$createCategory.custom_attributes[url_key]$$)}}" stepKey="openCategoryPageAfterAddedProductToCart"/>
68+
<!--Add to compare Simple Product and Simple Product 2-->
69+
<actionGroup ref="StorefrontAddCategoryProductToCompareActionGroup" stepKey="addSimpleProduct1ToCompare" >
70+
<argument name="productVar" value="$$createSimpleProduct1$$"/>
71+
</actionGroup>
72+
<actionGroup ref="StorefrontAddCategoryProductToCompareActionGroup" stepKey="addSimpleProduct2ToCompare" >
73+
<argument name="productVar" value="$$createSimpleProduct2$$"/>
74+
</actionGroup>
75+
<!--The Compare Products widget displays Simple Product 1 and Simple Product 2-->
76+
<actionGroup ref="StorefrontCheckCompareSidebarProductActionGroup" stepKey="checkSimpleProduct1InCompareSidebar">
77+
<argument name="productVar" value="$$createSimpleProduct1$$"/>
78+
</actionGroup>
79+
<actionGroup ref="StorefrontCheckCompareSidebarProductActionGroup" stepKey="checkSimpleProduct2InCompareSidebar">
80+
<argument name="productVar" value="$$createSimpleProduct2$$"/>
81+
</actionGroup>
82+
83+
<!--Click Clear all in the Compare Products widget-->
84+
<actionGroup ref="StorefrontClearCompareActionGroup" stepKey="clearCompareList"/>
85+
<!--The Recently Compared widget displays Simple Product 1 and Simple Product 2-->
86+
<amOnPage url="{{StorefrontCategoryPage.url($$createCategory.custom_attributes[url_key]$$)}}" stepKey="openCategoryPageToCheckProductsInRecentlyComparedSidebar"/>
87+
<actionGroup ref="StorefrontAssertProductInRecentlyComparedWidgetActionGroup" stepKey="checkSimpleProduct1ExistInRecentlyComparedWidget">
88+
<argument name="product" value="$$createSimpleProduct1$$"/>
89+
</actionGroup>
90+
<actionGroup ref="StorefrontAssertProductInRecentlyComparedWidgetActionGroup" stepKey="checkSimpleProduct2ExistInRecentlyComparedWidget">
91+
<argument name="product" value="$$createSimpleProduct2$$"/>
92+
</actionGroup>
93+
<!--The Recently Compared widget not displays Simple Product 3 and Simple Product 4-->
94+
<actionGroup ref="StorefrontAssertNotExistProductInRecentlyComparedWidgetActionGroup" stepKey="checkSimpleProduct3NotExistInRecentlyComparedWidget">
95+
<argument name="product" value="$$createSimpleProduct3$$"/>
96+
</actionGroup>
97+
<actionGroup ref="StorefrontAssertNotExistProductInRecentlyComparedWidgetActionGroup" stepKey="checkSimpleProduct4NotExistInRecentlyComparedWidget">
98+
<argument name="product" value="$$createSimpleProduct4$$"/>
99+
</actionGroup>
100+
<amOnPage url="customer/account/logout/" stepKey="logoutCustomer"/>
101+
<waitForPageLoad time="30" stepKey="waitForPageLoad2"/>
102+
</test>
103+
</tests>

app/code/Magento/Catalog/view/frontend/web/js/product/provider-compared.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,27 @@ define([
3131
*/
3232
dataFilter: function (data) {
3333
var providerData = this.idsStorage.prepareData(customerData.get(this.identifiersConfig.provider)().items),
34-
result = {};
34+
result = {},
35+
productCurrentScope,
36+
scopeId;
3537

36-
_.each(data, function (value, key) {
37-
if (!providerData[key]) {
38-
result[key] = value;
39-
}
40-
});
38+
if (typeof this.data.productCurrentScope !== 'undefined') {
39+
productCurrentScope = this.data.productCurrentScope;
40+
scopeId = productCurrentScope === 'store' ? window.checkout.storeId :
41+
productCurrentScope === 'group' ? window.checkout.storeGroupId :
42+
window.checkout.websiteId;
43+
_.each(data, function (value, key) {
44+
if (!providerData[productCurrentScope + '-' + scopeId + '-' + key]) {
45+
result[key] = value;
46+
}
47+
});
48+
} else {
49+
_.each(data, function (value, key) {
50+
if (!providerData[key]) {
51+
result[key] = value;
52+
}
53+
});
54+
}
4155

4256
return result;
4357
},

app/code/Magento/Config/App/Config/Source/RuntimeConfigSource.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
88
use Magento\Framework\App\Config\ConfigSourceInterface;
99
use Magento\Framework\App\Config\ScopeCodeResolver;
1010
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
use Magento\Framework\App\DeploymentConfig;
12+
use Magento\Framework\App\ObjectManager;
1113
use Magento\Framework\DataObject;
1214
use Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory;
1315
use Magento\Framework\App\Config\Scope\Converter;
16+
use Magento\Framework\DB\Adapter\TableNotFoundException;
1417

1518
/**
1619
* Class for retrieving runtime configuration from database.
@@ -34,20 +37,27 @@ class RuntimeConfigSource implements ConfigSourceInterface
3437
* @var ScopeCodeResolver
3538
*/
3639
private $scopeCodeResolver;
40+
/**
41+
* @var DeploymentConfig
42+
*/
43+
private $deploymentConfig;
3744

3845
/**
3946
* @param CollectionFactory $collectionFactory
4047
* @param ScopeCodeResolver $scopeCodeResolver
4148
* @param Converter $converter
49+
* @param DeploymentConfig|null $deploymentConfig
4250
*/
4351
public function __construct(
4452
CollectionFactory $collectionFactory,
4553
ScopeCodeResolver $scopeCodeResolver,
46-
Converter $converter
54+
Converter $converter,
55+
?DeploymentConfig $deploymentConfig = null
4756
) {
4857
$this->collectionFactory = $collectionFactory;
4958
$this->converter = $converter;
5059
$this->scopeCodeResolver = $scopeCodeResolver;
60+
$this->deploymentConfig = $deploymentConfig ?? ObjectManager::getInstance()->get(DeploymentConfig::class);
5161
}
5262

5363
/**
@@ -59,7 +69,7 @@ public function __construct(
5969
*/
6070
public function get($path = '')
6171
{
62-
$data = new DataObject($this->loadConfig());
72+
$data = new DataObject($this->deploymentConfig->isDbAvailable() ? $this->loadConfig() : []);
6373
return $data->getData($path) ?: [];
6474
}
6575

@@ -75,8 +85,12 @@ private function loadConfig()
7585
{
7686
try {
7787
$collection = $this->collectionFactory->create();
88+
$collection->load();
7889
} catch (\DomainException $e) {
7990
$collection = [];
91+
} catch (TableNotFoundException $exception) {
92+
// database is empty or not setup
93+
$collection = [];
8094
}
8195
$config = [];
8296
foreach ($collection as $item) {

app/code/Magento/Config/Test/Unit/App/Config/Source/RuntimeConfigSourceTest.php

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,57 @@
55
*/
66
namespace Magento\Config\Test\Unit\App\Config\Source;
77

8+
use ArrayIterator;
89
use Magento\Config\App\Config\Source\RuntimeConfigSource;
10+
use Magento\Config\Model\ResourceModel\Config\Data\Collection;
911
use Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory;
1012
use Magento\Framework\App\Config\Scope\Converter;
1113
use Magento\Framework\App\Config\ScopeCodeResolver;
1214
use Magento\Framework\App\Config\ScopeConfigInterface;
1315
use Magento\Framework\App\Config\Value;
16+
use Magento\Framework\App\DeploymentConfig;
17+
use Magento\Framework\DB\Adapter\TableNotFoundException;
18+
use PHPUnit\Framework\MockObject\MockObject;
19+
use PHPUnit\Framework\TestCase;
1420

1521
/**
1622
* Test Class for retrieving runtime configuration from database.
17-
* @package Magento\Config\Test\Unit\App\Config\Source
1823
*/
19-
class RuntimeConfigSourceTest extends \PHPUnit\Framework\TestCase
24+
class RuntimeConfigSourceTest extends TestCase
2025
{
2126
/**
22-
* @var CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
27+
* @var CollectionFactory|MockObject
2328
*/
2429
private $collectionFactory;
2530

2631
/**
27-
* @var ScopeCodeResolver|\PHPUnit_Framework_MockObject_MockObject
32+
* @var ScopeCodeResolver|MockObject
2833
*/
2934
private $scopeCodeResolver;
3035

3136
/**
32-
* @var Converter|\PHPUnit_Framework_MockObject_MockObject
37+
* @var Converter|MockObject
3338
*/
3439
private $converter;
3540

3641
/**
37-
* @var Value|\PHPUnit_Framework_MockObject_MockObject
42+
* @var Value|MockObject
3843
*/
3944
private $configItem;
4045

4146
/**
42-
* @var Value|\PHPUnit_Framework_MockObject_MockObject
47+
* @var Value|MockObject
4348
*/
4449
private $configItemTwo;
4550

4651
/**
4752
* @var RuntimeConfigSource
4853
*/
4954
private $configSource;
55+
/**
56+
* @var DeploymentConfig|MockObject
57+
*/
58+
private $deploymentConfig;
5059

5160
public function setUp()
5261
{
@@ -68,20 +77,29 @@ public function setUp()
6877
->disableOriginalConstructor()
6978
->setMethods(['getScope', 'getPath', 'getValue', 'getScopeId'])
7079
->getMock();
80+
$this->deploymentConfig = $this->createPartialMock(DeploymentConfig::class, ['isDbAvailable']);
7181
$this->configSource = new RuntimeConfigSource(
7282
$this->collectionFactory,
7383
$this->scopeCodeResolver,
74-
$this->converter
84+
$this->converter,
85+
$this->deploymentConfig
7586
);
7687
}
7788

7889
public function testGet()
7990
{
91+
$this->deploymentConfig->method('isDbAvailable')
92+
->willReturn(true);
93+
$collection = $this->createPartialMock(Collection::class, ['load', 'getIterator']);
94+
$collection->method('load')
95+
->willReturn($collection);
96+
$collection->method('getIterator')
97+
->willReturn(new ArrayIterator([$this->configItem, $this->configItemTwo]));
8098
$scope = 'websites';
8199
$scopeCode = 'myWebsites';
82100
$this->collectionFactory->expects($this->once())
83101
->method('create')
84-
->willReturn([$this->configItem, $this->configItemTwo]);
102+
->willReturn($collection);
85103
$this->configItem->expects($this->exactly(2))
86104
->method('getScope')
87105
->willReturn(ScopeConfigInterface::SCOPE_TYPE_DEFAULT);
@@ -133,4 +151,22 @@ public function testGet()
133151
$this->configSource->get()
134152
);
135153
}
154+
155+
public function testGetWhenDbIsNotAvailable()
156+
{
157+
$this->deploymentConfig->method('isDbAvailable')->willReturn(false);
158+
$this->assertEquals([], $this->configSource->get());
159+
}
160+
161+
public function testGetWhenDbIsEmpty()
162+
{
163+
$this->deploymentConfig->method('isDbAvailable')
164+
->willReturn(true);
165+
$collection = $this->createPartialMock(Collection::class, ['load']);
166+
$collection->method('load')
167+
->willThrowException($this->createMock(TableNotFoundException::class));
168+
$this->collectionFactory->method('create')
169+
->willReturn($collection);
170+
$this->assertEquals([], $this->configSource->get());
171+
}
136172
}

0 commit comments

Comments
 (0)