Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PathConfigTest.php
Go to the documentation of this file.
1 <?php
8 
13 
14 class PathConfigTest extends \PHPUnit\Framework\TestCase
15 {
17  private $scopeConfigMock;
19  private $urlSecurityInfoMock;
21  private $storeManagerMock;
23  private $storeMock;
25  protected $model;
26 
27  protected function setUp()
28  {
29  $this->scopeConfigMock = $this->getMockBuilder(\Magento\Framework\App\Config\ScopeConfigInterface::class)
30  ->disableOriginalConstructor()
31  ->getMock();
32  $this->urlSecurityInfoMock = $this->getMockBuilder(\Magento\Framework\Url\SecurityInfoInterface::class)
33  ->disableOriginalConstructor()
34  ->getMock();
35  $this->storeManagerMock = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)
36  ->disableOriginalConstructor()
37  ->getMock();
38  $this->storeMock = $this->getMockBuilder(\Magento\Store\Model\Store::class)
39  ->disableOriginalConstructor()
40  ->getMock();
41  $mockArgs = [
42  'scopeConfig' => $this->scopeConfigMock,
43  'urlSecurityInfo' => $this->urlSecurityInfoMock,
44  'storeManager' => $this->storeManagerMock,
45  ];
46  $this->model = (new ObjectManager($this))->getObject(\Magento\Store\Model\PathConfig::class, $mockArgs);
47  }
48 
50  {
51  $baseUrl = 'base-store.url/';
52  $pathInfo = 'path/to/action';
53 
54  $this->storeMock->expects($this->once())->method('getBaseUrl')->with('link', true)->willReturn($baseUrl);
55  $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($this->storeMock);
56 
57  $request = $this->getMockBuilder(\Magento\Framework\App\Request\Http::class)
58  ->disableOriginalConstructor()
59  ->getMock();
60 
61  $request->expects($this->once())->method('getAlias')->willReturn(null);
62  $request->expects($this->once())->method('getPathInfo')->willReturn($pathInfo);
63  $this->assertSame($baseUrl . $pathInfo, $this->model->getCurrentSecureUrl($request));
64  }
65 
67  {
68  $baseUrl = 'base-store.url/';
69  $alias = 'action-alias';
70 
71  $this->storeMock->expects($this->once())->method('getBaseUrl')->with('link', true)->willReturn($baseUrl);
72  $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($this->storeMock);
73 
74  $request = $this->getMockBuilder(\Magento\Framework\App\Request\Http::class)
75  ->disableOriginalConstructor()
76  ->getMock();
77 
78  $request->expects($this->once())->method('getAlias')->willReturn($alias);
79  $request->expects($this->never())->method('getPathInfo');
80  $this->assertSame($baseUrl . $alias, $this->model->getCurrentSecureUrl($request));
81  }
82 
88  public function testShouldBeSecureUnsecureBaseUrl($base, $secure)
89  {
90  $this->scopeConfigMock->expects($this->once())
91  ->method('getValue')
93  ->willReturn($base);
94  $this->assertSame($secure, $this->model->shouldBeSecure('path/to/action'));
95  }
96 
102  public function testShouldBeSecureSecureBaseUrl($base, $secure)
103  {
104  $path = 'path/to/action';
105 
106  $this->scopeConfigMock->expects($this->once())->method('isSetFlag')
108  ->willReturn($secure);
109 
110  $getValueReturnMap = [
112  [Store::XML_PATH_UNSECURE_BASE_URL, ScopeInterface::SCOPE_STORE, null, 'http://unsecure.url'],
113  ];
114 
115  $this->scopeConfigMock->expects($this->any())
116  ->method('getValue')
117  ->will($this->returnValueMap($getValueReturnMap));
118 
119  if ($secure) {
120  $this->urlSecurityInfoMock->expects($this->once())->method('isSecure')->with($path)->willReturn($secure);
121  }
122 
123  $this->assertSame($secure, $this->model->shouldBeSecure($path));
124  }
125 
129  public function urlSchemeProvider()
130  {
131  return [
132  ['https://base.url', true],
133  ['http://base.url', false]
134  ];
135  }
136 }
const XML_PATH_UNSECURE_BASE_URL
Definition: Store.php:66
const XML_PATH_SECURE_IN_FRONTEND
Definition: Store.php:70
const XML_PATH_SECURE_BASE_URL
Definition: Store.php:68
if(!trim($html)) $alias
Definition: details.phtml:20