3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+
6
7
namespace Magento \Search \Test \Unit \Helper ;
7
8
8
9
/**
@@ -43,6 +44,11 @@ class DataTest extends \PHPUnit\Framework\TestCase
43
44
*/
44
45
protected $ storeManagerMock ;
45
46
47
+ /**
48
+ * @var \Magento\Framework\UrlInterface|\PHPUnit_Framework_MockObject_MockObject
49
+ */
50
+ private $ urlBuilderMock ;
51
+
46
52
protected function setUp ()
47
53
{
48
54
$ this ->stringMock = $ this ->createMock (\Magento \Framework \Stdlib \StringUtils::class);
@@ -53,9 +59,14 @@ protected function setUp()
53
59
->disableOriginalConstructor ()
54
60
->setMethods ([])
55
61
->getMock ();
62
+ $ this ->urlBuilderMock = $ this ->getMockBuilder (\Magento \Framework \UrlInterface::class)
63
+ ->setMethods (['getUrl ' ])
64
+ ->disableOriginalConstructor ()
65
+ ->getMockForAbstractClass ();
56
66
$ this ->contextMock = $ this ->createMock (\Magento \Framework \App \Helper \Context::class);
57
67
$ this ->contextMock ->expects ($ this ->any ())->method ('getScopeConfig ' )->willReturn ($ this ->scopeConfigMock );
58
68
$ this ->contextMock ->expects ($ this ->any ())->method ('getRequest ' )->willReturn ($ this ->requestMock );
69
+ $ this ->contextMock ->expects ($ this ->any ())->method ('getUrlBuilder ' )->willReturn ($ this ->urlBuilderMock );
59
70
60
71
$ this ->model = new \Magento \Search \Helper \Data (
61
72
$ this ->contextMock ,
@@ -126,4 +137,39 @@ public function queryTextDataProvider()
126
137
['testtest ' , 7 , 'testtes ' ],
127
138
];
128
139
}
140
+
141
+ /**
142
+ * Test getSuggestUrl() take into consideration type of request(secure, non-secure).
143
+ *
144
+ * @dataProvider getSuggestUrlDataProvider
145
+ * @param bool $isSecure
146
+ * @return void
147
+ */
148
+ public function testGetSuggestUrl (bool $ isSecure )
149
+ {
150
+ $ this ->requestMock ->expects (self ::once ())
151
+ ->method ('isSecure ' )
152
+ ->willReturn ($ isSecure );
153
+ $ this ->urlBuilderMock ->expects (self ::once ())
154
+ ->method ('getUrl ' )
155
+ ->with (self ::identicalTo ('search/ajax/suggest ' ), self ::identicalTo (['_secure ' => $ isSecure ]));
156
+ $ this ->model ->getSuggestUrl ();
157
+ }
158
+
159
+ /**
160
+ * Provide test data for testGetSuggestUrl() test.
161
+ *
162
+ * @return array
163
+ */
164
+ public function getSuggestUrlDataProvider ()
165
+ {
166
+ return [
167
+ 'non-secure ' => [
168
+ 'isSecure ' => false ,
169
+ ],
170
+ 'secure ' => [
171
+ 'secure ' => true ,
172
+ ],
173
+ ];
174
+ }
129
175
}
0 commit comments