Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / vendor / drush / drush / isolation / tests / SiteAliasFileLoaderTest.php
1 <?php
2 namespace Drush\SiteAlias;
3
4 use PHPUnit\Framework\TestCase;
5
6 use Consolidation\SiteAlias\Util\YamlDataFileLoader;
7 use Consolidation\SiteAlias\AliasRecord;
8
9 class SiteAliasFileLoaderTest extends TestCase
10 {
11     use \Drush\FixtureFactory;
12     use \Drush\FunctionUtils;
13
14     function setUp()
15     {
16         $this->sut = new SiteAliasFileLoader();
17
18         $ymlLoader = new YamlDataFileLoader();
19         $this->sut->addLoader('yml', $ymlLoader);
20     }
21
22     public function testLoadSingleAliasFile()
23     {
24         $siteAliasFixtures = $this->fixturesDir() . '/sitealiases/single';
25         $this->assertTrue(is_dir($siteAliasFixtures));
26         $this->assertTrue(is_file($siteAliasFixtures . '/simple.site.yml'));
27         $this->assertTrue(is_file($siteAliasFixtures . '/single.site.yml'));
28
29         $this->sut->addSearchLocation($siteAliasFixtures);
30
31         // Look for a simple alias with no environments defined
32         $name = new SiteAliasName('simple');
33         $result = $this->callProtected('loadSingleAliasFile', [$name]);
34         $this->assertEquals(AliasRecord::class, get_class($result));
35         $this->assertEquals('/path/to/simple', $result->get('root'));
36
37         // Look for a single alias without an environment specified.
38         $name = new SiteAliasName('single');
39         $result = $this->callProtected('loadSingleAliasFile', [$name]);
40         $this->assertTrue($result instanceof AliasRecord);
41         $this->assertEquals('/path/to/single', $result->get('root'));
42         $this->assertEquals('bar', $result->get('foo'));
43
44         // Same test, but with environment explicitly requested.
45         $name = new SiteAliasName('single', 'alternate');
46         $result = $this->callProtected('loadSingleAliasFile', [$name]);
47         $this->assertTrue($result instanceof AliasRecord);
48         $this->assertEquals('/alternate/path/to/single', $result->get('root'));
49         $this->assertEquals('bar', $result->get('foo'));
50
51         // Try to fetch an alias that does not exist.
52         $name = new SiteAliasName('missing');
53         $result = $this->callProtected('loadSingleAliasFile', [$name]);
54         $this->assertFalse($result);
55     }
56
57     public function testLoadLegacy()
58     {
59         $this->sut->addSearchLocation($this->fixturesDir() . '/sitealiases/legacy');
60     }
61
62     public function testLoad()
63     {
64         $this->sut->addSearchLocation($this->fixturesDir() . '/sitealiases/single');
65         $this->sut->addSearchLocation($this->fixturesDir() . '/sitealiases/group');
66
67         // Look for a simple alias with no environments defined
68         $name = new SiteAliasName('simple');
69         $result = $this->sut->load($name);
70         $this->assertTrue($result instanceof AliasRecord);
71         $this->assertEquals('/path/to/simple', $result->get('root'));
72
73         // Look for a single alias without an environment specified.
74         $name = new SiteAliasName('single');
75         $result = $this->sut->load($name);
76         $this->assertTrue($result instanceof AliasRecord);
77         $this->assertEquals('/path/to/single', $result->get('root'));
78         $this->assertEquals('bar', $result->get('foo'));
79
80         // Same test, but with environment explicitly requested.
81         $name = new SiteAliasName('single', 'alternate');
82         $result = $this->sut->load($name);
83         $this->assertTrue($result instanceof AliasRecord);
84         $this->assertEquals('/alternate/path/to/single', $result->get('root'));
85         $this->assertEquals('bar', $result->get('foo'));
86
87         // Try to fetch an alias that does not exist.
88         $name = new SiteAliasName('missing');
89         $result = $this->sut->load($name);
90         $this->assertFalse($result);
91
92         // Try to fetch an alias that does not exist.
93         $name = new SiteAliasName('missing');
94         $result = $this->sut->load($name);
95         $this->assertFalse($result);
96     }
97
98     public function testLoadAll()
99     {
100         $this->sut->addSearchLocation($this->fixturesDir() . '/sitealiases/single');
101
102         $all = $this->sut->loadAll();
103         $this->assertEquals('@single.single.alternate,@single.single.dev', implode(',', array_keys($all)));
104     }
105 }