annotate vendor/webflo/drupal-finder/tests/Drupal7FinderTest.php @ 19:fa3358dc1485 tip

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