2 namespace Drush\SiteAlias;
4 use PHPUnit\Framework\TestCase;
6 class SiteAliasFileLoaderTest extends TestCase
8 use \Drush\FixtureFactory;
9 use \Drush\FunctionUtils;
13 $this->sut = new SiteAliasFileLoader();
16 public function testLoadSingleAliasFile()
18 $this->sut->addSearchLocation($this->fixturesDir() . '/sitealiases/single');
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'));
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'));
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'));
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);
46 public function testLoadLegacy()
48 $this->sut->addSearchLocation($this->fixturesDir() . '/sitealiases/legacy');
51 public function testLoad()
53 $this->sut->addSearchLocation($this->fixturesDir() . '/sitealiases/single');
54 $this->sut->addSearchLocation($this->fixturesDir() . '/sitealiases/group');
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'));
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'));
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'));
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);
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);
87 public function testLoadAll()
89 $this->sut->addSearchLocation($this->fixturesDir() . '/sitealiases/single');
91 $all = $this->sut->loadAll();
92 $this->assertEquals('@single.alternate,@single.common,@single.dev', implode(',', array_keys($all)));