Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 0c26a71

Browse files
author
Michael Yu
committed
Merge branch '2.2-develop' of github.com:magento-jackalopes/magento2ce into MAGETWO-71765
2 parents 3521cb8 + 9223ab3 commit 0c26a71

File tree

9 files changed

+330
-118
lines changed

9 files changed

+330
-118
lines changed

app/code/Magento/CatalogWidget/Block/Product/ProductsList.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,14 @@ protected function getConditions()
259259
$conditions = $this->conditionsHelper->decode($conditions);
260260
}
261261

262+
foreach ($conditions as $key => $condition) {
263+
if (!empty($condition['attribute'])
264+
&& in_array($condition['attribute'], ['special_from_date', 'special_to_date'])
265+
) {
266+
$conditions[$key]['value'] = date('Y-m-d H:i:s', strtotime($condition['value']));
267+
}
268+
}
269+
262270
$this->rule->loadPost(['conditions' => $conditions]);
263271
return $this->rule->getConditions();
264272
}

app/code/Magento/CatalogWidget/Test/Unit/Block/Product/ProductsListTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,11 @@ public function testCreateCollection($pagerEnable, $productsCount, $productsPerP
288288
$this->collectionFactory->expects($this->once())->method('create')->willReturn($collection);
289289
$this->productsList->setData('conditions_encoded', 'some_serialized_conditions');
290290

291+
$this->widgetConditionsHelper->expects($this->once())
292+
->method('decode')
293+
->with('some_serialized_conditions')
294+
->willReturn([]);
295+
291296
$this->builder->expects($this->once())->method('attachConditionToCollection')
292297
->with($collection, $this->getConditionsForCollection($collection))
293298
->willReturnSelf();

app/code/Magento/ConfigurableProduct/Block/Product/View/Type/Configurable.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Magento\ConfigurableProduct\Model\ConfigurableAttributeData;
1111
use Magento\Customer\Helper\Session\CurrentCustomer;
12+
use Magento\Customer\Model\Session;
1213
use Magento\Framework\App\ObjectManager;
1314
use Magento\Framework\Locale\Format;
1415
use Magento\Framework\Pricing\PriceCurrencyInterface;
@@ -31,6 +32,7 @@ class Configurable extends \Magento\Catalog\Block\Product\View\AbstractView
3132
/**
3233
* Current customer
3334
*
35+
* @deprecated, as unused property
3436
* @var CurrentCustomer
3537
*/
3638
protected $currentCustomer;
@@ -67,6 +69,11 @@ class Configurable extends \Magento\Catalog\Block\Product\View\AbstractView
6769
*/
6870
private $localeFormat;
6971

72+
/**
73+
* @var Session
74+
*/
75+
private $customerSession;
76+
7077
/**
7178
* @param \Magento\Catalog\Block\Product\Context $context
7279
* @param \Magento\Framework\Stdlib\ArrayUtils $arrayUtils
@@ -78,6 +85,7 @@ class Configurable extends \Magento\Catalog\Block\Product\View\AbstractView
7885
* @param ConfigurableAttributeData $configurableAttributeData
7986
* @param array $data
8087
* @param Format|null $localeFormat
88+
* @param Session|null $customerSession
8189
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
8290
*/
8391
public function __construct(
@@ -90,7 +98,8 @@ public function __construct(
9098
PriceCurrencyInterface $priceCurrency,
9199
ConfigurableAttributeData $configurableAttributeData,
92100
array $data = [],
93-
Format $localeFormat = null
101+
Format $localeFormat = null,
102+
Session $customerSession = null
94103
) {
95104
$this->priceCurrency = $priceCurrency;
96105
$this->helper = $helper;
@@ -99,6 +108,7 @@ public function __construct(
99108
$this->currentCustomer = $currentCustomer;
100109
$this->configurableAttributeData = $configurableAttributeData;
101110
$this->localeFormat = $localeFormat ?: ObjectManager::getInstance()->get(Format::class);
111+
$this->customerSession = $customerSession ?: ObjectManager::getInstance()->get(Session::class);
102112

103113
parent::__construct(
104114
$context,
@@ -117,6 +127,7 @@ public function getCacheKeyInfo()
117127
{
118128
$parentData = parent::getCacheKeyInfo();
119129
$parentData[] = $this->priceCurrency->getCurrencySymbol();
130+
$parentData[] = $this->customerSession->getCustomerGroupId();
120131
return $parentData;
121132
}
122133

app/code/Magento/ConfigurableProduct/Test/Unit/Block/Product/View/Type/ConfigurableTest.php

Lines changed: 117 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
*/
66
namespace Magento\ConfigurableProduct\Test\Unit\Block\Product\View\Type;
77

8+
use Magento\Customer\Model\Session;
9+
use Magento\Framework\App\State;
10+
811
/**
912
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1013
*/
@@ -65,6 +68,11 @@ class ConfigurableTest extends \PHPUnit\Framework\TestCase
6568
*/
6669
private $storeManager;
6770

71+
/**
72+
* @var \PHPUnit_Framework_MockObject_MockObject
73+
*/
74+
private $customerSession;
75+
6876
protected function setUp()
6977
{
7078
$this->mockContextObject();
@@ -92,6 +100,28 @@ protected function setUp()
92100
->disableOriginalConstructor()
93101
->getMock();
94102

103+
$appState = $this->getMockBuilder(State::class)
104+
->disableOriginalConstructor()
105+
->getMock();
106+
$this->context->expects($this->once())
107+
->method('getAppState')
108+
->willReturn($appState);
109+
$appState->expects($this->any())
110+
->method('getAreaCode')
111+
->willReturn('frontend');
112+
$urlBuilder = $this->getMockBuilder(\Magento\Framework\UrlInterface::class)
113+
->disableOriginalConstructor()
114+
->getMock();
115+
$this->context->expects($this->once())
116+
->method('getUrlBuilder')
117+
->willReturn($urlBuilder);
118+
$fileResolverMock = $this
119+
->getMockBuilder(\Magento\Framework\View\Element\Template\File\Resolver::class)
120+
->disableOriginalConstructor()
121+
->getMock();
122+
$this->context->expects($this->once())
123+
->method('getResolver')
124+
->willReturn($fileResolverMock);
95125
$this->configurableAttributeData = $this->getMockBuilder(
96126
\Magento\ConfigurableProduct\Model\ConfigurableAttributeData::class
97127
)
@@ -102,6 +132,10 @@ protected function setUp()
102132
->disableOriginalConstructor()
103133
->getMock();
104134

135+
$this->customerSession = $this->getMockBuilder(Session::class)
136+
->disableOriginalConstructor()
137+
->getMock();
138+
105139
$this->block = new \Magento\ConfigurableProduct\Block\Product\View\Type\Configurable(
106140
$this->context,
107141
$this->arrayUtils,
@@ -112,10 +146,92 @@ protected function setUp()
112146
$this->priceCurrency,
113147
$this->configurableAttributeData,
114148
[],
115-
$this->localeFormat
149+
$this->localeFormat,
150+
$this->customerSession
116151
);
117152
}
118153

154+
/**
155+
* Provide cache key info
156+
*
157+
* @return array
158+
*/
159+
public function cacheKeyProvider() : array
160+
{
161+
return [
162+
'without_currency_and_customer_group' => [
163+
[
164+
0 => 'BLOCK_TPL',
165+
1 => 'default',
166+
2 => null,
167+
'base_url' => null,
168+
'template' => null,
169+
3 => null,
170+
4 => null,
171+
],
172+
null,
173+
null,
174+
],
175+
'with_customer_group' => [
176+
[
177+
0 => 'BLOCK_TPL',
178+
1 => 'default',
179+
2 => null,
180+
'base_url' => null,
181+
'template' => null,
182+
3 => null,
183+
4 => 1,
184+
],
185+
null,
186+
1,
187+
],
188+
'with_price_currency' => [
189+
[
190+
0 => 'BLOCK_TPL',
191+
1 => 'default',
192+
2 => null,
193+
'base_url' => null,
194+
'template' => null,
195+
3 => '$',
196+
4 => null,
197+
],
198+
'$',
199+
null,
200+
]
201+
];
202+
}
203+
204+
/**
205+
* Test cache Tags
206+
* @dataProvider cacheKeyProvider
207+
* @param array $expected
208+
* @param string|null $priceCurrency
209+
* @param string|null $customerGroupId
210+
*/
211+
public function testGetCacheKeyInfo(array $expected, string $priceCurrency = null, string $customerGroupId = null)
212+
{
213+
$storeMock = $this->getMockBuilder(\Magento\Store\Api\Data\StoreInterface::class)
214+
->setMethods([
215+
'getCurrentCurrency',
216+
])
217+
->getMockForAbstractClass();
218+
$storeMock->expects($this->any())
219+
->method('getCode')
220+
->willReturn('default');
221+
222+
$this->storeManager->expects($this->any())
223+
->method('getStore')
224+
->willReturn($storeMock);
225+
$this->priceCurrency->expects($this->once())
226+
->method('getCurrencySymbol')
227+
->willReturn($priceCurrency);
228+
$this->customerSession->expects($this->once())
229+
->method('getCustomerGroupId')
230+
->willReturn($customerGroupId);
231+
$actual = $this->block->getCacheKeyInfo();
232+
$this->assertEquals($expected, $actual);
233+
}
234+
119235
/**
120236
* Check that getJsonConfig() method returns expected value
121237
*/

app/code/Magento/GiftMessage/Model/GiftMessageConfigProvider.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,7 @@ public function getConfig()
119119
$configuration['isCustomerLoggedIn'] = $this->isCustomerLoggedIn();
120120
$configuration['formKey'] = $this->formKey->getFormKey();
121121
$store = $this->storeManager->getStore();
122-
$configuration['baseUrl'] = $store->isFrontUrlSecure()
123-
? $store->getBaseUrl(UrlInterface::URL_TYPE_LINK, true)
124-
: $store->getBaseUrl(UrlInterface::URL_TYPE_LINK, false);
122+
$configuration['baseUrl'] = $store->getBaseUrl(UrlInterface::URL_TYPE_LINK);
125123
return $configuration;
126124
}
127125

app/code/Magento/GiftMessage/Test/Unit/Model/GiftMessageConfigProviderTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,12 @@ public function testGetConfig()
9898
$storeCode = 4;
9999
$messageDataMock = ['from' => 'John Doe', 'to' => 'Jane Doe'];
100100
$formKey = 'ABCDEFGHIJKLMNOP';
101-
$isFrontUrlSecure = true;
102101
$baseUrl = 'https://magento.com/';
103102
$quoteItemMock = $this->createMock(\Magento\Quote\Model\Quote\Item::class);
104103
$productMock = $this->createMock(\Magento\Catalog\Model\Product::class);
105104
$storeMock = $this->createPartialMock(
106105
\Magento\Store\Model\Store::class,
107-
['isFrontUrlSecure', 'getBaseUrl', 'getCode']
106+
['getBaseUrl', 'getCode']
108107
);
109108
$quoteMock = $this->createPartialMock(
110109
\Magento\Quote\Model\Quote::class,
@@ -142,8 +141,7 @@ public function testGetConfig()
142141
->willReturn($isCustomerLoggedIn);
143142
$this->formKeyMock->expects($this->once())->method('getFormKey')->willReturn($formKey);
144143
$this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($storeMock);
145-
$storeMock->expects($this->once())->method('isFrontUrlSecure')->willReturn($isFrontUrlSecure);
146-
$storeMock->expects($this->once())->method('getBaseUrl')->with(UrlInterface::URL_TYPE_LINK, $isFrontUrlSecure)
144+
$storeMock->expects($this->once())->method('getBaseUrl')->with(UrlInterface::URL_TYPE_LINK)
147145
->willReturn($baseUrl);
148146

149147
$expectedResult = [

app/code/Magento/Rule/Model/Condition/Sql/Builder.php

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ protected function _joinTablesToCollection(
108108
}
109109

110110
/**
111+
* Returns sql expression based on rule condition.
112+
*
111113
* @param AbstractCondition $condition
112114
* @param string $value
113115
* @return string
@@ -116,24 +118,27 @@ protected function _joinTablesToCollection(
116118
protected function _getMappedSqlCondition(AbstractCondition $condition, $value = '')
117119
{
118120
$argument = $condition->getMappedSqlField();
119-
if ($argument) {
120-
$conditionOperator = $condition->getOperatorForValidate();
121121

122-
if (!isset($this->_conditionOperatorMap[$conditionOperator])) {
123-
throw new \Magento\Framework\Exception\LocalizedException(__('Unknown condition operator'));
124-
}
122+
// If rule hasn't valid argument - create negative expression to prevent incorrect rule behavior.
123+
if (empty($argument)) {
124+
return $this->_expressionFactory->create(['expression' => '1 = -1']);
125+
}
125126

126-
$sql = str_replace(
127-
':field',
128-
$this->_connection->getIfNullSql($this->_connection->quoteIdentifier($argument), 0),
129-
$this->_conditionOperatorMap[$conditionOperator]
130-
);
127+
$conditionOperator = $condition->getOperatorForValidate();
131128

132-
return $this->_expressionFactory->create(
133-
['expression' => $value . $this->_connection->quoteInto($sql, $condition->getBindArgumentValue())]
134-
);
129+
if (!isset($this->_conditionOperatorMap[$conditionOperator])) {
130+
throw new \Magento\Framework\Exception\LocalizedException(__('Unknown condition operator'));
135131
}
136-
return '';
132+
133+
$sql = str_replace(
134+
':field',
135+
$this->_connection->getIfNullSql($this->_connection->quoteIdentifier($argument), 0),
136+
$this->_conditionOperatorMap[$conditionOperator]
137+
);
138+
139+
return $this->_expressionFactory->create(
140+
['expression' => $value . $this->_connection->quoteInto($sql, $condition->getBindArgumentValue())]
141+
);
137142
}
138143

139144
/**
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Rule\Model\Condition\Sql;
8+
9+
use Magento\TestFramework\Helper\Bootstrap;
10+
11+
class BuilderTest extends \PHPUnit\Framework\TestCase
12+
{
13+
/**
14+
* @var \Magento\Rule\Model\Condition\Sql\Builder
15+
*/
16+
private $model;
17+
18+
protected function setUp()
19+
{
20+
$this->model = Bootstrap::getObjectManager()->create(\Magento\Rule\Model\Condition\Sql\Builder::class);
21+
}
22+
23+
public function testAttachConditionToCollection()
24+
{
25+
/** @var \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $collectionFactory */
26+
$collectionFactory = Bootstrap::getObjectManager()->create(
27+
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory::class
28+
);
29+
/** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $collection */
30+
$collection = $collectionFactory->create();
31+
32+
/** @var \Magento\CatalogWidget\Model\RuleFactory $ruleFactory */
33+
$ruleFactory = Bootstrap::getObjectManager()->create(\Magento\CatalogWidget\Model\RuleFactory::class);
34+
/** @var \Magento\CatalogWidget\Model\Rule $rule */
35+
$rule = $ruleFactory->create();
36+
37+
$ruleConditionArray = [
38+
'conditions' => [
39+
'1' => [
40+
'type' => \Magento\CatalogWidget\Model\Rule\Condition\Combine::class,
41+
'aggregator' => 'all',
42+
'value' => '1',
43+
'new_child' => ''
44+
],
45+
'1--1' => [
46+
'type' => \Magento\CatalogWidget\Model\Rule\Condition\Product::class,
47+
'attribute' => 'category_ids',
48+
'operator' => '==',
49+
'value' => '3'
50+
],
51+
'1--2' => [
52+
'type' => \Magento\CatalogWidget\Model\Rule\Condition\Product::class,
53+
'attribute' => 'special_to_date',
54+
'operator' => '==',
55+
'value' => '2017-09-15'
56+
],
57+
]
58+
];
59+
60+
$rule->loadPost($ruleConditionArray);
61+
$this->model->attachConditionToCollection($collection, $rule->getConditions());
62+
63+
$whereString = 'WHERE (category_id IN (\'3\')))) AND(IFNULL(`e`.`entity_id`, 0) = \'2017-09-15\') ))';
64+
$this->assertNotFalse(strpos($collection->getSelectSql(true), $whereString));
65+
}
66+
}

0 commit comments

Comments
 (0)