|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2015 Magento. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace Magento\Backend\Test\Unit\Model; |
| 7 | + |
| 8 | +use Magento\Backend\Model\AdminPathConfig; |
| 9 | +use Magento\Store\Model\Store; |
| 10 | + |
| 11 | +class AdminPathConfigTest extends \PHPUnit_Framework_TestCase |
| 12 | +{ |
| 13 | + /** |
| 14 | + * @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject |
| 15 | + */ |
| 16 | + protected $coreConfig; |
| 17 | + |
| 18 | + /** |
| 19 | + * @var \Magento\Backend\App\ConfigInterface|\PHPUnit_Framework_MockObject_MockObject |
| 20 | + */ |
| 21 | + protected $backendConfig; |
| 22 | + |
| 23 | + /** |
| 24 | + * @var \Magento\Framework\UrlInterface|\PHPUnit_Framework_MockObject_MockObject |
| 25 | + */ |
| 26 | + protected $url; |
| 27 | + |
| 28 | + /** |
| 29 | + * @var AdminPathConfig |
| 30 | + */ |
| 31 | + protected $adminPathConfig; |
| 32 | + |
| 33 | + public function setUp() |
| 34 | + { |
| 35 | + $this->coreConfig = $this->getMockForAbstractClass( |
| 36 | + 'Magento\Framework\App\Config\ScopeConfigInterface', |
| 37 | + [], |
| 38 | + '', |
| 39 | + false |
| 40 | + ); |
| 41 | + $this->backendConfig = $this->getMockForAbstractClass('Magento\Backend\App\ConfigInterface', [], '', false); |
| 42 | + $this->url = $this->getMockForAbstractClass( |
| 43 | + 'Magento\Framework\UrlInterface', |
| 44 | + [], |
| 45 | + '', |
| 46 | + false, |
| 47 | + true, |
| 48 | + true, |
| 49 | + ['getBaseUrl'] |
| 50 | + ); |
| 51 | + $this->adminPathConfig = new AdminPathConfig($this->coreConfig, $this->backendConfig, $this->url); |
| 52 | + } |
| 53 | + |
| 54 | + public function testGetCurrentSecureUrl() |
| 55 | + { |
| 56 | + $request = $this->getMockForAbstractClass( |
| 57 | + 'Magento\Framework\App\RequestInterface', |
| 58 | + [], |
| 59 | + '', |
| 60 | + false, |
| 61 | + true, |
| 62 | + true, |
| 63 | + ['getPathInfo'] |
| 64 | + ); |
| 65 | + $request->expects($this->once())->method('getPathInfo')->willReturn('/info'); |
| 66 | + $this->url->expects($this->once())->method('getBaseUrl')->with('link', true)->willReturn('localhost/'); |
| 67 | + $this->assertEquals('localhost/info', $this->adminPathConfig->getCurrentSecureUrl($request)); |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * @param $unsecureBaseUrl |
| 72 | + * @param $useSecureInAdmin |
| 73 | + * @param $secureBaseUrl |
| 74 | + * @param $expected |
| 75 | + * @dataProvider shouldBeSecureDataProvider |
| 76 | + */ |
| 77 | + public function testShouldBeSecure($unsecureBaseUrl, $useSecureInAdmin, $secureBaseUrl, $expected) |
| 78 | + { |
| 79 | + $coreConfigValueMap = [ |
| 80 | + [\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_URL, 'default', null, $unsecureBaseUrl], |
| 81 | + [\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_URL, 'default', null, $secureBaseUrl], |
| 82 | + ]; |
| 83 | + $this->coreConfig->expects($this->any())->method('getValue')->will($this->returnValueMap($coreConfigValueMap)); |
| 84 | + $this->backendConfig->expects($this->any())->method('isSetFlag')->willReturn($useSecureInAdmin); |
| 85 | + $this->assertEquals($expected, $this->adminPathConfig->shouldBeSecure('')); |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * @return array |
| 90 | + */ |
| 91 | + public function shouldBeSecureDataProvider() |
| 92 | + { |
| 93 | + return [ |
| 94 | + ['http://localhost/', false, 'default', false], |
| 95 | + ['http://localhost/', true, 'default', false], |
| 96 | + ['https://localhost/', false, 'default', true], |
| 97 | + ['https://localhost/', true, 'default', true], |
| 98 | + ['http://localhost/', false, 'https://localhost/', false], |
| 99 | + ['http://localhost/', true, 'https://localhost/', true], |
| 100 | + ['https://localhost/', true, 'https://localhost/', true], |
| 101 | + ]; |
| 102 | + } |
| 103 | + |
| 104 | + public function testGetDefaultPath() |
| 105 | + { |
| 106 | + $this->backendConfig->expects($this->once()) |
| 107 | + ->method('getValue') |
| 108 | + ->with('web/default/admin') |
| 109 | + ->willReturn('default/path'); |
| 110 | + $this->assertEquals('default/path', $this->adminPathConfig->getDefaultPath()); |
| 111 | + } |
| 112 | +} |
0 commit comments