Skip to content

Commit 81d30a9

Browse files
author
Volodymyr Klymenko
authored
Merge pull request #925 from magento-east/MAGETWO-66117
[East] Stabilize 2.1-develop
2 parents 506a93f + 298710d commit 81d30a9

File tree

8 files changed

+227
-45
lines changed

8 files changed

+227
-45
lines changed

app/code/Magento/Reports/Test/Unit/Model/ResourceModel/Report/CollectionTest.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -143,44 +143,46 @@ public function intervalsDataProvider()
143143
return [
144144
[
145145
'_period' => 'day',
146-
'_from' => new \DateTime('-3 day'),
147-
'_to' => new \DateTime('+3 day'),
146+
'_from' => new \DateTime('-3 day', new \DateTimeZone('UTC')),
147+
'_to' => new \DateTime('+3 day', new \DateTimeZone('UTC')),
148148
'size' => 7
149149
],
150150
[
151151
'_period' => 'month',
152-
'_from' => new \DateTime('2015-01-15 11:11:11'),
153-
'_to' => new \DateTime('2015-01-25 11:11:11'),
152+
'_from' => new \DateTime('2015-01-15 11:11:11', new \DateTimeZone('UTC')),
153+
'_to' => new \DateTime('2015-01-25 11:11:11', new \DateTimeZone('UTC')),
154154
'size' => 1
155155
],
156156
[
157157
'_period' => 'month',
158-
'_from' => new \DateTime('2015-01-15 11:11:11'),
159-
'_to' => new \DateTime('2015-02-25 11:11:11'),
158+
'_from' => new \DateTime('2015-01-15 11:11:11', new \DateTimeZone('UTC')),
159+
'_to' => new \DateTime('2015-02-25 11:11:11', new \DateTimeZone('UTC')),
160160
'size' => 2
161161
],
162162
[
163163
'_period' => 'year',
164-
'_from' => new \DateTime('2015-01-15 11:11:11'),
165-
'_to' => new \DateTime('2015-01-25 11:11:11'),
164+
'_from' => new \DateTime('2015-01-15 11:11:11', new \DateTimeZone('UTC')),
165+
'_to' => new \DateTime('2015-01-25 11:11:11', new \DateTimeZone('UTC')),
166166
'size' => 1
167167
],
168168
[
169169
'_period' => 'year',
170-
'_from' => new \DateTime('2014-01-15 11:11:11'),
171-
'_to' => new \DateTime('2015-01-25 11:11:11'),
170+
'_from' => new \DateTime('2014-01-15 11:11:11', new \DateTimeZone('UTC')),
171+
'_to' => new \DateTime('2015-01-25 11:11:11', new \DateTimeZone('UTC')),
172172
'size' => 2
173173
],
174174
[
175175
'_period' => null,
176-
'_from' => new \DateTime('-3 day'),
177-
'_to' => new \DateTime('+3 day'),
176+
'_from' => new \DateTime('-3 day', new \DateTimeZone('UTC')),
177+
'_to' => new \DateTime('+3 day', new \DateTimeZone('UTC')),
178178
'size' => 0
179179
]
180180
];
181181
}
182182

183183
/**
184+
* Format datetime.
185+
*
184186
* @return string
185187
*/
186188
public function formatDateTime()

app/code/Magento/Swatches/Block/Product/Renderer/Listing/Configurable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ protected function getRendererTemplate()
2929
protected function _toHtml()
3030
{
3131
$output = '';
32-
if ($this->isProductHasSwatchAttribute) {
32+
if ($this->isProductHasSwatchAttribute()) {
3333
$output = parent::_toHtml();
3434
}
3535

app/code/Magento/Swatches/Test/Unit/Block/Product/Renderer/Listing/ConfigurableTest.php

Lines changed: 202 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
*/
66
namespace Magento\Swatches\Test\Unit\Block\Product\Renderer\Listing;
77

8-
use Magento\Swatches\Block\Product\Renderer\Configurable;
8+
use \Magento\Swatches\Block\Product\Renderer\Listing\Configurable;
9+
use Magento\Swatches\Model\SwatchAttributesProvider;
910

1011
/**
1112
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
13+
* @SuppressWarnings(PHPMD.TooManyFields)
1214
*/
1315
class ConfigurableTest extends \PHPUnit_Framework_TestCase
1416
{
@@ -57,33 +59,129 @@ class ConfigurableTest extends \PHPUnit_Framework_TestCase
5759
/** @var \Magento\Framework\UrlInterface|\PHPUnit_Framework_MockObject_MockObject */
5860
private $urlBuilder;
5961

62+
/** @var SwatchAttributesProvider|\PHPUnit_Framework_MockObject_MockObject */
63+
private $swatchAttributesProvider;
64+
65+
/** @var \Magento\Catalog\Block\Product\Context|\PHPUnit_Framework_MockObject_MockObject */
66+
private $contextMock;
67+
68+
/** @var \Magento\Framework\View\Element\Template\File\Resolver|\PHPUnit_Framework_MockObject_MockObject */
69+
private $resolver;
70+
71+
/** @var \Magento\Framework\Event\Manager|\PHPUnit_Framework_MockObject_MockObject */
72+
private $eventManager;
73+
74+
/** @var \Magento\Framework\App\Cache\StateInterface|\PHPUnit_Framework_MockObject_MockObject */
75+
private $cacheState;
76+
77+
/** @var \Magento\Framework\Filesystem\Directory\ReadInterface|\PHPUnit_Framework_MockObject_MockObject */
78+
private $directory;
79+
80+
/** @var \Magento\Framework\View\Element\Template\File\Validator|\PHPUnit_Framework_MockObject_MockObject */
81+
private $validator;
82+
83+
/** @var \Magento\Framework\View\TemplateEnginePool|\PHPUnit_Framework_MockObject_MockObject */
84+
private $templateEnginePool;
85+
86+
/**
87+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
88+
*/
6089
public function setUp()
6190
{
62-
$this->arrayUtils = $this->getMock('\Magento\Framework\Stdlib\ArrayUtils', [], [], '', false);
63-
$this->jsonEncoder = $this->getMock('\Magento\Framework\Json\EncoderInterface', [], [], '', false);
64-
$this->helper = $this->getMock('\Magento\ConfigurableProduct\Helper\Data', [], [], '', false);
65-
$this->swatchHelper = $this->getMock('\Magento\Swatches\Helper\Data', [], [], '', false);
66-
$this->swatchMediaHelper = $this->getMock('\Magento\Swatches\Helper\Media', [], [], '', false);
67-
$this->catalogProduct = $this->getMock('\Magento\Catalog\Helper\Product', [], [], '', false);
68-
$this->currentCustomer = $this->getMock('\Magento\Customer\Helper\Session\CurrentCustomer', [], [], '', false);
69-
$this->priceCurrency = $this->getMock('\Magento\Framework\Pricing\PriceCurrencyInterface', [], [], '', false);
91+
$objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
92+
93+
$this->arrayUtils = $this->getMock(\Magento\Framework\Stdlib\ArrayUtils::class, [], [], '', false);
94+
$this->jsonEncoder = $this->getMock(\Magento\Framework\Json\EncoderInterface::class, [], [], '', false);
95+
$this->helper = $this->getMock(\Magento\ConfigurableProduct\Helper\Data::class, [], [], '', false);
96+
$this->swatchHelper = $this->getMock(\Magento\Swatches\Helper\Data::class, [], [], '', false);
97+
$this->swatchMediaHelper = $this->getMock(\Magento\Swatches\Helper\Media::class, [], [], '', false);
98+
$this->catalogProduct = $this->getMock(\Magento\Catalog\Helper\Product::class, [], [], '', false);
99+
$this->currentCustomer = $this->getMock(
100+
\Magento\Customer\Helper\Session\CurrentCustomer::class,
101+
[],
102+
[],
103+
'',
104+
false
105+
);
106+
$this->priceCurrency = $this->getMock(
107+
\Magento\Framework\Pricing\PriceCurrencyInterface::class,
108+
[],
109+
[],
110+
'',
111+
false
112+
);
70113
$this->configurableAttributeData = $this->getMock(
71-
'Magento\ConfigurableProduct\Model\ConfigurableAttributeData',
114+
\Magento\ConfigurableProduct\Model\ConfigurableAttributeData::class,
115+
[],
116+
[],
117+
'',
118+
false
119+
);
120+
$this->product = $this->getMock(\Magento\Catalog\Model\Product::class, [], [], '', false);
121+
$this->typeInstance = $this->getMock(
122+
\Magento\Catalog\Model\Product\Type\AbstractType::class,
72123
[],
73124
[],
74125
'',
75126
false
76127
);
77-
$this->product = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false);
78-
$this->typeInstance = $this->getMock('\Magento\Catalog\Model\Product\Type\AbstractType', [], [], '', false);
79-
$this->scopeConfig = $this->getMock('\Magento\Framework\App\Config\ScopeConfigInterface', [], [], '', false);
80-
$this->imageHelper = $this->getMock('\Magento\Catalog\Helper\Image', [], [], '', false);
81-
$this->urlBuilder = $this->getMock('\Magento\Framework\UrlInterface');
128+
$this->scopeConfig = $this->getMock(
129+
\Magento\Framework\App\Config\ScopeConfigInterface::class,
130+
[],
131+
[],
132+
'',
133+
false
134+
);
135+
$this->imageHelper = $this->getMock(\Magento\Catalog\Helper\Image::class, [], [], '', false);
136+
$this->urlBuilder = $this->getMock(\Magento\Framework\UrlInterface::class);
137+
138+
$this->swatchAttributesProvider = self::getMockBuilder(SwatchAttributesProvider::class)
139+
->setMethods(['provide'])
140+
->disableOriginalConstructor()
141+
->getMock();
142+
143+
$this->contextMock = self::getMockBuilder(\Magento\Catalog\Block\Product\Context::class)
144+
->disableOriginalConstructor()
145+
->getMock();
146+
147+
$this->eventManager = self::getMockBuilder(\Magento\Framework\Event\Manager::class)
148+
->disableOriginalConstructor()
149+
->getMock();
150+
151+
$this->resolver = self::getMockBuilder(\Magento\Framework\View\Element\Template\File\Resolver::class)
152+
->setMethods(['getTemplateFileName'])
153+
->disableOriginalConstructor()
154+
->getMock();
155+
156+
$this->cacheState = self::getMockBuilder(\Magento\Framework\App\Cache\StateInterface::class)
157+
->disableOriginalConstructor()
158+
->getMockForAbstractClass();
159+
160+
$this->directory = self::getMockBuilder(\Magento\Framework\Filesystem\Directory\ReadInterface::class)
161+
->disableOriginalConstructor()
162+
->getMockForAbstractClass();
163+
164+
$this->validator = self::getMockBuilder(\Magento\Framework\View\Element\Template\File\Validator::class)
165+
->disableOriginalConstructor()
166+
->getMock();
167+
168+
$this->templateEnginePool = self::getMockBuilder(
169+
\Magento\Framework\View\TemplateEnginePool::class
170+
)
171+
->disableOriginalConstructor()
172+
->getMock();
173+
174+
$this->contextMock->expects($this->once())->method('getResolver')->willReturn($this->resolver);
175+
$this->contextMock->expects($this->once())->method('getEventManager')->willReturn($this->eventManager);
176+
$this->contextMock->expects($this->once())->method('getScopeConfig')->willReturn($this->scopeConfig);
177+
$this->contextMock->expects($this->once())->method('getCacheState')->willReturn($this->cacheState);
178+
$this->contextMock->expects($this->once())->method('getValidator')->willReturn($this->validator);
179+
$this->contextMock->expects($this->once())->method('getEnginePool')->willReturn($this->templateEnginePool);
82180

83-
$objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
84181
$this->configurable = $objectManagerHelper->getObject(
85-
'\Magento\Swatches\Block\Product\Renderer\Listing\Configurable',
182+
\Magento\Swatches\Block\Product\Renderer\Listing\Configurable::class,
86183
[
184+
'context' => $this->contextMock,
87185
'scopeConfig' => $this->scopeConfig,
88186
'imageHelper' => $this->imageHelper,
89187
'urlBuilder' => $this->urlBuilder,
@@ -96,9 +194,12 @@ public function setUp()
96194
'currentCustomer' => $this->currentCustomer,
97195
'priceCurrency' => $this->priceCurrency,
98196
'configurableAttributeData' => $this->configurableAttributeData,
197+
'swatchAttributesProvider' => $this->swatchAttributesProvider,
99198
'data' => [],
100199
]
101200
);
201+
202+
$objectManagerHelper->setBackwardCompatibleProperty($this->configurable, 'directory', $this->directory);
102203
}
103204

104205
/**
@@ -176,32 +277,42 @@ public function testGetJsonSwatchUsedInProductListing()
176277
$this->configurable->getJsonSwatchConfig();
177278
}
178279

280+
/**
281+
* @return void
282+
*/
179283
private function prepareGetJsonSwatchConfig()
180284
{
181-
$product1 = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false);
285+
$product1 = $this->getMock(\Magento\Catalog\Model\Product::class, [], [], '', false);
182286
$product1->expects($this->any())->method('getData')->with('code')->willReturn(1);
183287

184-
$product2 = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false);
288+
$product2 = $this->getMock(\Magento\Catalog\Model\Product::class, [], [], '', false);
185289
$product2->expects($this->any())->method('getData')->with('code')->willReturn(3);
186290

187291
$simpleProducts = [$product1, $product2];
188292
$configurableType = $this->getMock(
189-
'\Magento\ConfigurableProduct\Model\Product\Type\Configurable',
293+
\Magento\ConfigurableProduct\Model\Product\Type\Configurable::class,
190294
[],
191295
[],
192296
'',
193297
false
194298
);
195-
$configurableType->expects($this->atLeastOnce())->method('getSalableUsedProducts')->with($this->product, null)
299+
$configurableType->expects($this->atLeastOnce())->method('getSalableUsedProducts')
300+
->with($this->product, null)
196301
->willReturn($simpleProducts);
197302
$this->product->expects($this->any())->method('getTypeInstance')->willReturn($configurableType);
198303

199-
$productAttribute1 = $this->getMock('\Magento\Eav\Model\Entity\Attribute\AbstractAttribute', [], [], '', false);
304+
$productAttribute1 = $this->getMock(
305+
\Magento\Eav\Model\Entity\Attribute\AbstractAttribute::class,
306+
[],
307+
[],
308+
'',
309+
false
310+
);
200311
$productAttribute1->expects($this->any())->method('getId')->willReturn(1);
201312
$productAttribute1->expects($this->any())->method('getAttributeCode')->willReturn('code');
202313

203314
$attribute1 = $this->getMock(
204-
'\Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute',
315+
\Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute::class,
205316
['getProductAttribute'],
206317
[],
207318
'',
@@ -212,4 +323,72 @@ private function prepareGetJsonSwatchConfig()
212323
$this->helper->expects($this->any())->method('getAllowAttributes')->with($this->product)
213324
->willReturn([$attribute1]);
214325
}
326+
327+
/**
328+
* @return void
329+
*/
330+
public function testToHtmlNoSwatches()
331+
{
332+
$this->swatchAttributesProvider->expects(self::atLeastOnce())
333+
->method('provide')
334+
->with($this->product)
335+
->willReturn([]);
336+
337+
$this->configurable->setProduct($this->product);
338+
339+
self::assertEmpty($this->configurable->toHtml());
340+
}
341+
342+
/**
343+
* @return void
344+
*/
345+
public function testToHtmlSwatches()
346+
{
347+
$attribute = self::getMockBuilder(
348+
\Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute::class
349+
)
350+
->disableOriginalConstructor()
351+
->getMock();
352+
353+
$this->swatchAttributesProvider->expects(self::atLeastOnce())
354+
->method('provide')
355+
->with($this->product)
356+
->willReturn([$attribute]);
357+
358+
$engine = self::getMockBuilder(\Magento\Framework\View\TemplateEngineInterface::class)
359+
->getMockForAbstractClass();
360+
361+
$engine->expects(self::atLeastOnce())
362+
->method('render')
363+
->with($this->configurable, 'product/listing/renderer.phtml')
364+
->willReturn('<li>Swatches listing</li>');
365+
366+
$this->templateEnginePool->expects(self::atLeastOnce())
367+
->method('get')
368+
->withAnyParameters()
369+
->willReturn($engine);
370+
371+
$this->configurable->setProduct($this->product);
372+
$this->configurable->setTemplate('product/listing/renderer.phtml');
373+
$this->configurable->setArea('frontend');
374+
375+
$this->resolver->expects(self::atLeastOnce())
376+
->method('getTemplateFileName')
377+
->willReturn('product/listing/renderer.phtml');
378+
379+
$this->directory->expects(self::atLeastOnce())
380+
->method('getRelativePath')
381+
->with('product/listing/renderer.phtml')
382+
->willReturn('product/listing/renderer.phtml');
383+
384+
$this->validator->expects(self::atLeastOnce())
385+
->method('isValid')
386+
->with('product/listing/renderer.phtml')
387+
->willReturn(true);
388+
389+
$html = $this->configurable->toHtml();
390+
391+
self::assertNotEmpty($html);
392+
self::assertEquals('<li>Swatches listing</li>', $html);
393+
}
215394
}

dev/tests/functional/lib/Magento/Mtf/Util/Command/Cli.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ public function execute($command, $options = [])
5858
*/
5959
private function prepareUrl($command, $options = [])
6060
{
61-
$command .= ' ' . implode(' ', $options);
61+
if ($options) {
62+
$command .= ' ' . implode(' ', $options);
63+
}
6264
return $_ENV['app_frontend_url'] . self::URL . '?command=' . urlencode($command);
6365
}
6466
}

dev/tests/functional/tests/app/Magento/Config/Test/TestStep/SetupConfigurationStep.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,12 @@ public function run()
9696
$config->persist();
9797
$result = array_replace_recursive($result, $config->getSection());
9898
}
99-
if ($this->flushCache) {
100-
$this->cache->flush();
101-
}
10299
}
100+
101+
if ($this->flushCache) {
102+
$this->cache->flush();
103+
}
104+
103105
$config = $this->fixtureFactory->createByCode('configData', ['data' => $result]);
104106

105107
return ['config' => $config];

0 commit comments

Comments
 (0)