794b63e9226a123118b03055a9fab9b78415b400
[yaffs-website] / vendor / drush / drush / isolation / tests / SiteSpecParserTest.php
1 <?php
2 namespace Drush\SiteAlias;
3
4 use PHPUnit\Framework\TestCase;
5
6 class SiteSpecParserTest extends TestCase
7 {
8     use \Drush\FixtureFactory;
9
10     /**
11      * @dataProvider parserTestValues
12      */
13     public function testSiteSpecParser(
14         $spec,
15         $expected)
16     {
17         $root = $this->siteDir();
18         $fixtureSite = '/' . basename($root);
19         $parser = new SiteSpecParser();
20
21         // If the test spec begins with '/fixtures', substitute the
22         // actual path to our fixture site.
23         $spec = preg_replace('%^/fixtures%', $root, $spec);
24
25         // Parse it!
26         $result = $parser->parse($spec, $root);
27
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']);
32         }
33
34         // Compare the altered result with the expected value.
35         $this->assertEquals($expected, $result);
36     }
37
38     /**
39      * @dataProvider validSiteSpecs
40      */
41     public function testValidSiteSpecs($spec)
42     {
43         $this->isSpecValid($spec, true);
44     }
45
46     /**
47      * @dataProvider invalidSiteSpecs
48      */
49     public function testInvalidSiteSpecs($spec)
50     {
51         $this->isSpecValid($spec, false);
52     }
53
54     protected function isSpecValid($spec, $expected)
55     {
56         $parser = new SiteSpecParser();
57
58         $result = $parser->validSiteSpec($spec);
59         $this->assertEquals($expected, $result);
60     }
61
62     public static function validSiteSpecs()
63     {
64         return [
65             [ '/path/to/drupal#uri' ],
66             [ 'user@server/path/to/drupal#uri' ],
67             [ 'user.name@example.com/path/to/drupal#uri' ],
68             [ 'user@server/path/to/drupal' ],
69             [ 'user@example.com/path/to/drupal' ],
70             [ 'user@server#uri' ],
71             [ 'user@example.com#uri' ],
72             [ '#uri' ],
73         ];
74     }
75
76     public static function invalidSiteSpecs()
77     {
78         return [
79             [ 'uri' ],
80             [ '@/#' ],
81             [ 'user@#uri' ],
82             [ '@server/path/to/drupal#uri' ],
83             [ 'user@server/path/to/drupal#' ],
84             [ 'user@server/path/to/drupal#uri!' ],
85             [ 'user@server/path/to/drupal##uri' ],
86             [ 'user#server/path/to/drupal#uri' ],
87        ];
88     }
89
90     public static function parserTestValues()
91     {
92         return [
93             [
94                 'user@server/path#somemultisite',
95                 [
96                     'user' => 'user',
97                     'host' => 'server',
98                     'root' => '/path',
99                     'uri' => 'somemultisite',
100                 ],
101             ],
102
103             [
104                 'user.name@example.com/path#somemultisite',
105                 [
106                     'user' => 'user.name',
107                     'host' => 'example.com',
108                     'root' => '/path',
109                     'uri' => 'somemultisite',
110                 ],
111             ],
112
113             [
114                 'user@server/path',
115                 [
116                     'user' => 'user',
117                     'host' => 'server',
118                     'root' => '/path',
119                     'uri' => 'default',
120                 ],
121             ],
122
123             [
124                 'user.name@example.com/path',
125                 [
126                     'user' => 'user.name',
127                     'host' => 'example.com',
128                     'root' => '/path',
129                     'uri' => 'default',
130                 ],
131             ],
132
133             [
134                 '/fixtures#mymultisite',
135                 [
136                     'root' => '/fixtures',
137                     'uri' => 'mymultisite',
138                 ],
139             ],
140
141             [
142                 '#mymultisite',
143                 [
144                     'root' => '/fixtures',
145                     'uri' => 'mymultisite',
146                 ],
147             ],
148
149             [
150                 '/fixtures#somemultisite',
151                 [
152                 ],
153             ],
154
155             [
156                 '/path#somemultisite',
157                 [
158                 ],
159             ],
160
161             [
162                 '/path#mymultisite',
163                 [
164                 ],
165             ],
166
167             [
168                 '#somemultisite',
169                 [
170                 ],
171             ],
172         ];
173     }
174 }