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