X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fdrush%2Fdrush%2Fisolation%2Ftests%2FSiteSpecParserTest.php;fp=vendor%2Fdrush%2Fdrush%2Fisolation%2Ftests%2FSiteSpecParserTest.php;h=417b7f9768cf9d522df2639f17e0b2318e4bb618;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/vendor/drush/drush/isolation/tests/SiteSpecParserTest.php b/vendor/drush/drush/isolation/tests/SiteSpecParserTest.php new file mode 100644 index 000000000..417b7f976 --- /dev/null +++ b/vendor/drush/drush/isolation/tests/SiteSpecParserTest.php @@ -0,0 +1,151 @@ +siteDir(); + $fixtureSite = '/' . basename($root); + $parser = new SiteSpecParser(); + + // If the test spec begins with '/fixtures', substitute the + // actual path to our fixture site. + $spec = preg_replace('%^/fixtures%', $root, $spec); + + // Parse it! + $result = $parser->parse($spec, $root); + + // If the result contains the path to our fixtures site, replace + // it with the simple string '/fixtures'. + if (isset($result['root'])) { + $result['root'] = preg_replace("%.*$fixtureSite%", '/fixtures', $result['root']); + } + + // Compare the altered result with the expected value. + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider validSiteSpecs + */ + public function testValidSiteSpecs($spec) + { + $this->isSpecValid($spec, true); + } + + /** + * @dataProvider invalidSiteSpecs + */ + public function testInvalidSiteSpecs($spec) + { + $this->isSpecValid($spec, false); + } + + protected function isSpecValid($spec, $expected) + { + $parser = new SiteSpecParser(); + + $result = $parser->validSiteSpec($spec); + $this->assertEquals($expected, $result); + } + + public static function validSiteSpecs() + { + return [ + [ '/path/to/drupal#uri' ], + [ 'user@server/path/to/drupal#uri' ], + [ 'user@server/path/to/drupal' ], + [ 'user@server#uri' ], + [ '#uri' ], + ]; + } + + public static function invalidSiteSpecs() + { + return [ + [ 'uri' ], + [ '@/#' ], + [ 'user@#uri' ], + [ '@server/path/to/drupal#uri' ], + [ 'user@server/path/to/drupal#' ], + [ 'user@server/path/to/drupal#uri!' ], + [ 'user@server/path/to/drupal##uri' ], + [ 'user#server/path/to/drupal#uri' ], + ]; + } + + public static function parserTestValues() + { + return [ + [ + 'user@server/path#somemultisite', + [ + 'user' => 'user', + 'host' => 'server', + 'root' => '/path', + 'uri' => 'somemultisite', + ], + ], + + [ + 'user@server/path', + [ + 'user' => 'user', + 'host' => 'server', + 'root' => '/path', + 'uri' => 'default', + ], + ], + + [ + '/fixtures#mymultisite', + [ + 'root' => '/fixtures', + 'uri' => 'mymultisite', + ], + ], + + [ + '#mymultisite', + [ + 'root' => '/fixtures', + 'uri' => 'mymultisite', + ], + ], + + [ + '/fixtures#somemultisite', + [ + ], + ], + + [ + '/path#somemultisite', + [ + ], + ], + + [ + '/path#mymultisite', + [ + ], + ], + + [ + '#somemultisite', + [ + ], + ], + ]; + } +}