Skip to content
Snippets Groups Projects
Commit f46da7b3 authored by Yaroslav Onischenko's avatar Yaroslav Onischenko
Browse files

MAGETWO-36035: Pagination in Catalog Products List widget works incorrect with FPC

parent 9cdc523a
No related merge requests found
......@@ -53,7 +53,7 @@ class Widget
/**
* @var \Magento\Framework\Math\Random
*/
protected $mathRandom;
private $mathRandom;
/**
* @param \Magento\Framework\Escaper $escaper
......@@ -62,7 +62,6 @@ class Widget
* @param \Magento\Framework\View\Asset\Source $assetSource
* @param \Magento\Framework\View\FileSystem $viewFileSystem
* @param \Magento\Widget\Helper\Conditions $conditionsHelper
* @param \Magento\Framework\Math\Random $mathRandom
*/
public function __construct(
\Magento\Framework\Escaper $escaper,
......@@ -70,8 +69,7 @@ class Widget
\Magento\Framework\View\Asset\Repository $assetRepo,
\Magento\Framework\View\Asset\Source $assetSource,
\Magento\Framework\View\FileSystem $viewFileSystem,
\Magento\Widget\Helper\Conditions $conditionsHelper,
\Magento\Framework\Math\Random $mathRandom
\Magento\Widget\Helper\Conditions $conditionsHelper
) {
$this->escaper = $escaper;
$this->dataStorage = $dataStorage;
......@@ -79,7 +77,20 @@ class Widget
$this->assetSource = $assetSource;
$this->viewFileSystem = $viewFileSystem;
$this->conditionsHelper = $conditionsHelper;
$this->mathRandom = $mathRandom;
}
/**
* @return \Magento\Framework\Math\Random
*
* @deprecated
*/
private function getMathRandom()
{
if ($this->mathRandom === null) {
$this->mathRandom = \Magento\Framework\App\ObjectManager::getInstance()
->get('\Magento\Framework\Math\Random');
}
return $this->mathRandom;
}
/**
......@@ -310,7 +321,7 @@ class Widget
$directive .= sprintf(
' %s="%s"',
'page_var_name',
'p' . $this->mathRandom->getRandomString(5, \Magento\Framework\Math\Random::CHARS_LOWERS)
'p' . $this->getMathRandom()->getRandomString(5, \Magento\Framework\Math\Random::CHARS_LOWERS)
);
}
......
......@@ -17,15 +17,24 @@ class WidgetTest extends \PHPUnit_Framework_TestCase
*/
protected $widget;
/**
* @var \Magento\Widget\Helper\Conditions
*/
private $conditionsHelper;
public function setUp()
{
$this->dataStorageMock = $this->getMockBuilder('Magento\Widget\Model\Config\Data')
->disableOriginalConstructor()
->getMock();
$this->conditionsHelper = $this->getMockBuilder('\Magento\Widget\Helper\Conditions')
->setMethods(['encode'])
->disableOriginalConstructor()
->getMock();
$objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->widget = $objectManagerHelper->getObject(
'Magento\Widget\Model\Widget',
['dataStorage' => $this->dataStorageMock]
['dataStorage' => $this->dataStorageMock, 'conditionsHelper' => $this->conditionsHelper]
);
}
......@@ -119,4 +128,37 @@ class WidgetTest extends \PHPUnit_Framework_TestCase
$this->assertInstanceOf('Magento\Framework\DataObject', $resultObject);
$this->assertSame([], $resultObject->getData());
}
public function testGetWidgetDeclaration()
{
$mathRandomMock = $this->getMock('\Magento\Framework\Math\Random', ['getRandomString'], [], '', false);
$mathRandomMock->expects($this->any())->method('getRandomString')->willReturn('asdf');
$reflection = new \ReflectionClass(get_class($this->widget));
$reflectionProperty = $reflection->getProperty('mathRandom');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue($this->widget, $mathRandomMock);
$conditions = [
[
'type' => 'Magento\CatalogWidget\Model\Rule\Condition\Combine',
'aggregator' => 'all',
'value' => '1',
'new_child' => ''
]
];
$params = [
'title' => 'my widget',
'show_pager' => '1',
'products_per_page' => '5',
'products_count' => '10',
'template' => 'product/widget/content/grid.phtml',
'conditions' => $conditions
];
$this->conditionsHelper->expects($this->once())->method('encode')->with($conditions)
->willReturn('encoded-conditions-string');
$result = $this->widget->getWidgetDeclaration('Magento\CatalogWidget\Block\Product\ProductsList', $params);
$this->assertContains('{{widget type="Magento\CatalogWidget\Block\Product\ProductsList"', $result);
$this->assertContains('conditions_encoded="encoded-conditions-string"', $result);
$this->assertContains('page_var_name="pasdf"}}', $result);
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment