|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2015 Magento. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace Magento\Store\App\Request; |
| 7 | + |
| 8 | +use \Magento\TestFramework\Helper\Bootstrap; |
| 9 | +use \Magento\Store\Model\ScopeInterface; |
| 10 | +use \Magento\Store\Model\Store; |
| 11 | + |
| 12 | +class PathInfoProcessorTest extends \PHPUnit_Framework_TestCase |
| 13 | +{ |
| 14 | + /** |
| 15 | + * @var \Magento\Store\App\Request\PathInfoProcessor |
| 16 | + */ |
| 17 | + protected $pathProcessor; |
| 18 | + |
| 19 | + protected function setUp() |
| 20 | + { |
| 21 | + $this->pathProcessor = Bootstrap::getObjectManager()->create('Magento\Store\App\Request\PathInfoProcessor'); |
| 22 | + } |
| 23 | + |
| 24 | + /** |
| 25 | + * @covers \Magento\Store\App\Request\PathInfoProcessor::process |
| 26 | + * @dataProvider notValidStoreCodeDataProvider |
| 27 | + */ |
| 28 | + public function testProcessNotValidStoreCode($pathInfo) |
| 29 | + { |
| 30 | + /** @var \Magento\Framework\App\RequestInterface $request */ |
| 31 | + $request = Bootstrap::getObjectManager()->create('Magento\Framework\App\RequestInterface'); |
| 32 | + $this->assertEquals($pathInfo, $this->pathProcessor->process($request, $pathInfo)); |
| 33 | + } |
| 34 | + |
| 35 | + public function notValidStoreCodeDataProvider() |
| 36 | + { |
| 37 | + return [ |
| 38 | + ['not_valid_store_code_int' => '/100500/m/c/a'], |
| 39 | + ['not_valid_store_code_str' => '/test_string/m/c/a'], |
| 40 | + ]; |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * @covers \Magento\Store\App\Request\PathInfoProcessor::process |
| 45 | + * @magentoDataFixture Magento/Store/_files/core_fixturestore.php |
| 46 | + */ |
| 47 | + public function testProcessValidStoreCodeCase1() |
| 48 | + { |
| 49 | + /** @var \Magento\Store\Model\Store $store */ |
| 50 | + $store = Bootstrap::getObjectManager()->get('Magento\Store\Model\Store'); |
| 51 | + $store->load('fixturestore', 'code'); |
| 52 | + |
| 53 | + /** @var \Magento\Framework\App\RequestInterface $request */ |
| 54 | + $request = Bootstrap::getObjectManager()->create('Magento\Framework\App\RequestInterface'); |
| 55 | + |
| 56 | + /** @var \Magento\Framework\App\Config\ReinitableConfigInterface $config */ |
| 57 | + $config = Bootstrap::getObjectManager()->get('\Magento\Framework\App\Config\ReinitableConfigInterface'); |
| 58 | + $config->setValue(Store::XML_PATH_STORE_IN_URL, false, ScopeInterface::SCOPE_STORE, $store->getCode()); |
| 59 | + $pathInfo = sprintf('/%s/m/c/a', $store->getCode()); |
| 60 | + $this->assertEquals($pathInfo, $this->pathProcessor->process($request, $pathInfo)); |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * @covers \Magento\Store\App\Request\PathInfoProcessor::process |
| 65 | + * @magentoDataFixture Magento/Store/_files/core_fixturestore.php |
| 66 | + */ |
| 67 | + public function testProcessValidStoreCodeCase2() |
| 68 | + { |
| 69 | + /** @var \Magento\Store\Model\Store $store */ |
| 70 | + $store = Bootstrap::getObjectManager()->get('Magento\Store\Model\Store'); |
| 71 | + $store->load('fixturestore', 'code'); |
| 72 | + |
| 73 | + /** @var \Magento\Framework\App\RequestInterface $request */ |
| 74 | + $request = Bootstrap::getObjectManager()->create('Magento\Framework\App\RequestInterface'); |
| 75 | + |
| 76 | + /** @var \Magento\Framework\App\Config\ReinitableConfigInterface $config */ |
| 77 | + $config = Bootstrap::getObjectManager()->get('\Magento\Framework\App\Config\ReinitableConfigInterface'); |
| 78 | + $config->setValue(Store::XML_PATH_STORE_IN_URL, true, ScopeInterface::SCOPE_STORE, $store->getCode()); |
| 79 | + $pathInfo = sprintf('/%s/m/c/a', $store->getCode()); |
| 80 | + $this->assertEquals('/m/c/a', $this->pathProcessor->process($request, $pathInfo)); |
| 81 | + } |
| 82 | + |
| 83 | + /** |
| 84 | + * @covers \Magento\Store\App\Request\PathInfoProcessor::process |
| 85 | + * @magentoDataFixture Magento/Store/_files/core_fixturestore.php |
| 86 | + */ |
| 87 | + public function testProcessValidStoreCodeCase3() |
| 88 | + { |
| 89 | + /** @var \Magento\Store\Model\Store $store */ |
| 90 | + $store = Bootstrap::getObjectManager()->get('Magento\Store\Model\Store'); |
| 91 | + $store->load('fixturestore', 'code'); |
| 92 | + |
| 93 | + /** @var \Magento\Framework\App\RequestInterface $request */ |
| 94 | + $request = Bootstrap::getObjectManager()->create( |
| 95 | + 'Magento\Framework\App\RequestInterface', |
| 96 | + ['directFrontNames' => [$store->getCode() => true]] |
| 97 | + ); |
| 98 | + |
| 99 | + /** @var \Magento\Framework\App\Config\ReinitableConfigInterface $config */ |
| 100 | + $config = Bootstrap::getObjectManager()->get('\Magento\Framework\App\Config\ReinitableConfigInterface'); |
| 101 | + $config->setValue(Store::XML_PATH_STORE_IN_URL, true, ScopeInterface::SCOPE_STORE, $store->getCode()); |
| 102 | + $pathInfo = sprintf('/%s/m/c/a', $store->getCode()); |
| 103 | + $this->assertEquals($pathInfo, $this->pathProcessor->process($request, $pathInfo)); |
| 104 | + $this->assertEquals('noroute', $request->getActionName()); |
| 105 | + } |
| 106 | +} |
0 commit comments