|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2015 Magento. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +namespace Magento\UrlRewrite\Test\Unit\Block\Plugin\Store\Switcher; |
| 8 | + |
| 9 | +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
| 10 | + |
| 11 | +class SetRedirectUrlTest extends \PHPUnit_Framework_TestCase |
| 12 | +{ |
| 13 | + /** @var \Magento\UrlRewrite\Block\Plugin\Store\Switcher\SetRedirectUrl */ |
| 14 | + protected $unit; |
| 15 | + |
| 16 | + /** @var \PHPUnit_Framework_MockObject_MockObject */ |
| 17 | + protected $urlFinder; |
| 18 | + |
| 19 | + /** @var \PHPUnit_Framework_MockObject_MockObject */ |
| 20 | + protected $urlHelper; |
| 21 | + |
| 22 | + /** @var \Magento\Store\Block\Switcher|\PHPUnit_Framework_MockObject_MockObject */ |
| 23 | + protected $switcher; |
| 24 | + |
| 25 | + /** @var \Magento\Store\Model\Store|\PHPUnit_Framework_MockObject_MockObject */ |
| 26 | + protected $store; |
| 27 | + |
| 28 | + /** @var \PHPUnit_Framework_MockObject_MockObject */ |
| 29 | + protected $request; |
| 30 | + |
| 31 | + /** @var \Magento\Framework\UrlInterface|\PHPUnit_Framework_MockObject_MockObject */ |
| 32 | + protected $urlBuilder; |
| 33 | + |
| 34 | + protected function setUp() |
| 35 | + { |
| 36 | + $this->store = $this->getMock('Magento\Store\Model\Store', [], [], '', false); |
| 37 | + $this->request = $this->getMock('Magento\Framework\App\Request\Http', [], [], '', false); |
| 38 | + $this->urlBuilder = $this->getMock('Magento\Framework\UrlInterface'); |
| 39 | + $this->urlHelper = $this->getMock('Magento\Framework\Url\Helper\Data', [], [], '', false); |
| 40 | + $this->urlFinder = $this->getMock('Magento\UrlRewrite\Model\UrlFinderInterface', [], [], '', false); |
| 41 | + $this->switcher = $this->getMock('Magento\Store\Block\Switcher', [], [], '', false); |
| 42 | + |
| 43 | + $this->unit = (new ObjectManager($this))->getObject( |
| 44 | + 'Magento\UrlRewrite\Block\Plugin\Store\Switcher\SetRedirectUrl', |
| 45 | + [ |
| 46 | + 'urlFinder' => $this->urlFinder, |
| 47 | + 'urlHelper' => $this->urlHelper, |
| 48 | + 'urlBuilder' => $this->urlBuilder, |
| 49 | + 'request' => $this->request, |
| 50 | + ] |
| 51 | + ); |
| 52 | + } |
| 53 | + |
| 54 | + public function testNoUrlRewriteForSpecificStoreOnGetTargetStorePostData() |
| 55 | + { |
| 56 | + $this->request->expects($this->once())->method('getPathInfo')->willReturn('path'); |
| 57 | + $this->urlFinder->expects($this->once())->method('findOneByData')->willReturn(null); |
| 58 | + $this->urlHelper->expects($this->never())->method('getEncodedUrl'); |
| 59 | + $this->assertEquals( |
| 60 | + [$this->store, []], |
| 61 | + $this->unit->beforeGetTargetStorePostData($this->switcher, $this->store, []) |
| 62 | + ); |
| 63 | + } |
| 64 | + |
| 65 | + public function testTrimPathInfoForGetTargetStorePostData() |
| 66 | + { |
| 67 | + $this->request->expects($this->once())->method('getPathInfo')->willReturn('path/with/trim/'); |
| 68 | + $this->store->expects($this->once())->method('getId')->willReturn(1); |
| 69 | + $this->urlFinder->expects($this->once())->method('findOneByData') |
| 70 | + ->with([ |
| 71 | + \Magento\UrlRewrite\Service\V1\Data\UrlRewrite::TARGET_PATH => 'path/with/trim', |
| 72 | + \Magento\UrlRewrite\Service\V1\Data\UrlRewrite::STORE_ID => 1, |
| 73 | + ]) |
| 74 | + ->willReturn(null); |
| 75 | + $this->urlHelper->expects($this->never())->method('getEncodedUrl'); |
| 76 | + $this->assertEquals( |
| 77 | + [$this->store, []], |
| 78 | + $this->unit->beforeGetTargetStorePostData($this->switcher, $this->store, []) |
| 79 | + ); |
| 80 | + } |
| 81 | + |
| 82 | + public function testGetTargetStorePostData() |
| 83 | + { |
| 84 | + $urlRewrite = $this->getMock('Magento\UrlRewrite\Service\V1\Data\UrlRewrite'); |
| 85 | + $urlRewrite->expects($this->once())->method('getRequestPath')->willReturn('path'); |
| 86 | + |
| 87 | + $this->request->expects($this->once())->method('getPathInfo')->willReturn('path'); |
| 88 | + $this->urlFinder->expects($this->once())->method('findOneByData')->willReturn($urlRewrite); |
| 89 | + $this->urlHelper->expects($this->once())->method('getEncodedUrl')->willReturn('encoded-path'); |
| 90 | + $this->urlBuilder->expects($this->once())->method('getUrl')->willReturn('path'); |
| 91 | + $this->assertEquals( |
| 92 | + [$this->store, [\Magento\Framework\App\ActionInterface::PARAM_NAME_URL_ENCODED => 'encoded-path']], |
| 93 | + $this->unit->beforeGetTargetStorePostData($this->switcher, $this->store, []) |
| 94 | + ); |
| 95 | + } |
| 96 | +} |
0 commit comments