33 * Copyright © Magento, Inc. All rights reserved.
44 * See COPYING.txt for license details.
55 */
6+
67namespace Magento \Search \Test \Unit \Helper ;
78
89/**
@@ -43,6 +44,11 @@ class DataTest extends \PHPUnit\Framework\TestCase
4344 */
4445 protected $ storeManagerMock ;
4546
47+ /**
48+ * @var \Magento\Framework\UrlInterface|\PHPUnit_Framework_MockObject_MockObject
49+ */
50+ private $ urlBuilderMock ;
51+
4652 protected function setUp ()
4753 {
4854 $ this ->stringMock = $ this ->createMock (\Magento \Framework \Stdlib \StringUtils::class);
@@ -53,9 +59,14 @@ protected function setUp()
5359 ->disableOriginalConstructor ()
5460 ->setMethods ([])
5561 ->getMock ();
62+ $ this ->urlBuilderMock = $ this ->getMockBuilder (\Magento \Framework \UrlInterface::class)
63+ ->setMethods (['getUrl ' ])
64+ ->disableOriginalConstructor ()
65+ ->getMockForAbstractClass ();
5666 $ this ->contextMock = $ this ->createMock (\Magento \Framework \App \Helper \Context::class);
5767 $ this ->contextMock ->expects ($ this ->any ())->method ('getScopeConfig ' )->willReturn ($ this ->scopeConfigMock );
5868 $ this ->contextMock ->expects ($ this ->any ())->method ('getRequest ' )->willReturn ($ this ->requestMock );
69+ $ this ->contextMock ->expects ($ this ->any ())->method ('getUrlBuilder ' )->willReturn ($ this ->urlBuilderMock );
5970
6071 $ this ->model = new \Magento \Search \Helper \Data (
6172 $ this ->contextMock ,
@@ -126,4 +137,39 @@ public function queryTextDataProvider()
126137 ['testtest ' , 7 , 'testtes ' ],
127138 ];
128139 }
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+ }
129175}
0 commit comments