comparison vendor/webflo/drupal-finder/tests/Drupal7FinderTest.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 Drupal7FinderTest extends DrupalFinderTestBase
8 {
9 /**
10 * @var \DrupalFinder\DrupalFinder
11 */
12 protected $finder;
13
14 protected static $fileStructure = [
15 'includes' => [
16 'common.inc' => '',
17 ],
18 'misc' => [
19 'drupal.js' => '',
20 ],
21 'sites' => [
22 'all' => [
23 'modules' => []
24 ]
25 ]
26 ];
27
28 /**
29 * @return array
30 */
31 protected function getDrupalComposerStructure()
32 {
33 $fileStructure = [
34 'web' => static::$fileStructure,
35 'composer.json' => [
36 'require' => [
37 'drupal/drupal' => '*',
38 ],
39 'extra' => [
40 'installer-paths' => [
41 'web/' => [
42 'type:drupal-core',
43 ],
44 ],
45 ],
46 ],
47 'vendor' => [],
48 ];
49 return $fileStructure;
50 }
51
52 public function testDrupalComposerStructure()
53 {
54 $fileStructure = $this->getDrupalComposerStructure();
55 $this->assertComposerStructure($fileStructure);
56 }
57
58 public function testDrupalComposerStructureWithoutRequire()
59 {
60 $fileStructure = [
61 'web' => static::$fileStructure,
62 'composer.json' => [
63 'extra' => [
64 'installer-paths' => [
65 'web' => [
66 'drupal/drupal',
67 ],
68 ],
69 ],
70 ],
71 ];
72 $this->assertComposerStructure($fileStructure);
73 }
74
75 public function testNoDrupalRootWithRealFilesystem()
76 {
77 $root = $this->tempdir(sys_get_temp_dir());
78
79 $this->assertFalse($this->finder->locateRoot($root));
80 $this->assertFalse($this->finder->getDrupalRoot());
81 $this->assertFalse($this->finder->getComposerRoot());
82 $this->assertFalse($this->finder->getVendorDir());
83 }
84
85 public function testDrupalComposerStructureWithRealFilesystem()
86 {
87 $root = $this->tempdir(sys_get_temp_dir());
88 $this->dumpToFileSystem($this->getDrupalComposerStructure(), $root);
89
90 $this->assertTrue($this->finder->locateRoot($root));
91 $this->assertSame($root . '/web', $this->finder->getDrupalRoot());
92 $this->assertSame($root, $this->finder->getComposerRoot());
93 $this->assertSame($root . '/vendor', $this->finder->getVendorDir());
94
95 // Test symlink implementation
96 $symlink = $this->tempdir(sys_get_temp_dir());
97 $this->symlink($root, $symlink . '/foo');
98
99 $this->assertTrue($this->finder->locateRoot($symlink . '/foo'));
100 $this->assertSame($root . '/web', $this->finder->getDrupalRoot());
101 $this->assertSame($root, $this->finder->getComposerRoot());
102 $this->assertSame($root . '/vendor', $this->finder->getVendorDir());
103 }
104
105 public function testDrupalWithLinkedModule()
106 {
107 $root = $this->tempdir(sys_get_temp_dir());
108 $this->dumpToFileSystem($this->getDrupalComposerStructure(), $root);
109
110 $module = $this->tempdir(sys_get_temp_dir());
111 $module_link = $root . '/web/sites/all/modules/foo';
112 $this->symlink($module, $module_link);
113
114 $this->assertTrue($this->finder->locateRoot($module_link));
115 $this->assertSame($root . '/web', realpath($this->finder->getDrupalRoot()));
116 $this->assertSame($root, realpath($this->finder->getComposerRoot()));
117 $this->assertSame($root . '/vendor', realpath($this->finder->getVendorDir()));
118 }
119
120 public function testDrupalWithCustomVendor()
121 {
122 $root = $this->tempdir(sys_get_temp_dir());
123 $fileStructure = $this->getDrupalComposerStructure();
124 $composerJson = $fileStructure['composer.json'];
125 $composerJson['config']['vendor-dir'] = 'vendor-foo';
126 $fileStructure['composer.json'] = $composerJson;
127 $fileStructure['vendor-foo'] = [];
128 $this->dumpToFileSystem($fileStructure, $root);
129
130 $this->assertTrue($this->finder->locateRoot($root));
131 $this->assertSame($root . '/web', realpath($this->finder->getDrupalRoot()));
132 $this->assertSame($root, realpath($this->finder->getComposerRoot()));
133 $this->assertSame($root . '/vendor-foo', realpath($this->finder->getVendorDir()));
134 }
135
136 /**
137 * @param $fileStructure
138 */
139 protected function assertComposerStructure($fileStructure)
140 {
141 $fileStructure = $this->prepareFileStructure($fileStructure);
142 $root = vfsStream::setup('root', null, $fileStructure);
143 $this->assertTrue($this->finder->locateRoot($root->url() . '/web'));
144 $this->assertSame('vfs://root/web', $this->finder->getDrupalRoot());
145 $this->assertSame('vfs://root', $this->finder->getComposerRoot());
146 $this->assertSame('vfs://root/vendor', $this->finder->getVendorDir());
147
148 $this->assertTrue($this->finder->locateRoot($root->url() . '/web/misc'));
149 $this->assertSame('vfs://root/web', $this->finder->getDrupalRoot());
150 $this->assertSame('vfs://root', $this->finder->getComposerRoot());
151 $this->assertSame('vfs://root/vendor', $this->finder->getVendorDir());
152
153 $this->assertTrue($this->finder->locateRoot($root->url()));
154 $this->assertSame('vfs://root/web', $this->finder->getDrupalRoot());
155 $this->assertSame('vfs://root', $this->finder->getComposerRoot());
156 $this->assertSame('vfs://root/vendor', $this->finder->getVendorDir());
157
158 $root = vfsStream::setup(
159 'root',
160 null,
161 ['nested_folder' => $fileStructure]
162 );
163 $this->assertFalse($this->finder->locateRoot($root->url()));
164 $this->assertFalse($this->finder->getDrupalRoot());
165 $this->assertFalse($this->finder->getComposerRoot());
166 $this->assertFalse($this->finder->getVendorDir());
167 }
168 }