6
6
namespace Magento \Framework ;
7
7
8
8
use Zend \Stdlib \Parameters ;
9
+ use Magento \TestFramework \Helper \Bootstrap ;
9
10
10
11
class UrlTest extends \PHPUnit_Framework_TestCase
11
12
{
@@ -16,7 +17,7 @@ class UrlTest extends \PHPUnit_Framework_TestCase
16
17
17
18
protected function setUp ()
18
19
{
19
- $ this ->_model = \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ()->create ('Magento\Framework\Url ' );
20
+ $ this ->_model = Bootstrap::getObjectManager ()->create ('Magento\Framework\Url ' );
20
21
}
21
22
22
23
public function testSetGetUseSession ()
@@ -77,6 +78,92 @@ public function testGetBaseUrlConfigured($params, $expectedUrl)
77
78
$ this ->assertEquals ($ expectedUrl , $ actualUrl );
78
79
}
79
80
81
+ /**
82
+ * Note: isolation flushes the URL memory cache
83
+ * @magentoAppIsolation enabled
84
+ *
85
+ * @magentoConfigFixture current_store web/secure/base_url http://sample.com/
86
+ * @magentoConfigFixture current_store web/unsecure/base_link_url http://sample.com/
87
+ * @magentoConfigFixture current_store web/secure/base_link_url https://sample.com/
88
+ * @magentoConfigFixture current_store web/secure/use_in_frontend 1
89
+ *
90
+ * @magentoAppArea frontend
91
+ */
92
+ public function testGetUnsecureUrlInSecureArea ()
93
+ {
94
+ /** @var \Magento\Framework\App\Request\Http $request */
95
+ $ request = Bootstrap::getObjectManager ()->create (\Magento \Framework \App \Request \Http::class);
96
+ //Emulate HTTPS request
97
+ $ request ->getServer ()->set ('HTTPS ' , 'on ' );
98
+ $ request ->getServer ()->set ('SERVER_PORT ' , 443 );
99
+
100
+ $ model = Bootstrap::getObjectManager ()->create (\Magento \Framework \Url::class, ['request ' => $ request ]);
101
+
102
+ $ secureUrl = $ model ->getUrl ('some/index/controller ' );
103
+ $ this ->assertStringStartsWith (
104
+ 'https://sample.com/index.php/some/index/controller/ ' ,
105
+ $ secureUrl ,
106
+ 'Default URL in secure area is incorrect '
107
+ );
108
+
109
+ $ secureUrl = $ model ->getUrl ('some/index/controller ' , ['_secure ' => true ]);
110
+ $ this ->assertStringStartsWith (
111
+ 'https://sample.com/index.php/some/index/controller/ ' ,
112
+ $ secureUrl ,
113
+ 'Secure URL in secure area is incorrect '
114
+ );
115
+
116
+ $ unsecureUrl = $ model ->getUrl ('some/index/controller ' , ['_secure ' => false ]);
117
+ $ this ->assertStringStartsWith (
118
+ 'http://sample.com/index.php/some/index/controller/ ' ,
119
+ $ unsecureUrl ,
120
+ 'Unsecure URL in secure area is incorrect '
121
+ );
122
+ }
123
+
124
+ /**
125
+ * Note: isolation flushes the URL memory cache
126
+ * @magentoAppIsolation enabled
127
+ *
128
+ * @magentoConfigFixture current_store web/secure/base_url http://sample.com/
129
+ * @magentoConfigFixture current_store web/unsecure/base_link_url http://sample.com/
130
+ * @magentoConfigFixture current_store web/secure/base_link_url https://sample.com/
131
+ * @magentoConfigFixture current_store web/secure/use_in_frontend 1
132
+ *
133
+ * @magentoAppArea frontend
134
+ */
135
+ public function testGetSecureUrlInUnsecureArea ()
136
+ {
137
+ /** @var \Magento\Framework\App\Request\Http $request */
138
+ $ request = Bootstrap::getObjectManager ()->create (\Magento \Framework \App \Request \Http::class);
139
+ //Emulate HTTPS request
140
+ $ request ->getServer ()->set ('HTTPS ' , 'off ' );
141
+ $ request ->getServer ()->set ('SERVER_PORT ' , 80 );
142
+
143
+ $ model = Bootstrap::getObjectManager ()->create (\Magento \Framework \Url::class, ['request ' => $ request ]);
144
+
145
+ $ secureUrl = $ model ->getUrl ('some/index/controller ' , ['_nosid ' => 1 ]);
146
+ $ this ->assertEquals (
147
+ 'http://sample.com/index.php/some/index/controller/ ' ,
148
+ $ secureUrl ,
149
+ 'Default URL in unsecure area is incorrect '
150
+ );
151
+
152
+ $ secureUrl = $ model ->getUrl ('some/index/controller ' , ['_secure ' => true , '_nosid ' => 1 ]);
153
+ $ this ->assertEquals (
154
+ 'https://sample.com/index.php/some/index/controller/ ' ,
155
+ $ secureUrl ,
156
+ 'Secure URL in unsecure area is incorrect '
157
+ );
158
+
159
+ $ unsecureUrl = $ model ->getUrl ('some/index/controller ' , ['_secure ' => false , '_nosid ' => 1 ]);
160
+ $ this ->assertEquals (
161
+ 'http://sample.com/index.php/some/index/controller/ ' ,
162
+ $ unsecureUrl ,
163
+ 'Unsecure URL in unsecure area is incorrect '
164
+ );
165
+ }
166
+
80
167
/**
81
168
* Check that url type is restored to default after call getBaseUrl with type specified in params
82
169
*/
0 commit comments