comparison vendor/webflo/drupal-finder/tests/Drupal8FinderTest.php @ 18:af1871eacc83

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:33:08 +0100
parents
children
comparison
equal deleted inserted replaced
17:129ea1e6d783 18:af1871eacc83
1 <?php
2
3 namespace DrupalFinder\Tests;
4
5 use org\bovigo\vfs\vfsStream;
6
7 class Drupal8FinderTest extends DrupalFinderTestBase
8 {
9 protected static $fileStructure = [
10 'autoload.php' => '',
11 'composer.json' => [
12 'extra' => [
13 'installer-paths' => [
14 'core' => [
15 'type:drupal-core'
16 ]
17 ]
18 ]
19 ],
20 'core' => [
21 'includes' => [
22 'common.inc' => '',
23 ],
24 'misc' => [
25 'drupal.js' => '',
26 ],
27 'core.services.yml' => '',
28 ],
29 'modules' => [],
30 'vendor' => [],
31 ];
32
33 /**
34 * @return array
35 */
36 protected function getDrupalComposerStructure()
37 {
38 $fileStructure = [
39 'web' => static::$fileStructure,
40 'composer.json' => [
41 'require' => [
42 'drupal/core' => '*',
43 ],
44 'extra' => [
45 'installer-paths' => [
46 'web/core' => [
47 'type:drupal-core',
48 ],
49 ],
50 ],
51 ],
52 'vendor' => [],
53 ];
54 unset($fileStructure['web']['composer.json']);
55 unset($fileStructure['web']['vendor']);
56
57 return $fileStructure;
58 }
59
60 protected function setUp()
61 {
62 parent::setUp();
63 $this->finder = new \DrupalFinder\DrupalFinder();
64 }
65
66 public function testDrupalDefaultStructure()
67 {
68 $root = vfsStream::setup('root', null, $this->prepareFileStructure(static::$fileStructure));
69
70 $this->assertTrue($this->finder->locateRoot($root->url()));
71 $this->assertSame('vfs://root', $this->finder->getDrupalRoot());
72 $this->assertSame('vfs://root', $this->finder->getComposerRoot());
73 $this->assertSame('vfs://root/vendor', $this->finder->getVendorDir());
74
75 $this->assertTrue($this->finder->locateRoot($root->url() . '/misc'));
76 $this->assertSame('vfs://root', $this->finder->getDrupalRoot());
77 $this->assertSame('vfs://root', $this->finder->getComposerRoot());
78 $this->assertSame('vfs://root/vendor', $this->finder->getVendorDir());
79
80 $root = vfsStream::setup(
81 'root',
82 null,
83 ['project' => $this->prepareFileStructure(static::$fileStructure)]
84 );
85 $this->assertFalse(
86 $this->finder->locateRoot($root->url()),
87 'Not in the scope of the project'
88 );
89 $this->assertFalse($this->finder->getDrupalRoot());
90 $this->assertFalse($this->finder->getComposerRoot());
91 $this->assertFalse($this->finder->getVendorDir());
92 }
93
94 public function testDrupalComposerStructure()
95 {
96 $fileStructure = $this->getDrupalComposerStructure();
97 $this->assertComposerStructure($fileStructure);
98 }
99
100 public function testDrupalComposerStructureWithCustomRoot()
101 {
102 $fileStructure = [
103 'src' => static::$fileStructure,
104 'composer.json' => [
105 'require' => [
106 'drupal/core' => '*',
107 ],
108 'extra' => [
109 'installer-paths' => [
110 'src/core' => [
111 'type:drupal-core',
112 ],
113 ],
114 ],
115 ],
116 'vendor' => [],
117 ];
118 unset($fileStructure['src']['composer.json']);
119 unset($fileStructure['src']['vendor']);
120
121 $fileStructure = $this->prepareFileStructure($fileStructure);
122 $root = vfsStream::setup('root', null, $fileStructure);
123 $this->assertTrue($this->finder->locateRoot($root->url() . '/src'));
124 $this->assertSame('vfs://root/src', $this->finder->getDrupalRoot());
125 $this->assertSame('vfs://root', $this->finder->getComposerRoot());
126 $this->assertSame('vfs://root/vendor', $this->finder->getVendorDir());
127
128 $this->assertTrue($this->finder->locateRoot($root->url() . '/src/misc'));
129 $this->assertSame('vfs://root/src', $this->finder->getDrupalRoot());
130 $this->assertSame('vfs://root', $this->finder->getComposerRoot());
131 $this->assertSame('vfs://root/vendor', $this->finder->getVendorDir());
132
133 $this->assertTrue($this->finder->locateRoot($root->url()));
134 $this->assertSame('vfs://root/src', $this->finder->getDrupalRoot());
135 $this->assertSame('vfs://root', $this->finder->getComposerRoot());
136 $this->assertSame('vfs://root/vendor', $this->finder->getVendorDir());
137
138 $root = vfsStream::setup(
139 'root',
140 null,
141 ['nested_folder' => $fileStructure]
142 );
143 $this->assertFalse($this->finder->locateRoot($root->url()));
144 $this->assertFalse($this->finder->getDrupalRoot());
145 $this->assertFalse($this->finder->getComposerRoot());
146 $this->assertFalse($this->finder->getVendorDir());
147 }
148
149 public function testDrupalComposerStructureWithoutRequire()
150 {
151 $fileStructure = [
152 'web' => static::$fileStructure,
153 'composer.json' => [
154 'extra' => [
155 'installer-paths' => [
156 'web/core' => [
157 'drupal/core',
158 ],
159 ],
160 ],
161 ],
162 ];
163 unset($fileStructure['web']['composer.json']);
164 $this->assertComposerStructure($fileStructure);
165 }
166
167 public function testNoDrupalRootWithRealFilesystem()
168 {
169 $root = $this->tempdir(sys_get_temp_dir());
170
171 $this->assertFalse($this->finder->locateRoot($root));
172 $this->assertFalse($this->finder->getDrupalRoot());
173 $this->assertFalse($this->finder->getComposerRoot());
174 $this->assertFalse($this->finder->getVendorDir());
175 }
176
177 public function testDrupalDefaultStructureWithRealFilesystem()
178 {
179 $root = $this->tempdir(sys_get_temp_dir());
180 $this->dumpToFileSystem(static::$fileStructure, $root);
181
182 $this->assertTrue($this->finder->locateRoot($root));
183 $this->assertSame($root, $this->finder->getDrupalRoot());
184 $this->assertSame($root, $this->finder->getComposerRoot());
185 $this->assertSame($root . '/vendor', $this->finder->getVendorDir());
186
187 // Test symlink implementation
188 $symlink = $this->tempdir(sys_get_temp_dir());
189 $this->symlink($root, $symlink . '/foo');
190
191 $this->assertTrue($this->finder->locateRoot($symlink . '/foo'));
192 $this->assertSame($root, $this->finder->getDrupalRoot());
193 $this->assertSame($root, $this->finder->getComposerRoot());
194 $this->assertSame($root . '/vendor', $this->finder->getVendorDir());
195 }
196
197 public function testDrupalComposerStructureWithRealFilesystem()
198 {
199 $root = $this->tempdir(sys_get_temp_dir());
200 $this->dumpToFileSystem($this->getDrupalComposerStructure(), $root);
201
202 $this->assertTrue($this->finder->locateRoot($root));
203 $this->assertSame($root . '/web', $this->finder->getDrupalRoot());
204 $this->assertSame($root, $this->finder->getComposerRoot());
205 $this->assertSame($root . '/vendor', $this->finder->getVendorDir());
206
207 // Test symlink implementation
208 $symlink = $this->tempdir(sys_get_temp_dir());
209 $this->symlink($root, $symlink . '/foo');
210
211 $this->assertTrue($this->finder->locateRoot($symlink . '/foo'));
212 $this->assertSame($root . '/web', $this->finder->getDrupalRoot());
213 $this->assertSame($root, $this->finder->getComposerRoot());
214 $this->assertSame($root . '/vendor', $this->finder->getVendorDir());
215 }
216
217 public function testDrupalWithLinkedModule()
218 {
219 $root = $this->tempdir(sys_get_temp_dir());
220 $this->dumpToFileSystem(static::$fileStructure, $root);
221
222 $module = $this->tempdir(sys_get_temp_dir());
223 $module_link = $root . '/modules/foo';
224 $this->symlink($module, $module_link);
225
226 $this->assertTrue($this->finder->locateRoot($module_link));
227 $this->assertSame($root, realpath($this->finder->getDrupalRoot()));
228 $this->assertSame($root, realpath($this->finder->getComposerRoot()));
229 $this->assertSame($root . '/vendor', realpath($this->finder->getVendorDir()));
230 }
231
232 public function testDrupalWithCustomVendor()
233 {
234 $root = $this->tempdir(sys_get_temp_dir());
235 $fileStructure = static::$fileStructure;
236 $fileStructure['composer.json'] = [
237 'config' => [
238 'vendor-dir' => 'vendor-foo'
239 ]
240 ];
241 $fileStructure['vendor-foo'] = [];
242 $this->dumpToFileSystem($fileStructure, $root);
243
244 $this->assertTrue($this->finder->locateRoot($root));
245 $this->assertSame($root, realpath($this->finder->getDrupalRoot()));
246 $this->assertSame($root, realpath($this->finder->getComposerRoot()));
247 $this->assertSame($root . '/vendor-foo', realpath($this->finder->getVendorDir()));
248 }
249
250 /**
251 * @param $fileStructure
252 */
253 protected function assertComposerStructure($fileStructure)
254 {
255 $fileStructure = $this->prepareFileStructure($fileStructure);
256 $root = vfsStream::setup('root', null, $fileStructure);
257 $this->assertTrue($this->finder->locateRoot($root->url() . '/web'));
258 $this->assertSame('vfs://root/web', $this->finder->getDrupalRoot());
259 $this->assertSame('vfs://root', $this->finder->getComposerRoot());
260 $this->assertSame('vfs://root/vendor', $this->finder->getVendorDir());
261
262 $this->assertTrue($this->finder->locateRoot($root->url() . '/web/misc'));
263 $this->assertSame('vfs://root/web', $this->finder->getDrupalRoot());
264 $this->assertSame('vfs://root', $this->finder->getComposerRoot());
265 $this->assertSame('vfs://root/vendor', $this->finder->getVendorDir());
266
267 $this->assertTrue($this->finder->locateRoot($root->url()));
268 $this->assertSame('vfs://root/web', $this->finder->getDrupalRoot());
269 $this->assertSame('vfs://root', $this->finder->getComposerRoot());
270 $this->assertSame('vfs://root/vendor', $this->finder->getVendorDir());
271
272 $root = vfsStream::setup(
273 'root',
274 null,
275 ['nested_folder' => $fileStructure]
276 );
277 $this->assertFalse($this->finder->locateRoot($root->url()));
278 $this->assertFalse($this->finder->getDrupalRoot());
279 $this->assertFalse($this->finder->getComposerRoot());
280 $this->assertFalse($this->finder->getVendorDir());
281 }
282 }