@@ -17,15 +17,24 @@ class WidgetTest extends \PHPUnit_Framework_TestCase
17
17
*/
18
18
protected $ widget ;
19
19
20
+ /**
21
+ * @var \Magento\Widget\Helper\Conditions
22
+ */
23
+ private $ conditionsHelper ;
24
+
20
25
public function setUp ()
21
26
{
22
27
$ this ->dataStorageMock = $ this ->getMockBuilder ('Magento\Widget\Model\Config\Data ' )
23
28
->disableOriginalConstructor ()
24
29
->getMock ();
30
+ $ this ->conditionsHelper = $ this ->getMockBuilder ('\Magento\Widget\Helper\Conditions ' )
31
+ ->setMethods (['encode ' ])
32
+ ->disableOriginalConstructor ()
33
+ ->getMock ();
25
34
$ objectManagerHelper = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
26
35
$ this ->widget = $ objectManagerHelper ->getObject (
27
36
'Magento\Widget\Model\Widget ' ,
28
- ['dataStorage ' => $ this ->dataStorageMock ]
37
+ ['dataStorage ' => $ this ->dataStorageMock , ' conditionsHelper ' => $ this -> conditionsHelper ]
29
38
);
30
39
}
31
40
@@ -119,4 +128,37 @@ public function testGetConfigAsObjectWidgetNoFound()
119
128
$ this ->assertInstanceOf ('Magento\Framework\DataObject ' , $ resultObject );
120
129
$ this ->assertSame ([], $ resultObject ->getData ());
121
130
}
131
+
132
+ public function testGetWidgetDeclaration ()
133
+ {
134
+ $ mathRandomMock = $ this ->getMock ('\Magento\Framework\Math\Random ' , ['getRandomString ' ], [], '' , false );
135
+ $ mathRandomMock ->expects ($ this ->any ())->method ('getRandomString ' )->willReturn ('asdf ' );
136
+ $ reflection = new \ReflectionClass (get_class ($ this ->widget ));
137
+ $ reflectionProperty = $ reflection ->getProperty ('mathRandom ' );
138
+ $ reflectionProperty ->setAccessible (true );
139
+ $ reflectionProperty ->setValue ($ this ->widget , $ mathRandomMock );
140
+
141
+ $ conditions = [
142
+ [
143
+ 'type ' => 'Magento\CatalogWidget\Model\Rule\Condition\Combine ' ,
144
+ 'aggregator ' => 'all ' ,
145
+ 'value ' => '1 ' ,
146
+ 'new_child ' => ''
147
+ ]
148
+ ];
149
+ $ params = [
150
+ 'title ' => 'my widget ' ,
151
+ 'show_pager ' => '1 ' ,
152
+ 'products_per_page ' => '5 ' ,
153
+ 'products_count ' => '10 ' ,
154
+ 'template ' => 'product/widget/content/grid.phtml ' ,
155
+ 'conditions ' => $ conditions
156
+ ];
157
+ $ this ->conditionsHelper ->expects ($ this ->once ())->method ('encode ' )->with ($ conditions )
158
+ ->willReturn ('encoded-conditions-string ' );
159
+ $ result = $ this ->widget ->getWidgetDeclaration ('Magento\CatalogWidget\Block\Product\ProductsList ' , $ params );
160
+ $ this ->assertContains ('{{widget type="Magento\CatalogWidget\Block\Product\ProductsList" ' , $ result );
161
+ $ this ->assertContains ('conditions_encoded="encoded-conditions-string" ' , $ result );
162
+ $ this ->assertContains ('page_var_name="pasdf"}} ' , $ result );
163
+ }
122
164
}
0 commit comments