1717
1818namespace OpenMage \Tests \Unit \Mage \Core \Helper ;
1919
20+ use Generator ;
2021use Mage ;
2122use Mage_Core_Helper_Url ;
2223use PHPUnit \Framework \TestCase ;
2324
2425class UrlTest extends TestCase
2526{
26- public const TEST_URL_1 = 'http ://example.com?foo=ba ' ;
27+ public const TEST_URL_BASE = 'https ://example.com ' ;
2728
28- public const TEST_URL_2 = 'http ://example.com?foo=bar&boo=baz ' ;
29+ public const TEST_URL_PARAM = 'https ://example.com?foo=bar ' ;
2930
30- public const TEST_URL_PUNY = 'http://XN--example.com?foo=bar&boo=baz ' ;
31+ public const TEST_URL_PARAMS = 'https://example.com?foo=bar&BOO=baz ' ;
32+
33+ public const TEST_URL_SID1 = 'https://example.com?SID=S&foo=bar&BOO=baz ' ;
34+
35+ public const TEST_URL_SID2 = 'https://example.com?___SID=S&foo=bar&BOO=baz ' ;
36+
37+ public const TEST_URL_SID_BOTH = 'https://example.com?___SID=S&SID=S&foo=bar&BOO=baz ' ;
38+
39+ public const TEST_URL_PUNY = 'https://XN--example.com?foo=bar&BOO=baz ' ;
3140
3241 public Mage_Core_Helper_Url $ subject ;
3342
@@ -47,13 +56,25 @@ public function testGetCurrentBase64Url(): void
4756 }
4857
4958 /**
59+ * @dataProvider provideGetEncodedUrl
5060 * @group Mage_Core
5161 * @group Mage_Core_Helper
5262 */
53- public function testGetEncodedUrl (): void
63+ public function testGetEncodedUrl (string $ expectedResult , ?string $ url ): void
64+ {
65+ $ this ->assertSame ($ expectedResult , $ this ->subject ->getEncodedUrl ($ url ));
66+ }
67+
68+ public function provideGetEncodedUrl (): Generator
5469 {
55- $ this ->assertIsString ($ this ->subject ->getEncodedUrl ());
56- $ this ->assertIsString ($ this ->subject ->getEncodedUrl (self ::TEST_URL_1 ));
70+ yield 'null ' => [
71+ 'aHR0cDovLw,, ' ,
72+ null ,
73+ ];
74+ yield 'base url ' => [
75+ 'aHR0cHM6Ly9leGFtcGxlLmNvbQ,, ' ,
76+ self ::TEST_URL_BASE ,
77+ ];
5778 }
5879
5980 /**
@@ -66,25 +87,98 @@ public function testGetHomeUrl(): void
6687 }
6788
6889 /**
90+ * @dataProvider provideAddRequestParam
6991 * @group Mage_Core
7092 * @group Mage_Core_Helper
7193 */
72- public function testAddRequestParam (): void
94+ public function testAddRequestParam (string $ expectedResult , string $ url , array $ param ): void
7395 {
74- $ this ->assertIsString ($ this ->subject ->addRequestParam (self ::TEST_URL_1 , [0 => 'int ' ]));
75- $ this ->assertIsString ($ this ->subject ->addRequestParam (self ::TEST_URL_1 , ['null ' => null ]));
76- $ this ->assertIsString ($ this ->subject ->addRequestParam (self ::TEST_URL_1 , ['key ' => 'value ' ]));
77- $ this ->assertIsString ($ this ->subject ->addRequestParam (self ::TEST_URL_1 , ['key ' => ['subKey ' => 'subValue ' ]]));
96+ $ this ->assertSame ($ expectedResult , $ this ->subject ->addRequestParam ($ url , $ param ));
97+ }
98+
99+ public function provideAddRequestParam (): Generator
100+ {
101+ yield 'int key ' => [
102+ self ::TEST_URL_BASE . '? ' ,
103+ self ::TEST_URL_BASE ,
104+ [0 => 'int ' ],
105+ ];
106+ yield 'int value ' => [
107+ self ::TEST_URL_BASE . '?int=0 ' ,
108+ self ::TEST_URL_BASE ,
109+ ['int ' => 0 ],
110+ ];
111+ yield 'null ' => [
112+ self ::TEST_URL_BASE . '?null ' ,
113+ self ::TEST_URL_BASE ,
114+ ['null ' => null ],
115+ ];
116+ yield 'string ' => [
117+ self ::TEST_URL_PARAM ,
118+ self ::TEST_URL_BASE ,
119+ ['foo ' => 'bar ' ],
120+ ];
121+ yield 'string extend ' => [
122+ self ::TEST_URL_PARAMS ,
123+ self ::TEST_URL_PARAM ,
124+ ['BOO ' => 'baz ' ],
125+ ];
126+ yield 'array ' => [
127+ self ::TEST_URL_BASE . '?key[]=subValue ' ,
128+ self ::TEST_URL_BASE ,
129+ ['key ' => ['subKey ' => 'subValue ' ]],
130+ ];
78131 }
79132
80133 /**
134+ * @dataProvider provideRemoveRequestParam
81135 * @group Mage_Core
82136 * @group Mage_Core_Helper
83137 */
84- public function testRemoveRequestParam (): void
138+ public function testRemoveRequestParam (string $ expectedResult , string $ url , string $ paramKey , bool $ caseSensitive = false ): void
139+ {
140+ $ this ->assertSame ($ expectedResult , $ this ->subject ->removeRequestParam ($ url , $ paramKey , $ caseSensitive ));
141+ }
142+
143+ public function provideRemoveRequestParam (): Generator
85144 {
86- $ this ->assertIsString ($ this ->subject ->removeRequestParam (self ::TEST_URL_1 , 'foo ' ));
87- $ this ->assertIsString ($ this ->subject ->removeRequestParam (self ::TEST_URL_2 , 'foo ' ));
145+ yield 'remove #1 ' => [
146+ self ::TEST_URL_BASE ,
147+ self ::TEST_URL_PARAM ,
148+ 'foo '
149+ ];
150+ yield 'remove #2 ' => [
151+ self ::TEST_URL_PARAMS ,
152+ self ::TEST_URL_PARAMS ,
153+ 'boo '
154+ ];
155+ yield 'remove #1 case sensitive ' => [
156+ self ::TEST_URL_PARAM ,
157+ self ::TEST_URL_PARAM ,
158+ 'FOO ' ,
159+ true
160+ ];
161+ yield 'remove #2 case sensitive ' => [
162+ self ::TEST_URL_PARAM ,
163+ self ::TEST_URL_PARAMS ,
164+ 'BOO ' ,
165+ true
166+ ];
167+ yield 'not-exists ' => [
168+ self ::TEST_URL_PARAMS ,
169+ self ::TEST_URL_PARAMS ,
170+ 'not-exists '
171+ ];
172+ yield '___SID ' => [
173+ self ::TEST_URL_SID1 ,
174+ self ::TEST_URL_SID_BOTH ,
175+ '___SID '
176+ ];
177+ yield 'SID ' => [
178+ self ::TEST_URL_SID2 ,
179+ self ::TEST_URL_SID_BOTH ,
180+ 'SID '
181+ ];
88182 }
89183
90184 /**
@@ -93,16 +187,18 @@ public function testRemoveRequestParam(): void
93187 */
94188 public function testEncodePunycode (): void
95189 {
96- $ this ->assertIsString ($ this ->subject ->encodePunycode (self ::TEST_URL_1 ));
97- $ this ->assertIsString ($ this ->subject ->encodePunycode (self ::TEST_URL_PUNY ));
190+ $ this ->assertSame (self ::TEST_URL_BASE , $ this ->subject ->encodePunycode (self ::TEST_URL_BASE ));
191+ $ this ->assertSame (self ::TEST_URL_PUNY , $ this ->subject ->encodePunycode (self ::TEST_URL_PUNY ));
192+ $ this ->markTestIncomplete ('This test has to be checked. ' );
98193 }
99194 /**
100195 * @group Mage_Core
101196 * @group Mage_Core_Helper
102197 */
103198 public function testDecodePunycode (): void
104199 {
105- $ this ->assertIsString ($ this ->subject ->decodePunycode (self ::TEST_URL_1 ));
106- $ this ->assertIsString ($ this ->subject ->decodePunycode (self ::TEST_URL_PUNY ));
200+ $ this ->assertSame (self ::TEST_URL_BASE , $ this ->subject ->decodePunycode (self ::TEST_URL_BASE ));
201+ $ this ->assertSame ('https://?foo=bar&BOO=baz ' , $ this ->subject ->decodePunycode (self ::TEST_URL_PUNY ));
202+ $ this ->markTestIncomplete ('This test has to be checked. ' );
107203 }
108204}
0 commit comments