|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2016 Magento. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace Magento\Customer\Test\Unit\Block\Account; |
| 7 | + |
| 8 | +use Magento\Customer\Block\Account\AuthenticationPopup; |
| 9 | +use Magento\Customer\Model\Form; |
| 10 | +use Magento\Framework\App\Config\ScopeConfigInterface; |
| 11 | +use Magento\Framework\UrlInterface; |
| 12 | +use Magento\Framework\View\Element\Template\Context; |
| 13 | +use Magento\Store\Api\Data\StoreInterface; |
| 14 | +use Magento\Store\Model\ScopeInterface; |
| 15 | +use Magento\Store\Model\StoreManagerInterface; |
| 16 | + |
| 17 | +class AuthenticationPopupTest extends \PHPUnit_Framework_TestCase |
| 18 | +{ |
| 19 | + /** @var AuthenticationPopup */ |
| 20 | + private $model; |
| 21 | + |
| 22 | + /** @var Context|\PHPUnit_Framework_MockObject_MockObject */ |
| 23 | + private $contextMock; |
| 24 | + |
| 25 | + /** @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject */ |
| 26 | + private $storeManagerMock; |
| 27 | + |
| 28 | + /** @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject */ |
| 29 | + private $scopeConfigMock; |
| 30 | + |
| 31 | + /** @var UrlInterface|\PHPUnit_Framework_MockObject_MockObject */ |
| 32 | + private $urlBuilderMock; |
| 33 | + |
| 34 | + protected function setUp() |
| 35 | + { |
| 36 | + $this->contextMock = $this->getMockBuilder(Context::class) |
| 37 | + ->disableOriginalConstructor() |
| 38 | + ->getMock(); |
| 39 | + |
| 40 | + $this->storeManagerMock = $this->getMockBuilder(StoreManagerInterface::class) |
| 41 | + ->getMock(); |
| 42 | + $this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class) |
| 43 | + ->getMock(); |
| 44 | + $this->urlBuilderMock = $this->getMockBuilder(UrlInterface::class) |
| 45 | + ->getMock(); |
| 46 | + |
| 47 | + $this->contextMock->expects($this->once()) |
| 48 | + ->method('getStoreManager') |
| 49 | + ->willReturn($this->storeManagerMock); |
| 50 | + $this->contextMock->expects($this->once()) |
| 51 | + ->method('getScopeConfig') |
| 52 | + ->willReturn($this->scopeConfigMock); |
| 53 | + $this->contextMock->expects($this->once()) |
| 54 | + ->method('getUrlBuilder') |
| 55 | + ->willReturn($this->urlBuilderMock); |
| 56 | + |
| 57 | + $this->model = new AuthenticationPopup( |
| 58 | + $this->contextMock |
| 59 | + ); |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * @param mixed $isAutocomplete |
| 64 | + * @param string $baseUrl |
| 65 | + * @param string $registerUrl |
| 66 | + * @param string $forgotUrl |
| 67 | + * @param array $result |
| 68 | + * |
| 69 | + * @dataProvider dataProviderGetConfig |
| 70 | + */ |
| 71 | + public function testGetConfig($isAutocomplete, $baseUrl, $registerUrl, $forgotUrl, array $result) |
| 72 | + { |
| 73 | + $this->scopeConfigMock->expects($this->any()) |
| 74 | + ->method('getValue') |
| 75 | + ->with(Form::XML_PATH_ENABLE_AUTOCOMPLETE, ScopeInterface::SCOPE_STORE, null) |
| 76 | + ->willReturn($isAutocomplete); |
| 77 | + |
| 78 | + /** @var StoreInterface||\PHPUnit_Framework_MockObject_MockObject $storeMock */ |
| 79 | + $storeMock = $this->getMockBuilder(StoreInterface::class) |
| 80 | + ->setMethods(['getBaseUrl']) |
| 81 | + ->getMockForAbstractClass(); |
| 82 | + |
| 83 | + $this->storeManagerMock->expects($this->any()) |
| 84 | + ->method('getStore') |
| 85 | + ->with(null) |
| 86 | + ->willReturn($storeMock); |
| 87 | + |
| 88 | + $storeMock->expects($this->any()) |
| 89 | + ->method('getBaseUrl') |
| 90 | + ->willReturn($baseUrl); |
| 91 | + |
| 92 | + $this->urlBuilderMock->expects($this->any()) |
| 93 | + ->method('getUrl') |
| 94 | + ->willReturnMap( |
| 95 | + [ |
| 96 | + ['customer/account/create', [], $registerUrl], |
| 97 | + ['customer/account/forgotpassword', [], $forgotUrl], |
| 98 | + ] |
| 99 | + ); |
| 100 | + |
| 101 | + $this->assertEquals($result, $this->model->getConfig()); |
| 102 | + } |
| 103 | + |
| 104 | + public function dataProviderGetConfig() |
| 105 | + { |
| 106 | + return [ |
| 107 | + [ |
| 108 | + 0, |
| 109 | + 'base', |
| 110 | + 'reg', |
| 111 | + 'forgot', |
| 112 | + [ |
| 113 | + 'autocomplete' => 'off', |
| 114 | + 'customerRegisterUrl' => 'reg', |
| 115 | + 'customerForgotPasswordUrl' => 'forgot', |
| 116 | + 'baseUrl' => 'base', |
| 117 | + ], |
| 118 | + ], |
| 119 | + [ |
| 120 | + 1, |
| 121 | + '', |
| 122 | + 'reg', |
| 123 | + 'forgot', |
| 124 | + [ |
| 125 | + 'autocomplete' => 'on', |
| 126 | + 'customerRegisterUrl' => 'reg', |
| 127 | + 'customerForgotPasswordUrl' => 'forgot', |
| 128 | + 'baseUrl' => '', |
| 129 | + ], |
| 130 | + ], |
| 131 | + [ |
| 132 | + '', |
| 133 | + 'base', |
| 134 | + '', |
| 135 | + 'forgot', |
| 136 | + [ |
| 137 | + 'autocomplete' => 'off', |
| 138 | + 'customerRegisterUrl' => '', |
| 139 | + 'customerForgotPasswordUrl' => 'forgot', |
| 140 | + 'baseUrl' => 'base', |
| 141 | + ], |
| 142 | + ], |
| 143 | + [ |
| 144 | + true, |
| 145 | + 'base', |
| 146 | + 'reg', |
| 147 | + '', |
| 148 | + [ |
| 149 | + 'autocomplete' => 'on', |
| 150 | + 'customerRegisterUrl' => 'reg', |
| 151 | + 'customerForgotPasswordUrl' => '', |
| 152 | + 'baseUrl' => 'base', |
| 153 | + ], |
| 154 | + ], |
| 155 | + ]; |
| 156 | + } |
| 157 | +} |
0 commit comments