Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AdminPathConfigTest.php
Go to the documentation of this file.
1 <?php
7 
10 
11 class AdminPathConfigTest extends \PHPUnit\Framework\TestCase
12 {
16  protected $coreConfig;
17 
21  protected $backendConfig;
22 
26  protected $url;
27 
31  protected $adminPathConfig;
32 
33  protected function setUp()
34  {
35  $this->coreConfig = $this->getMockForAbstractClass(
36  \Magento\Framework\App\Config\ScopeConfigInterface::class,
37  [],
38  '',
39  false
40  );
41  $this->backendConfig = $this->getMockForAbstractClass(
42  \Magento\Backend\App\ConfigInterface::class,
43  [],
44  '',
45  false
46  );
47  $this->url = $this->getMockForAbstractClass(
48  \Magento\Framework\UrlInterface::class,
49  [],
50  '',
51  false,
52  true,
53  true,
54  ['getBaseUrl']
55  );
56  $this->adminPathConfig = new AdminPathConfig($this->coreConfig, $this->backendConfig, $this->url);
57  }
58 
59  public function testGetCurrentSecureUrl()
60  {
61  $request = $this->getMockForAbstractClass(
62  \Magento\Framework\App\RequestInterface::class,
63  [],
64  '',
65  false,
66  true,
67  true,
68  ['getPathInfo']
69  );
70  $request->expects($this->once())->method('getPathInfo')->willReturn('/info');
71  $this->url->expects($this->once())->method('getBaseUrl')->with('link', true)->willReturn('localhost/');
72  $this->assertEquals('localhost/info', $this->adminPathConfig->getCurrentSecureUrl($request));
73  }
74 
82  public function testShouldBeSecure($unsecureBaseUrl, $useSecureInAdmin, $secureBaseUrl, $expected)
83  {
84  $coreConfigValueMap = [
85  [\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_URL, 'default', null, $unsecureBaseUrl],
86  [\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_URL, 'default', null, $secureBaseUrl],
87  ];
88  $this->coreConfig->expects($this->any())->method('getValue')->will($this->returnValueMap($coreConfigValueMap));
89  $this->backendConfig->expects($this->any())->method('isSetFlag')->willReturn($useSecureInAdmin);
90  $this->assertEquals($expected, $this->adminPathConfig->shouldBeSecure(''));
91  }
92 
96  public function shouldBeSecureDataProvider()
97  {
98  return [
99  ['http://localhost/', false, 'default', false],
100  ['http://localhost/', true, 'default', false],
101  ['https://localhost/', false, 'default', true],
102  ['https://localhost/', true, 'default', true],
103  ['http://localhost/', false, 'https://localhost/', false],
104  ['http://localhost/', true, 'https://localhost/', true],
105  ['https://localhost/', true, 'https://localhost/', true],
106  ];
107  }
108 
109  public function testGetDefaultPath()
110  {
111  $this->backendConfig->expects($this->once())
112  ->method('getValue')
113  ->with('web/default/admin')
114  ->willReturn('default/path');
115  $this->assertEquals('default/path', $this->adminPathConfig->getDefaultPath());
116  }
117 }
const XML_PATH_UNSECURE_BASE_URL
Definition: Store.php:66
testShouldBeSecure($unsecureBaseUrl, $useSecureInAdmin, $secureBaseUrl, $expected)
const XML_PATH_SECURE_BASE_URL
Definition: Store.php:68