Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SetupInfoTest.php
Go to the documentation of this file.
1 <?php
8 
9 use \Magento\Framework\App\SetupInfo;
10 
11 class SetupInfoTest extends \PHPUnit\Framework\TestCase
12 {
18  private static $fixture = ['DOCUMENT_ROOT' => '/doc/root', 'SCRIPT_FILENAME' => '/doc/root/dir/file.php'];
19 
25  public function testConstructorExceptions($server, $expectedError)
26  {
27  $this->expectException('\InvalidArgumentException');
28  $this->expectExceptionMessage($expectedError);
29  new SetupInfo($server);
30  }
31 
36  {
37  $docRootErr = 'DOCUMENT_ROOT variable is unavailable.';
38  $projectRootErr = 'Project root cannot be automatically detected.';
39  return [
40  [[], $docRootErr],
41  [['DOCUMENT_ROOT' => ''], $docRootErr],
42  [['DOCUMENT_ROOT' => '/foo'], $projectRootErr],
43  [['DOCUMENT_ROOT' => '/foo', 'SCRIPT_FILENAME' => ''], $projectRootErr],
44  ];
45  }
46 
52  public function testGetUrl($server, $expected)
53  {
54  $info = new SetupInfo($server);
55  $this->assertEquals($expected, $info->getUrl());
56  }
57 
61  public function getUrlDataProvider()
62  {
63  return [
64  [
65  self::$fixture,
66  '/setup/'
67  ],
68  [
69  self::$fixture + [SetupInfo::PARAM_NOT_INSTALLED_URL_PATH => 'install'],
70  '/install/',
71  ],
72  [
73  self::$fixture + [SetupInfo::PARAM_NOT_INSTALLED_URL => 'http://example.com/'],
74  'http://example.com/',
75  ],
76  ];
77  }
78 
84  public function testGetProjectUrl($server, $expected)
85  {
86  $info = new SetupInfo($server);
87  $this->assertEquals($expected, $info->getProjectUrl());
88  }
89 
93  public function getProjectUrlDataProvider()
94  {
95  return [
96  [self::$fixture, ''],
97  [self::$fixture + ['HTTP_HOST' => ''], ''],
98  [
99  ['DOCUMENT_ROOT' => '/foo/bar', 'SCRIPT_FILENAME' => '/other/baz.php', 'HTTP_HOST' => 'example.com'],
100  'http://example.com/'
101  ],
102  [self::$fixture + ['HTTP_HOST' => 'example.com'], 'http://example.com/dir/'],
103  [
104  ['DOCUMENT_ROOT' => '/foo/bar', 'SCRIPT_FILENAME' => '/foo/bar/baz.php', 'HTTP_HOST' => 'example.com'],
105  'http://example.com/'
106  ],
107  ];
108  }
109 
116  public function testGetDir($server, $projectRoot, $expected)
117  {
118  $info = new SetupInfo($server);
119  $this->assertEquals($expected, $info->getDir($projectRoot));
120  }
121 
125  public function getDirDataProvider()
126  {
127  return [
128  [
129  self::$fixture,
130  '/test/root',
131  '/test/root/setup',
132  ],
133  [
134  self::$fixture,
135  '/test/root/',
136  '/test/root/setup',
137  ],
138  [
139  self::$fixture + [SetupInfo::PARAM_NOT_INSTALLED_URL_PATH => '/install/'],
140  '/test/',
141  '/test/install',
142  ],
143  ];
144  }
145 
151  public function testIsAvailable($server, $expected)
152  {
153  $info = new SetupInfo($server);
154  $this->assertEquals($expected, $info->isAvailable());
155  }
156 
160  public function isAvailableDataProvider()
161  {
162  $server = ['DOCUMENT_ROOT' => __DIR__, 'SCRIPT_FILENAME' => __FILE__];
163  return [
164  'root = doc root, but no "setup" sub-directory' => [
165  $server, // it will look for "setup/" sub-directory, but won't find anything
166  false
167  ],
168  'root = doc root, nonexistent sub-directory' => [
169  $server + [SetupInfo::PARAM_NOT_INSTALLED_URL_PATH => 'nonexistent'],
170  false
171  ],
172  'root = doc root, existent sub-directory' => [
173  $server + [SetupInfo::PARAM_NOT_INSTALLED_URL_PATH => '_files'],
174  true
175  ],
176  'root within doc root, existent sub-directory' => [
177  [
178  'DOCUMENT_ROOT' => dirname(__DIR__),
179  'SCRIPT_FILENAME' => __FILE__,
181  ],
182  true
183  ],
184  'root outside of doc root, existent sub-directory' => [
185  [
186  'DOCUMENT_ROOT' => __DIR__,
187  'SCRIPT_FILENAME' => dirname(dirname(__DIR__)) . '/foo.php',
189  ],
190  false
191  ],
192  'root within doc root, existent sub-directory, trailing slash' => [
193  [
194  'DOCUMENT_ROOT' => dirname(__DIR__) . DIRECTORY_SEPARATOR,
195  'SCRIPT_FILENAME' => __FILE__,
197  ],
198  true
199  ],
200  'root within doc root + pub, existent sub-directory' => [
201  [
202  'DOCUMENT_ROOT' => __DIR__ . '/_files/pub/',
203  'SCRIPT_FILENAME' => __DIR__ . '/_files/pub/index.php',
204  ],
205  true
206  ],
207  ];
208  }
209 }
return false
Definition: gallery.phtml:36
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
defined('MTF_BOOT_FILE')||define('MTF_BOOT_FILE' __FILE__
Definition: bootstrap.php:7
testGetDir($server, $projectRoot, $expected)
testConstructorExceptions($server, $expectedError)
foreach( $_productCollection as $_product)() ?>" class $info
Definition: listing.phtml:52