Skip to content

Commit

Permalink
Merge pull request #925 from magento-east/MAGETWO-66117
Browse files Browse the repository at this point in the history
[East] Stabilize 2.1-develop
  • Loading branch information
Volodymyr Klymenko authored Mar 14, 2017
2 parents 506a93f + 298710d commit 81d30a9
Show file tree
Hide file tree
Showing 8 changed files with 227 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,44 +143,46 @@ public function intervalsDataProvider()
return [
[
'_period' => 'day',
'_from' => new \DateTime('-3 day'),
'_to' => new \DateTime('+3 day'),
'_from' => new \DateTime('-3 day', new \DateTimeZone('UTC')),
'_to' => new \DateTime('+3 day', new \DateTimeZone('UTC')),
'size' => 7
],
[
'_period' => 'month',
'_from' => new \DateTime('2015-01-15 11:11:11'),
'_to' => new \DateTime('2015-01-25 11:11:11'),
'_from' => new \DateTime('2015-01-15 11:11:11', new \DateTimeZone('UTC')),
'_to' => new \DateTime('2015-01-25 11:11:11', new \DateTimeZone('UTC')),
'size' => 1
],
[
'_period' => 'month',
'_from' => new \DateTime('2015-01-15 11:11:11'),
'_to' => new \DateTime('2015-02-25 11:11:11'),
'_from' => new \DateTime('2015-01-15 11:11:11', new \DateTimeZone('UTC')),
'_to' => new \DateTime('2015-02-25 11:11:11', new \DateTimeZone('UTC')),
'size' => 2
],
[
'_period' => 'year',
'_from' => new \DateTime('2015-01-15 11:11:11'),
'_to' => new \DateTime('2015-01-25 11:11:11'),
'_from' => new \DateTime('2015-01-15 11:11:11', new \DateTimeZone('UTC')),
'_to' => new \DateTime('2015-01-25 11:11:11', new \DateTimeZone('UTC')),
'size' => 1
],
[
'_period' => 'year',
'_from' => new \DateTime('2014-01-15 11:11:11'),
'_to' => new \DateTime('2015-01-25 11:11:11'),
'_from' => new \DateTime('2014-01-15 11:11:11', new \DateTimeZone('UTC')),
'_to' => new \DateTime('2015-01-25 11:11:11', new \DateTimeZone('UTC')),
'size' => 2
],
[
'_period' => null,
'_from' => new \DateTime('-3 day'),
'_to' => new \DateTime('+3 day'),
'_from' => new \DateTime('-3 day', new \DateTimeZone('UTC')),
'_to' => new \DateTime('+3 day', new \DateTimeZone('UTC')),
'size' => 0
]
];
}

/**
* Format datetime.
*
* @return string
*/
public function formatDateTime()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected function getRendererTemplate()
protected function _toHtml()
{
$output = '';
if ($this->isProductHasSwatchAttribute) {
if ($this->isProductHasSwatchAttribute()) {
$output = parent::_toHtml();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
*/
namespace Magento\Swatches\Test\Unit\Block\Product\Renderer\Listing;

use Magento\Swatches\Block\Product\Renderer\Configurable;
use \Magento\Swatches\Block\Product\Renderer\Listing\Configurable;
use Magento\Swatches\Model\SwatchAttributesProvider;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.TooManyFields)
*/
class ConfigurableTest extends \PHPUnit_Framework_TestCase
{
Expand Down Expand Up @@ -57,33 +59,129 @@ class ConfigurableTest extends \PHPUnit_Framework_TestCase
/** @var \Magento\Framework\UrlInterface|\PHPUnit_Framework_MockObject_MockObject */
private $urlBuilder;

/** @var SwatchAttributesProvider|\PHPUnit_Framework_MockObject_MockObject */
private $swatchAttributesProvider;

/** @var \Magento\Catalog\Block\Product\Context|\PHPUnit_Framework_MockObject_MockObject */
private $contextMock;

/** @var \Magento\Framework\View\Element\Template\File\Resolver|\PHPUnit_Framework_MockObject_MockObject */
private $resolver;

/** @var \Magento\Framework\Event\Manager|\PHPUnit_Framework_MockObject_MockObject */
private $eventManager;

/** @var \Magento\Framework\App\Cache\StateInterface|\PHPUnit_Framework_MockObject_MockObject */
private $cacheState;

/** @var \Magento\Framework\Filesystem\Directory\ReadInterface|\PHPUnit_Framework_MockObject_MockObject */
private $directory;

/** @var \Magento\Framework\View\Element\Template\File\Validator|\PHPUnit_Framework_MockObject_MockObject */
private $validator;

/** @var \Magento\Framework\View\TemplateEnginePool|\PHPUnit_Framework_MockObject_MockObject */
private $templateEnginePool;

/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function setUp()
{
$this->arrayUtils = $this->getMock('\Magento\Framework\Stdlib\ArrayUtils', [], [], '', false);
$this->jsonEncoder = $this->getMock('\Magento\Framework\Json\EncoderInterface', [], [], '', false);
$this->helper = $this->getMock('\Magento\ConfigurableProduct\Helper\Data', [], [], '', false);
$this->swatchHelper = $this->getMock('\Magento\Swatches\Helper\Data', [], [], '', false);
$this->swatchMediaHelper = $this->getMock('\Magento\Swatches\Helper\Media', [], [], '', false);
$this->catalogProduct = $this->getMock('\Magento\Catalog\Helper\Product', [], [], '', false);
$this->currentCustomer = $this->getMock('\Magento\Customer\Helper\Session\CurrentCustomer', [], [], '', false);
$this->priceCurrency = $this->getMock('\Magento\Framework\Pricing\PriceCurrencyInterface', [], [], '', false);
$objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);

$this->arrayUtils = $this->getMock(\Magento\Framework\Stdlib\ArrayUtils::class, [], [], '', false);
$this->jsonEncoder = $this->getMock(\Magento\Framework\Json\EncoderInterface::class, [], [], '', false);
$this->helper = $this->getMock(\Magento\ConfigurableProduct\Helper\Data::class, [], [], '', false);
$this->swatchHelper = $this->getMock(\Magento\Swatches\Helper\Data::class, [], [], '', false);
$this->swatchMediaHelper = $this->getMock(\Magento\Swatches\Helper\Media::class, [], [], '', false);
$this->catalogProduct = $this->getMock(\Magento\Catalog\Helper\Product::class, [], [], '', false);
$this->currentCustomer = $this->getMock(
\Magento\Customer\Helper\Session\CurrentCustomer::class,
[],
[],
'',
false
);
$this->priceCurrency = $this->getMock(
\Magento\Framework\Pricing\PriceCurrencyInterface::class,
[],
[],
'',
false
);
$this->configurableAttributeData = $this->getMock(
'Magento\ConfigurableProduct\Model\ConfigurableAttributeData',
\Magento\ConfigurableProduct\Model\ConfigurableAttributeData::class,
[],
[],
'',
false
);
$this->product = $this->getMock(\Magento\Catalog\Model\Product::class, [], [], '', false);
$this->typeInstance = $this->getMock(
\Magento\Catalog\Model\Product\Type\AbstractType::class,
[],
[],
'',
false
);
$this->product = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false);
$this->typeInstance = $this->getMock('\Magento\Catalog\Model\Product\Type\AbstractType', [], [], '', false);
$this->scopeConfig = $this->getMock('\Magento\Framework\App\Config\ScopeConfigInterface', [], [], '', false);
$this->imageHelper = $this->getMock('\Magento\Catalog\Helper\Image', [], [], '', false);
$this->urlBuilder = $this->getMock('\Magento\Framework\UrlInterface');
$this->scopeConfig = $this->getMock(
\Magento\Framework\App\Config\ScopeConfigInterface::class,
[],
[],
'',
false
);
$this->imageHelper = $this->getMock(\Magento\Catalog\Helper\Image::class, [], [], '', false);
$this->urlBuilder = $this->getMock(\Magento\Framework\UrlInterface::class);

$this->swatchAttributesProvider = self::getMockBuilder(SwatchAttributesProvider::class)
->setMethods(['provide'])
->disableOriginalConstructor()
->getMock();

$this->contextMock = self::getMockBuilder(\Magento\Catalog\Block\Product\Context::class)
->disableOriginalConstructor()
->getMock();

$this->eventManager = self::getMockBuilder(\Magento\Framework\Event\Manager::class)
->disableOriginalConstructor()
->getMock();

$this->resolver = self::getMockBuilder(\Magento\Framework\View\Element\Template\File\Resolver::class)
->setMethods(['getTemplateFileName'])
->disableOriginalConstructor()
->getMock();

$this->cacheState = self::getMockBuilder(\Magento\Framework\App\Cache\StateInterface::class)
->disableOriginalConstructor()
->getMockForAbstractClass();

$this->directory = self::getMockBuilder(\Magento\Framework\Filesystem\Directory\ReadInterface::class)
->disableOriginalConstructor()
->getMockForAbstractClass();

$this->validator = self::getMockBuilder(\Magento\Framework\View\Element\Template\File\Validator::class)
->disableOriginalConstructor()
->getMock();

$this->templateEnginePool = self::getMockBuilder(
\Magento\Framework\View\TemplateEnginePool::class
)
->disableOriginalConstructor()
->getMock();

$this->contextMock->expects($this->once())->method('getResolver')->willReturn($this->resolver);
$this->contextMock->expects($this->once())->method('getEventManager')->willReturn($this->eventManager);
$this->contextMock->expects($this->once())->method('getScopeConfig')->willReturn($this->scopeConfig);
$this->contextMock->expects($this->once())->method('getCacheState')->willReturn($this->cacheState);
$this->contextMock->expects($this->once())->method('getValidator')->willReturn($this->validator);
$this->contextMock->expects($this->once())->method('getEnginePool')->willReturn($this->templateEnginePool);

$objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->configurable = $objectManagerHelper->getObject(
'\Magento\Swatches\Block\Product\Renderer\Listing\Configurable',
\Magento\Swatches\Block\Product\Renderer\Listing\Configurable::class,
[
'context' => $this->contextMock,
'scopeConfig' => $this->scopeConfig,
'imageHelper' => $this->imageHelper,
'urlBuilder' => $this->urlBuilder,
Expand All @@ -96,9 +194,12 @@ public function setUp()
'currentCustomer' => $this->currentCustomer,
'priceCurrency' => $this->priceCurrency,
'configurableAttributeData' => $this->configurableAttributeData,
'swatchAttributesProvider' => $this->swatchAttributesProvider,
'data' => [],
]
);

$objectManagerHelper->setBackwardCompatibleProperty($this->configurable, 'directory', $this->directory);
}

/**
Expand Down Expand Up @@ -176,32 +277,42 @@ public function testGetJsonSwatchUsedInProductListing()
$this->configurable->getJsonSwatchConfig();
}

/**
* @return void
*/
private function prepareGetJsonSwatchConfig()
{
$product1 = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false);
$product1 = $this->getMock(\Magento\Catalog\Model\Product::class, [], [], '', false);
$product1->expects($this->any())->method('getData')->with('code')->willReturn(1);

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

$simpleProducts = [$product1, $product2];
$configurableType = $this->getMock(
'\Magento\ConfigurableProduct\Model\Product\Type\Configurable',
\Magento\ConfigurableProduct\Model\Product\Type\Configurable::class,
[],
[],
'',
false
);
$configurableType->expects($this->atLeastOnce())->method('getSalableUsedProducts')->with($this->product, null)
$configurableType->expects($this->atLeastOnce())->method('getSalableUsedProducts')
->with($this->product, null)
->willReturn($simpleProducts);
$this->product->expects($this->any())->method('getTypeInstance')->willReturn($configurableType);

$productAttribute1 = $this->getMock('\Magento\Eav\Model\Entity\Attribute\AbstractAttribute', [], [], '', false);
$productAttribute1 = $this->getMock(
\Magento\Eav\Model\Entity\Attribute\AbstractAttribute::class,
[],
[],
'',
false
);
$productAttribute1->expects($this->any())->method('getId')->willReturn(1);
$productAttribute1->expects($this->any())->method('getAttributeCode')->willReturn('code');

$attribute1 = $this->getMock(
'\Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute',
\Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute::class,
['getProductAttribute'],
[],
'',
Expand All @@ -212,4 +323,72 @@ private function prepareGetJsonSwatchConfig()
$this->helper->expects($this->any())->method('getAllowAttributes')->with($this->product)
->willReturn([$attribute1]);
}

/**
* @return void
*/
public function testToHtmlNoSwatches()
{
$this->swatchAttributesProvider->expects(self::atLeastOnce())
->method('provide')
->with($this->product)
->willReturn([]);

$this->configurable->setProduct($this->product);

self::assertEmpty($this->configurable->toHtml());
}

/**
* @return void
*/
public function testToHtmlSwatches()
{
$attribute = self::getMockBuilder(
\Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute::class
)
->disableOriginalConstructor()
->getMock();

$this->swatchAttributesProvider->expects(self::atLeastOnce())
->method('provide')
->with($this->product)
->willReturn([$attribute]);

$engine = self::getMockBuilder(\Magento\Framework\View\TemplateEngineInterface::class)
->getMockForAbstractClass();

$engine->expects(self::atLeastOnce())
->method('render')
->with($this->configurable, 'product/listing/renderer.phtml')
->willReturn('<li>Swatches listing</li>');

$this->templateEnginePool->expects(self::atLeastOnce())
->method('get')
->withAnyParameters()
->willReturn($engine);

$this->configurable->setProduct($this->product);
$this->configurable->setTemplate('product/listing/renderer.phtml');
$this->configurable->setArea('frontend');

$this->resolver->expects(self::atLeastOnce())
->method('getTemplateFileName')
->willReturn('product/listing/renderer.phtml');

$this->directory->expects(self::atLeastOnce())
->method('getRelativePath')
->with('product/listing/renderer.phtml')
->willReturn('product/listing/renderer.phtml');

$this->validator->expects(self::atLeastOnce())
->method('isValid')
->with('product/listing/renderer.phtml')
->willReturn(true);

$html = $this->configurable->toHtml();

self::assertNotEmpty($html);
self::assertEquals('<li>Swatches listing</li>', $html);
}
}
4 changes: 3 additions & 1 deletion dev/tests/functional/lib/Magento/Mtf/Util/Command/Cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ public function execute($command, $options = [])
*/
private function prepareUrl($command, $options = [])
{
$command .= ' ' . implode(' ', $options);
if ($options) {
$command .= ' ' . implode(' ', $options);
}
return $_ENV['app_frontend_url'] . self::URL . '?command=' . urlencode($command);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,12 @@ public function run()
$config->persist();
$result = array_replace_recursive($result, $config->getSection());
}
if ($this->flushCache) {
$this->cache->flush();
}
}

if ($this->flushCache) {
$this->cache->flush();
}

$config = $this->fixtureFactory->createByCode('configData', ['data' => $result]);

return ['config' => $config];
Expand Down
Loading

0 comments on commit 81d30a9

Please sign in to comment.