UrlRewriteTest.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\UrlRewrite\Test\Unit\Helper;
  7. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
  8. class UrlRewriteTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * @var \Magento\UrlRewrite\Helper\UrlRewrite
  12. */
  13. protected $_helper;
  14. protected function setUp()
  15. {
  16. $this->_helper = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))->getObject(
  17. \Magento\UrlRewrite\Helper\UrlRewrite::class
  18. );
  19. }
  20. /**
  21. * @dataProvider requestPathDataProvider
  22. */
  23. public function testValidateRequestPath($requestPath)
  24. {
  25. $this->assertTrue($this->_helper->validateRequestPath($requestPath));
  26. }
  27. /**
  28. * @dataProvider requestPathExceptionDataProvider
  29. * @expectedException \Magento\Framework\Exception\LocalizedException
  30. */
  31. public function testValidateRequestPathException($requestPath)
  32. {
  33. $this->_helper->validateRequestPath($requestPath);
  34. }
  35. /**
  36. * @dataProvider requestPathDataProvider
  37. */
  38. public function testValidateSuffix($suffix)
  39. {
  40. $this->assertTrue($this->_helper->validateSuffix($suffix));
  41. }
  42. /**
  43. * @dataProvider requestPathExceptionDataProvider
  44. * @expectedException \Magento\Framework\Exception\LocalizedException
  45. */
  46. public function testValidateSuffixException($suffix)
  47. {
  48. $this->_helper->validateSuffix($suffix);
  49. }
  50. /**
  51. * @return array
  52. */
  53. public function requestPathDataProvider()
  54. {
  55. return [
  56. 'no leading slash' => ['correct/request/path'],
  57. 'leading slash' => ['another/good/request/path/']
  58. ];
  59. }
  60. /**
  61. * @return array
  62. */
  63. public function requestPathExceptionDataProvider()
  64. {
  65. return [
  66. 'two slashes' => ['request/path/with/two//slashes'],
  67. 'three slashes' => ['request/path/with/three///slashes'],
  68. 'anchor' => ['request/path/with#anchor']
  69. ];
  70. }
  71. }