2 namespace Consolidation\SiteAlias;
4 use PHPUnit\Framework\TestCase;
6 class SiteSpecParserTest extends TestCase
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);
25 // Make sure that our spec is valid
26 $this->assertTrue($parser->validSiteSpec($spec));
29 $result = $parser->parse($spec, $root);
31 // If the result contains the path to our fixtures site, replace
32 // it with the simple string '/fixtures'.
33 if (isset($result['root'])) {
34 $result['root'] = preg_replace("%.*$fixtureSite%", '/fixtures', $result['root']);
37 // Compare the altered result with the expected value.
38 $this->assertEquals($expected, $result);
42 * @dataProvider validSiteSpecs
44 public function testValidSiteSpecs($spec)
46 $this->isSpecValid($spec, true);
50 * @dataProvider invalidSiteSpecs
52 public function testInvalidSiteSpecs($spec)
54 $this->isSpecValid($spec, false);
57 protected function isSpecValid($spec, $expected)
59 $parser = new SiteSpecParser();
61 $result = $parser->validSiteSpec($spec);
62 $this->assertEquals($expected, $result);
65 public static function validSiteSpecs()
68 [ '/path/to/drupal#uri' ],
69 [ 'user@server/path/to/drupal#uri' ],
70 [ 'user.name@example.com/path/to/drupal#uri' ],
71 [ 'user@server/path/to/drupal' ],
72 [ 'user@example.com/path/to/drupal' ],
73 [ 'user@server#uri' ],
74 [ 'user@example.com#uri' ],
79 public static function invalidSiteSpecs()
85 [ '@server/path/to/drupal#uri' ],
86 [ 'user@server/path/to/drupal#' ],
87 [ 'user@server/path/to/drupal#uri!' ],
88 [ 'user@server/path/to/drupal##uri' ],
89 [ 'user#server/path/to/drupal#uri' ],
93 public static function parserTestValues()
97 'user@server/path#somemultisite',
102 'uri' => 'somemultisite',
107 'user.name@example.com/path#somemultisite',
109 'user' => 'user.name',
110 'host' => 'example.com',
112 'uri' => 'somemultisite',
127 'user.name@example.com/path',
129 'user' => 'user.name',
130 'host' => 'example.com',
137 '/fixtures#mymultisite',
139 'root' => '/fixtures',
140 'uri' => 'mymultisite',
147 'root' => '/fixtures',
148 'uri' => 'mymultisite',
153 '/fixtures#somemultisite',
159 '/path#somemultisite',