Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / drush / drush / isolation / tests / SiteAliasFileDiscoveryTest.php
diff --git a/vendor/drush/drush/isolation/tests/SiteAliasFileDiscoveryTest.php b/vendor/drush/drush/isolation/tests/SiteAliasFileDiscoveryTest.php
new file mode 100644 (file)
index 0000000..5cf85c4
--- /dev/null
@@ -0,0 +1,70 @@
+<?php
+namespace Drush\SiteAlias;
+
+use PHPUnit\Framework\TestCase;
+
+class SiteAliasFileDiscoveryTest extends TestCase
+{
+    use \Drush\FixtureFactory;
+    use \Drush\FunctionUtils;
+
+    function setUp()
+    {
+        $this->sut = new SiteAliasFileDiscovery();
+    }
+
+    public function testSearchForSingleAliasFile()
+    {
+        $this->sut->addSearchLocation($this->fixturesDir() . '/sitealiases/single');
+
+        $path = $this->sut->findSingleSiteAliasFile('single');
+        $this->assertLocation('single', $path);
+        $this->assertBasename('single.site.yml', $path);
+    }
+
+    public function testSearchForMissingSingleAliasFile()
+    {
+        $this->sut->addSearchLocation($this->fixturesDir() . '/sitealiases/single');
+
+        $path = $this->sut->findSingleSiteAliasFile('missing');
+        $this->assertFalse($path);
+    }
+
+    public function testFindAllLegacyAliasFiles()
+    {
+        $this->sut->addSearchLocation($this->fixturesDir() . '/sitealiases/legacy');
+
+        $result = $this->sut->findAllLegacyAliasFiles();
+        $paths = $this->simplifyToBasenamesWithLocation($result);
+        $this->assertEquals('legacy/cc.aliases.drushrc.php,legacy/one.alias.drushrc.php,legacy/pantheon.aliases.drushrc.php,legacy/server.aliases.drushrc.php', implode(',', $paths));
+    }
+
+    protected function assertLocation($expected, $path)
+    {
+        $this->assertEquals($expected, basename(dirname($path)));
+    }
+
+    protected function assertBasename($expected, $path)
+    {
+        $this->assertEquals($expected, basename($path));
+    }
+
+    protected function simplifyToBasenamesWithLocation($result)
+    {
+        if (!is_array($result)) {
+            return $result;
+        }
+
+        $result = array_map(
+            function ($item) {
+                return basename(dirname($item)) . '/' . basename($item);
+            }
+            ,
+            $result
+        );
+
+        sort($result);
+
+        return $result;
+    }
+}