Skip to content

Commit 1ac2118

Browse files
committed
MAGETWO-81220: Prepare code base 2.0.17
1 parent 548fec3 commit 1ac2118

File tree

24 files changed

+741
-398
lines changed

24 files changed

+741
-398
lines changed

app/code/Magento/CatalogRule/Test/Unit/Model/RuleTest.php

Lines changed: 67 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
namespace Magento\CatalogRule\Test\Unit\Model;
88

99
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
10+
use Magento\Framework\ObjectManagerInterface;
11+
use Magento\Framework\Unserialize\SecureUnserializer;
1012

1113
/**
1214
* Class RuleTest
@@ -56,26 +58,31 @@ class RuleTest extends \PHPUnit_Framework_TestCase
5658
*/
5759
protected $productModel;
5860

61+
/**
62+
* @var SecureUnserializer
63+
*/
64+
private $unserialize;
65+
5966
/**
6067
* Set up before test
6168
*
6269
* @return void
6370
*/
6471
protected function setUp()
6572
{
66-
$this->storeManager = $this->getMock('Magento\Store\Model\StoreManagerInterface');
67-
$this->storeModel = $this->getMock('Magento\Store\Model\Store', ['__wakeup', 'getId'], [], '', false);
73+
$this->storeManager = $this->getMock(\Magento\Store\Model\StoreManagerInterface::class);
74+
$this->storeModel = $this->getMock(\Magento\Store\Model\Store::class, ['__wakeup', 'getId'], [], '', false);
6875
$this->combineFactory = $this->getMock(
69-
'Magento\CatalogRule\Model\Rule\Condition\CombineFactory',
76+
\Magento\CatalogRule\Model\Rule\Condition\CombineFactory::class,
7077
[
71-
'create'
78+
'create',
7279
],
7380
[],
7481
'',
7582
false
7683
);
7784
$this->productModel = $this->getMock(
78-
'Magento\Catalog\Model\Product',
85+
\Magento\Catalog\Model\Product::class,
7986
[
8087
'__wakeup', 'getId', 'setData'
8188
],
@@ -84,53 +91,56 @@ protected function setUp()
8491
false
8592
);
8693
$this->condition = $this->getMock(
87-
'Magento\Rule\Model\Condition\Combine',
94+
\Magento\Rule\Model\Condition\Combine::class,
8895
[
8996
'setRule',
90-
'validate'
97+
'validate',
9198
],
9299
[],
93100
'',
94101
false
95102
);
96103
$this->websiteModel = $this->getMock(
97-
'Magento\Store\Model\Website',
104+
\Magento\Store\Model\Website::class,
98105
[
99106
'__wakeup',
100107
'getId',
101-
'getDefaultStore'
108+
'getDefaultStore',
102109
],
103110
[],
104111
'',
105112
false
106113
);
107114
$this->_ruleProductProcessor = $this->getMock(
108-
'\Magento\CatalogRule\Model\Indexer\Rule\RuleProductProcessor',
115+
\Magento\CatalogRule\Model\Indexer\Rule\RuleProductProcessor::class,
109116
[],
110117
[],
111118
'',
112119
false
113120
);
114121

115122
$this->_productCollectionFactory = $this->getMock(
116-
'\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory',
123+
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory::class,
117124
['create'],
118125
[],
119126
'',
120127
false
121128
);
122129

123130
$this->_resourceIterator = $this->getMock(
124-
'\Magento\Framework\Model\ResourceModel\Iterator',
131+
\Magento\Framework\Model\ResourceModel\Iterator::class,
125132
['walk'],
126133
[],
127134
'',
128135
false
129136
);
130137

131138
$this->objectManagerHelper = new ObjectManagerHelper($this);
139+
140+
$this->prepareObjectManager();
141+
132142
$this->rule = $this->objectManagerHelper->getObject(
133-
'Magento\CatalogRule\Model\Rule',
143+
\Magento\CatalogRule\Model\Rule::class,
134144
[
135145
'storeManager' => $this->storeManager,
136146
'combineFactory' => $this->combineFactory,
@@ -161,7 +171,7 @@ public function testCallbackValidateProduct($validate)
161171
'has_options' => '0',
162172
'required_options' => '0',
163173
'created_at' => '2014-06-25 13:14:30',
164-
'updated_at' => '2014-06-25 14:37:15'
174+
'updated_at' => '2014-06-25 14:37:15',
165175
];
166176
$this->storeManager->expects($this->any())->method('getWebsites')->with(true)
167177
->will($this->returnValue([$this->websiteModel, $this->websiteModel]));
@@ -236,15 +246,15 @@ public function validateDataDataProvider()
236246
'sub_simple_action' => 'by_percent',
237247
'sub_discount_amount' => '123',
238248
],
239-
true
249+
true,
240250
],
241251
[
242252
[
243253
'simple_action' => 'by_percent',
244254
'discount_amount' => '9,99',
245255
'sub_is_enable' => '0',
246256
],
247-
true
257+
true,
248258
],
249259
[
250260
[
@@ -256,7 +266,7 @@ public function validateDataDataProvider()
256266
],
257267
[
258268
'Percentage discount should be between 0 and 100.',
259-
]
269+
],
260270
],
261271
[
262272
[
@@ -269,7 +279,7 @@ public function validateDataDataProvider()
269279
[
270280
'Percentage discount should be between 0 and 100.',
271281
'Percentage discount should be between 0 and 100.',
272-
]
282+
],
273283
],
274284
[
275285
[
@@ -281,7 +291,7 @@ public function validateDataDataProvider()
281291
],
282292
[
283293
'Percentage discount should be between 0 and 100.',
284-
]
294+
],
285295
],
286296
[
287297
[
@@ -294,7 +304,7 @@ public function validateDataDataProvider()
294304
[
295305
'Discount value should be 0 or greater.',
296306
'Discount value should be 0 or greater.',
297-
]
307+
],
298308
],
299309
[
300310
[
@@ -304,7 +314,7 @@ public function validateDataDataProvider()
304314
],
305315
[
306316
'Unknown action.',
307-
]
317+
],
308318
],
309319
];
310320
}
@@ -316,7 +326,7 @@ public function validateDataDataProvider()
316326
*/
317327
public function testAfterDelete()
318328
{
319-
$indexer = $this->getMock('\Magento\Framework\Indexer\IndexerInterface');
329+
$indexer = $this->getMock(\Magento\Framework\Indexer\IndexerInterface::class);
320330
$indexer->expects($this->once())->method('invalidate');
321331
$this->_ruleProductProcessor->expects($this->once())->method('getIndexer')->will($this->returnValue($indexer));
322332
$this->rule->afterDelete();
@@ -330,7 +340,7 @@ public function testAfterDelete()
330340
public function testAfterUpdate()
331341
{
332342
$this->rule->isObjectNew(false);
333-
$indexer = $this->getMock('\Magento\Framework\Indexer\IndexerInterface');
343+
$indexer = $this->getMock(\Magento\Framework\Indexer\IndexerInterface::class);
334344
$indexer->expects($this->once())->method('invalidate');
335345
$this->_ruleProductProcessor->expects($this->once())->method('getIndexer')->will($this->returnValue($indexer));
336346
$this->rule->afterSave();
@@ -352,7 +362,7 @@ public function testIsRuleBehaviorChanged($dataArray, $originDataArray, $isObjec
352362
{
353363
$this->rule->setData('website_ids', []);
354364
$this->rule->isObjectNew($isObjectNew);
355-
$indexer = $this->getMock('\Magento\Framework\Indexer\IndexerInterface');
365+
$indexer = $this->getMock(\Magento\Framework\Indexer\IndexerInterface::class);
356366
$indexer->expects($this->any())->method('invalidate');
357367
$this->_ruleProductProcessor->expects($this->any())->method('getIndexer')->will($this->returnValue($indexer));
358368

@@ -383,4 +393,37 @@ public function isRuleBehaviorChangedDataProvider()
383393
[['name', 'description'], ['name', 'important_data'], true, true],
384394
];
385395
}
396+
397+
/**
398+
* Prepares ObjectManager mock.
399+
*
400+
* @return void
401+
*/
402+
private function prepareObjectManager()
403+
{
404+
$objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class)
405+
->disableOriginalConstructor()
406+
->getMock();
407+
408+
$this->unserialize = $this->getMockBuilder(SecureUnserializer::class)
409+
->disableOriginalConstructor()
410+
->getMock();
411+
412+
$objectManagerMock->expects($this->any())->method('get')->willReturn(
413+
[SecureUnserializer::class, $this->unserialize]
414+
);
415+
416+
\Magento\Framework\App\ObjectManager::setInstance($objectManagerMock);
417+
}
418+
419+
/**
420+
* @inheritdoc
421+
*/
422+
protected function tearDown()
423+
{
424+
$reflectionClass = new \ReflectionClass(\Magento\Framework\App\ObjectManager::class);
425+
$reflectionProperty = $reflectionClass->getProperty('_instance');
426+
$reflectionProperty->setAccessible(true);
427+
$reflectionProperty->setValue(null, null);
428+
}
386429
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,12 @@ protected function getConditions()
227227
: $this->getData('conditions');
228228

229229
if ($conditions) {
230-
$conditions = $this->conditionsHelper->decode($conditions);
230+
try {
231+
$conditions = $this->conditionsHelper->decode($conditions);
232+
} catch (\InvalidArgumentException $e) {
233+
$this->_logger->critical($e);
234+
$conditions = '';
235+
}
231236
}
232237

233238
$this->rule->loadPost(['conditions' => $conditions]);

0 commit comments

Comments
 (0)