Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
UrlTest Class Reference
Inheritance diagram for UrlTest:

Public Member Functions

 testSetGetUseSession ()
 
 testSetRouteFrontName ()
 
 testGetConfigData ()
 
 testGetBaseUrlDefaults ()
 
 testGetBaseUrlSeoRewrites ()
 
 testGetBaseUrlConfigured ($params, $expectedUrl)
 
 testGetBaseUrlWithTypeRestoring ()
 
 getBaseUrlConfiguredDataProvider ()
 
 testSetGetRouteName ()
 
 testSetGetControllerName ()
 
 testSetGetActionName ()
 
 testGetRouteUrl ()
 
 testSetGetFragment ()
 
 testGetUrl ()
 
 testGetUrlDoesntAddQueryParamsOnConsequentCalls ()
 
 testGetUrlDoesntAddFragmentOnConsequentCalls ()
 
 testGetUrlOnConsequentCalls ( $firstCallUrl, $secondCallUrl, $firstRouteParams, $secondRouteParams, $firstExpectedUrl, $secondExpectedUrl)
 
 consequentCallsDataProvider ()
 
 testEscape ()
 
 testGetDirectUrl ()
 
 testSessionUrlVar ()
 
 testUseSessionIdForUrl ()
 

Protected Member Functions

 setUp ()
 

Protected Attributes

 $model
 

Detailed Description

Definition at line 11 of file UrlTest.php.

Member Function Documentation

◆ consequentCallsDataProvider()

consequentCallsDataProvider ( )

Data provider for testGetUrlOnConsequentCalls()

@SuppressWarnings(PHPMD.ExcessiveMethodLength)

Returns
array

Definition at line 327 of file UrlTest.php.

328  {
329  return [
330  [
331  'r_1/c_1/a_1/p_1/v_1',
332  'r_1/c_1/a_1/p_1/v_1',
333  null,
334  null,
335  'http://localhost/index.php/r_1/c_1/a_1/p_1/v_1/',
336  'http://localhost/index.php/r_1/c_1/a_1/p_1/v_1/',
337  ],
338  [
339  'r_1/c_1/a_1/p_1/v_1',
340  'r_1/c_1/a_1/p_1/v_2',
341  null,
342  null,
343  'http://localhost/index.php/r_1/c_1/a_1/p_1/v_1/',
344  'http://localhost/index.php/r_1/c_1/a_1/p_1/v_2/'
345  ],
346  [
347  'r_1/c_1/a_1/p_1/v_1',
348  'r_1/c_1/a_1/p_1',
349  null,
350  null,
351  'http://localhost/index.php/r_1/c_1/a_1/p_1/v_1/',
352  'http://localhost/index.php/r_1/c_1/a_1/'
353  ],
354  [
355  'r_1/c_1/a_1/p_1/v_1',
356  'r_1/c_1/a_1/p_2/v_2',
357  null,
358  null,
359  'http://localhost/index.php/r_1/c_1/a_1/p_1/v_1/',
360  'http://localhost/index.php/r_1/c_1/a_1/p_2/v_2/'
361  ],
362  [
363  'r_1/c_1/a_1/p_1/v_1',
364  'r_1/c_1/a_1',
365  null,
366  null,
367  'http://localhost/index.php/r_1/c_1/a_1/p_1/v_1/',
368  'http://localhost/index.php/r_1/c_1/a_1/'
369  ],
370  [
371  'r_1/c_1/a_1/p_1/v_1',
372  'r_1/c_1/a_2',
373  null,
374  null,
375  'http://localhost/index.php/r_1/c_1/a_1/p_1/v_1/',
376  'http://localhost/index.php/r_1/c_1/a_2/'
377  ],
378  [
379  'r_1/c_1/a_1/p_1/v_1',
380  'r_1/c_1',
381  null,
382  null,
383  'http://localhost/index.php/r_1/c_1/a_1/p_1/v_1/',
384  'http://localhost/index.php/r_1/c_1/'
385  ],
386  [
387  'r_1/c_1/a_1/p_1/v_1',
388  'r_1/c_2',
389  null,
390  null,
391  'http://localhost/index.php/r_1/c_1/a_1/p_1/v_1/',
392  'http://localhost/index.php/r_1/c_2/'
393  ],
394  [
395  'r_1/c_1/a_1/p_1/v_1',
396  'r_1',
397  null,
398  null,
399  'http://localhost/index.php/r_1/c_1/a_1/p_1/v_1/',
400  'http://localhost/index.php/r_1/'
401  ],
402  [
403  'r_1/c_1/a_1/p_1/v_1',
404  'r_2',
405  null,
406  null,
407  'http://localhost/index.php/r_1/c_1/a_1/p_1/v_1/',
408  'http://localhost/index.php/r_2/'
409  ],
410  [
411  'r_1/c_1/a_1/p_1/v_1',
412  null,
413  null,
414  null,
415  'http://localhost/index.php/r_1/c_1/a_1/p_1/v_1/',
416  'http://localhost/index.php/'
417  ],
418  [
419  'r_1/c_1/a_1',
420  'r_1/c_1/a_1/p_1/v_1',
421  null,
422  null,
423  'http://localhost/index.php/r_1/c_1/a_1/',
424  'http://localhost/index.php/r_1/c_1/a_1/p_1/v_1/'
425  ],
426  [
427  null,
428  'r_1/c_1/a_1',
429  null,
430  null,
431  'http://localhost/index.php/',
432  'http://localhost/index.php/r_1/c_1/a_1/'
433  ],
434  [
435  'r_1/c_1/a_1/p_1/v_1',
436  'r_1/c_1/a_1/p_1/v_1',
437  ['p_2' => 'v_2'],
438  ['p_2' => 'v_2'],
439  'http://localhost/index.php/r_1/c_1/a_1/p_1/v_1/p_2/v_2/',
440  'http://localhost/index.php/r_1/c_1/a_1/p_1/v_1/p_2/v_2/'
441  ],
442  [
443  'r_1/c_1/a_1/p_1/v_1',
444  'r_1/c_1/a_1',
445  ['p_2' => 'v_2'],
446  ['p_2' => 'v_2'],
447  'http://localhost/index.php/r_1/c_1/a_1/p_1/v_1/p_2/v_2/',
448  'http://localhost/index.php/r_1/c_1/a_1/p_2/v_2/'
449  ],
450  [
451  'r_1/c_1/a_1/p_1/v_1',
452  null,
453  ['p_2' => 'v_2'],
454  ['p_1' => 'v_1', 'p_2' => 'v_2'],
455  'http://localhost/index.php/r_1/c_1/a_1/p_1/v_1/p_2/v_2/',
456  'http://localhost/index.php/p_1/v_1/p_2/v_2/'
457  ]
458  ];
459  }

◆ getBaseUrlConfiguredDataProvider()

getBaseUrlConfiguredDataProvider ( )

Definition at line 192 of file UrlTest.php.

193  {
194  return [
195  [['_type' => \Magento\Framework\UrlInterface::URL_TYPE_WEB], 'http://sample.com/base_path/'],
196  [
198  'http://sample.com/base_link_path/index.php/'
199  ],
200  [
201  ['_type' => \Magento\Framework\UrlInterface::URL_TYPE_LINK, '_secure' => 1],
202  'https://sample.com/base_link_path/index.php/'
203  ]
204  ];
205  }

◆ setUp()

setUp ( )
protected

Definition at line 18 of file UrlTest.php.

19  {
20  $this->model = Bootstrap::getObjectManager()->create(\Magento\Framework\Url::class);
21  }

◆ testEscape()

testEscape ( )

Definition at line 461 of file UrlTest.php.

462  {
463  $this->assertEquals('%22%27%3E%3C', $this->model->escape('"\'><'));
464  }

◆ testGetBaseUrlConfigured()

testGetBaseUrlConfigured (   $params,
  $expectedUrl 
)

Note: isolation flushes the URL memory cache @magentoAppIsolation enabled

@dataProvider getBaseUrlConfiguredDataProvider

@magentoConfigFixture current_store web/secure/base_url http://sample.com/base_path/ @magentoConfigFixture current_store web/unsecure/base_link_url http://sample.com/base_link_path/ @magentoConfigFixture current_store web/secure/base_link_url https://sample.com/base_link_path/ @magentoConfigFixture current_store web/secure/use_in_frontend 1

Parameters
array$params
string$expectedUrl

Definition at line 75 of file UrlTest.php.

76  {
77  $actualUrl = $this->model->getBaseUrl($params);
78  $this->assertEquals($expectedUrl, $actualUrl);
79  }
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ testGetBaseUrlDefaults()

testGetBaseUrlDefaults ( )

Note: isolation should be raised to flush the URL memory cache maintained by the store model @magentoAppIsolation enabled

Definition at line 46 of file UrlTest.php.

47  {
48  $this->assertEquals('http://localhost/index.php/', $this->model->getBaseUrl());
49  }

◆ testGetBaseUrlSeoRewrites()

testGetBaseUrlSeoRewrites ( )

Note: isolation flushes the URL memory cache @magentoAppIsolation enabled @magentoConfigFixture current_store web/seo/use_rewrites 1

Definition at line 56 of file UrlTest.php.

57  {
58  $this->assertEquals('http://localhost/', $this->model->getBaseUrl());
59  }

◆ testGetBaseUrlWithTypeRestoring()

testGetBaseUrlWithTypeRestoring ( )

Check that url type is restored to default after call getBaseUrl with type specified in params

Get base URL with default type

Set specified type

Get url with type specified in params

Definition at line 170 of file UrlTest.php.

171  {
175  $this->assertEquals('http://localhost/index.php/', $this->model->getBaseUrl(), 'Incorrect link url');
176 
180  $webUrl = $this->model->getBaseUrl(['_type' => \Magento\Framework\UrlInterface::URL_TYPE_WEB]);
181  $this->assertEquals('http://localhost/', $webUrl, 'Incorrect web url');
182  $this->assertEquals('http://localhost/index.php/', $this->model->getBaseUrl(), 'Incorrect link url');
183 
187  $mediaUrl = $this->model->getBaseUrl(['_type' => \Magento\Framework\UrlInterface::URL_TYPE_MEDIA]);
188  $this->assertEquals('http://localhost/pub/media/', $mediaUrl, 'Incorrect media url');
189  $this->assertEquals('http://localhost/index.php/', $this->model->getBaseUrl(), 'Incorrect link url');
190  }

◆ testGetConfigData()

testGetConfigData ( )

Definition at line 37 of file UrlTest.php.

38  {
39  $this->assertEquals('http://localhost/', $this->model->getConfigData('base_url'));
40  }

◆ testGetDirectUrl()

testGetDirectUrl ( )

Note: isolation flushes the URL memory cache @magentoAppIsolation enabled

Definition at line 470 of file UrlTest.php.

471  {
472  $directUrl = $this->model->getDirectUrl('fancy_uri', ['_query' => ['foo' => 'bar']]);
473  $this->assertEquals('http://localhost/index.php/fancy_uri?foo=bar', $directUrl);
474  }

◆ testGetRouteUrl()

testGetRouteUrl ( )

Note: isolation flushes the URL memory cache @magentoAppIsolation enabled

Definition at line 235 of file UrlTest.php.

236  {
237  $this->assertEquals('http://localhost/index.php/', $this->model->getRouteUrl());
238  $this->assertEquals(
239  'http://localhost/index.php/catalog/product/view/id/50/',
240  $this->model->getRouteUrl('catalog/product/view', ['id' => 50])
241  );
242  $this->assertEquals(
243  'http://localhost/index.php/fancy_uri',
244  $this->model->getRouteUrl('core/index/index', ['_direct' => 'fancy_uri'])
245  );
246  }

◆ testGetUrl()

testGetUrl ( )

Note: isolation flushes the URL memory cache @magentoAppIsolation enabled

Definition at line 258 of file UrlTest.php.

259  {
260  $result = $this->model->getUrl(
261  'catalog/product/view',
262  ['_fragment' => 'anchor', '_escape' => 1, '_query' => 'foo=bar', '_nosid' => 1, 'id' => 100]
263  );
264  $this->assertEquals('http://localhost/index.php/catalog/product/view/id/100/?foo=bar#anchor', $result);
265  }

◆ testGetUrlDoesntAddFragmentOnConsequentCalls()

testGetUrlDoesntAddFragmentOnConsequentCalls ( )

Note: isolation flushes the URL memory cache @magentoAppIsolation enabled @covers \Magento\Framework\Url::getUrl

Definition at line 284 of file UrlTest.php.

285  {
286  $result = $this->model->getUrl('catalog/product/view', ['_nosid' => 1, '_fragment' => 'section']);
287  $this->assertEquals('http://localhost/index.php/catalog/product/view/#section', $result);
288  $result = $this->model->getUrl('catalog/product/view', ['_nosid' => 1]);
289  $this->assertEquals('http://localhost/index.php/catalog/product/view/', $result);
290  }

◆ testGetUrlDoesntAddQueryParamsOnConsequentCalls()

testGetUrlDoesntAddQueryParamsOnConsequentCalls ( )

Note: isolation flushes the URL memory cache @magentoAppIsolation enabled

Definition at line 271 of file UrlTest.php.

272  {
273  $result = $this->model->getUrl('catalog/product/view', ['_query' => 'foo=bar', '_nosid' => 1]);
274  $this->assertEquals('http://localhost/index.php/catalog/product/view/?foo=bar', $result);
275  $result = $this->model->getUrl('catalog/product/view', ['_nosid' => 1]);
276  $this->assertEquals('http://localhost/index.php/catalog/product/view/', $result);
277  }

◆ testGetUrlOnConsequentCalls()

testGetUrlOnConsequentCalls (   $firstCallUrl,
  $secondCallUrl,
  $firstRouteParams,
  $secondRouteParams,
  $firstExpectedUrl,
  $secondExpectedUrl 
)

Note: isolation flushes the URL memory cache @magentoAppIsolation enabled

@dataProvider consequentCallsDataProvider

Parameters
string$firstCallUrl
string$secondCallUrl
array$firstRouteParams
array$secondRouteParams
string$firstExpectedUrl
string$secondExpectedUrl@covers \Magento\Framework\Url::getUrl

Definition at line 306 of file UrlTest.php.

313  {
314  $result = $this->model->getUrl($firstCallUrl, $firstRouteParams);
315  $this->assertEquals($firstExpectedUrl, $result);
316 
317  $result = $this->model->getUrl($secondCallUrl, $secondRouteParams);
318  $this->assertEquals($secondExpectedUrl, $result);
319  }

◆ testSessionUrlVar()

testSessionUrlVar ( )

Note: isolation flushes the URL memory cache @magentoAppIsolation enabled

Note: to enforce SID in URLs, base URL must be different from the current $_SERVER['HTTP_HOST'] @magentoConfigFixture current_store web/unsecure/base_link_url http://domain.com/

Definition at line 483 of file UrlTest.php.

484  {
486  \Magento\Framework\Session\Generic::class
487  )->getSessionId();
488  $sessionUrl = $this->model->sessionUrlVar('<a href="http://example.com/?___SID=U">www.example.com</a>');
489  $this->assertEquals('<a href="http://example.com/?SID=' . $sessionId . '">www.example.com</a>', $sessionUrl);
490  }

◆ testSetGetActionName()

testSetGetActionName ( )

Definition at line 223 of file UrlTest.php.

224  {
225  $this->model->setActionName('view');
226  $this->assertEquals('view', $this->model->getActionName());
227 
228  $this->markTestIncomplete('setActionName() logic is unclear.');
229  }

◆ testSetGetControllerName()

testSetGetControllerName ( )

Definition at line 215 of file UrlTest.php.

216  {
217  $this->model->setControllerName('product');
218  $this->assertEquals('product', $this->model->getControllerName());
219 
220  $this->markTestIncomplete('setControllerName() logic is unclear.');
221  }

◆ testSetGetFragment()

testSetGetFragment ( )

Definition at line 248 of file UrlTest.php.

249  {
250  $this->model->setFragment('value');
251  $this->assertEquals('value', $this->model->getFragment());
252  }

◆ testSetGetRouteName()

testSetGetRouteName ( )

Definition at line 207 of file UrlTest.php.

208  {
209  $this->model->setRouteName('catalog');
210  $this->assertEquals('catalog', $this->model->getRouteName());
211 
212  $this->markTestIncomplete('setRouteName() logic is unclear.');
213  }

◆ testSetGetUseSession()

testSetGetUseSession ( )

Definition at line 23 of file UrlTest.php.

24  {
25  $this->assertTrue((bool)$this->model->getUseSession());
26  $this->model->setUseSession(false);
27  $this->assertFalse($this->model->getUseSession());
28  }

◆ testSetRouteFrontName()

testSetRouteFrontName ( )

Definition at line 30 of file UrlTest.php.

31  {
32  $value = 'route';
33  $this->model->setRouteFrontName($value);
34  $this->assertEquals($value, $this->model->getData('route_front_name'));
35  }
$value
Definition: gender.phtml:16

◆ testUseSessionIdForUrl()

testUseSessionIdForUrl ( )

Definition at line 492 of file UrlTest.php.

493  {
494  $_SERVER['HTTP_HOST'] = 'localhost';
495  $this->assertFalse($this->model->useSessionIdForUrl(true));
496  $this->assertFalse($this->model->useSessionIdForUrl(false));
497  }

Field Documentation

◆ $model

$model
protected

Definition at line 16 of file UrlTest.php.


The documentation for this class was generated from the following file: