annotate vendor/webflo/drupal-finder/tests/Drupal7FinderTest.php @ 0:c75dbcec494b

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