2 namespace Drush\SiteAlias;
4 use PHPUnit\Framework\TestCase;
6 class SiteSpecParserTest extends TestCase
8 use \Drush\FixtureFactory;
11 * @dataProvider parserTestValues
13 public function testSiteSpecParser(
17 $root = $this->siteDir();
18 $fixtureSite = '/' . basename($root);
19 $parser = new SiteSpecParser();
21 // If the test spec begins with '/fixtures', substitute the
22 // actual path to our fixture site.
23 $spec = preg_replace('%^/fixtures%', $root, $spec);
26 $result = $parser->parse($spec, $root);
28 // If the result contains the path to our fixtures site, replace
29 // it with the simple string '/fixtures'.
30 if (isset($result['root'])) {
31 $result['root'] = preg_replace("%.*$fixtureSite%", '/fixtures', $result['root']);
34 // Compare the altered result with the expected value.
35 $this->assertEquals($expected, $result);
39 * @dataProvider validSiteSpecs
41 public function testValidSiteSpecs($spec)
43 $this->isSpecValid($spec, true);
47 * @dataProvider invalidSiteSpecs
49 public function testInvalidSiteSpecs($spec)
51 $this->isSpecValid($spec, false);
54 protected function isSpecValid($spec, $expected)
56 $parser = new SiteSpecParser();
58 $result = $parser->validSiteSpec($spec);
59 $this->assertEquals($expected, $result);
62 public static function validSiteSpecs()
65 [ '/path/to/drupal#uri' ],
66 [ 'user@server/path/to/drupal#uri' ],
67 [ 'user@server/path/to/drupal' ],
68 [ 'user@server#uri' ],
73 public static function invalidSiteSpecs()
79 [ '@server/path/to/drupal#uri' ],
80 [ 'user@server/path/to/drupal#' ],
81 [ 'user@server/path/to/drupal#uri!' ],
82 [ 'user@server/path/to/drupal##uri' ],
83 [ 'user#server/path/to/drupal#uri' ],
87 public static function parserTestValues()
91 'user@server/path#somemultisite',
96 'uri' => 'somemultisite',
111 '/fixtures#mymultisite',
113 'root' => '/fixtures',
114 'uri' => 'mymultisite',
121 'root' => '/fixtures',
122 'uri' => 'mymultisite',
127 '/fixtures#somemultisite',
133 '/path#somemultisite',