|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\Customer\Test\Unit\Model; |
| 9 | + |
| 10 | +use Magento\Customer\Model\Session; |
| 11 | +use Magento\Customer\Model\Url; |
| 12 | +use Magento\Framework\App\Config\ScopeConfigInterface; |
| 13 | +use Magento\Framework\App\RequestInterface; |
| 14 | +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
| 15 | +use Magento\Framework\UrlInterface; |
| 16 | +use PHPUnit\Framework\MockObject\MockObject; |
| 17 | +use PHPUnit\Framework\TestCase; |
| 18 | + |
| 19 | +/** |
| 20 | + * Unit test for \Magento\Customer\Model\Url |
| 21 | + */ |
| 22 | +class UrlTest extends TestCase |
| 23 | +{ |
| 24 | + /** |
| 25 | + * @var ScopeConfigInterface|MockObject |
| 26 | + */ |
| 27 | + protected $scopeConfigMock; |
| 28 | + |
| 29 | + /** |
| 30 | + * @var RequestInterface|MockObject |
| 31 | + */ |
| 32 | + protected $requestMock; |
| 33 | + |
| 34 | + /** |
| 35 | + * @var Session|MockObject |
| 36 | + */ |
| 37 | + protected $customerSessionMock; |
| 38 | + |
| 39 | + /** |
| 40 | + * @var UrlInterface|MockObject |
| 41 | + */ |
| 42 | + protected $urlBuilderMock; |
| 43 | + |
| 44 | + /** |
| 45 | + * @var ObjectManager |
| 46 | + */ |
| 47 | + protected $objectManager; |
| 48 | + |
| 49 | + /** |
| 50 | + * @var Url |
| 51 | + */ |
| 52 | + protected $model; |
| 53 | + |
| 54 | + /** |
| 55 | + * @inheritdoc |
| 56 | + */ |
| 57 | + protected function setUp(): void |
| 58 | + { |
| 59 | + $this->objectManager = new ObjectManager($this); |
| 60 | + |
| 61 | + $this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class) |
| 62 | + ->disableOriginalConstructor() |
| 63 | + ->getMock(); |
| 64 | + $this->requestMock = $this->getMockBuilder(RequestInterface::class) |
| 65 | + ->disableOriginalConstructor() |
| 66 | + ->setMethods(['isGet']) |
| 67 | + ->getMockForAbstractClass(); |
| 68 | + $this->customerSessionMock = $this->getMockBuilder(Session::class) |
| 69 | + ->disableOriginalConstructor() |
| 70 | + ->setMethods(['getNoReferer']) |
| 71 | + ->getMock(); |
| 72 | + $this->urlBuilderMock = $this->getMockBuilder(UrlInterface::class) |
| 73 | + ->disableOriginalConstructor() |
| 74 | + ->getMock(); |
| 75 | + |
| 76 | + $this->model = $this->objectManager->getObject( |
| 77 | + Url::class, |
| 78 | + [ |
| 79 | + 'scopeConfig' => $this->scopeConfigMock, |
| 80 | + 'request' => $this->requestMock, |
| 81 | + 'customerSession' => $this->customerSessionMock, |
| 82 | + 'urlBuilder' => $this->urlBuilderMock |
| 83 | + ] |
| 84 | + ); |
| 85 | + } |
| 86 | + |
| 87 | + /** |
| 88 | + * @return void |
| 89 | + */ |
| 90 | + public function testGetLoginUrlParamsForNoRouteReferrer() |
| 91 | + { |
| 92 | + $this->requestMock->expects($this->any()) |
| 93 | + ->method('getParam') |
| 94 | + ->with(Url::REFERER_QUERY_PARAM_NAME) |
| 95 | + ->willReturn(null); |
| 96 | + $this->scopeConfigMock->expects($this->any()) |
| 97 | + ->method('isSetFlag') |
| 98 | + ->willReturn(false); |
| 99 | + $this->customerSessionMock->expects($this->any()) |
| 100 | + ->method('getNoReferer') |
| 101 | + ->willReturn(false); |
| 102 | + $this->requestMock->expects($this->any()) |
| 103 | + ->method('isGet') |
| 104 | + ->willReturn(true); |
| 105 | + $this->urlBuilderMock->expects($this->any()) |
| 106 | + ->method('getUrl') |
| 107 | + ->willReturn('cms/noroute/index'); |
| 108 | + |
| 109 | + $this->assertEquals([], $this->model->getLoginUrlParams()); |
| 110 | + } |
| 111 | +} |
0 commit comments