forked from drush-ops/drush
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSiteSpecParserTest.php
175 lines (151 loc) · 4.29 KB
/
SiteSpecParserTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
namespace Drush\SiteAlias;
use PHPUnit\Framework\TestCase;
class SiteSpecParserTest extends TestCase
{
use \Unish\Utils\Fixtures;
/**
* @dataProvider parserTestValues
*/
public function testSiteSpecParser(
$spec,
$expected
) {
$root = $this->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.name@example.com/path/to/drupal#uri' ],
[ 'user@server/path/to/drupal' ],
[ 'user@example.com/path/to/drupal' ],
[ 'user@server#uri' ],
[ 'user@example.com#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.name@example.com/path#somemultisite',
[
'user' => 'user.name',
'host' => 'example.com',
'root' => '/path',
'uri' => 'somemultisite',
],
],
[
'user@server/path',
[
'user' => 'user',
'host' => 'server',
'root' => '/path',
'uri' => 'default',
],
],
[
'user.name@example.com/path',
[
'user' => 'user.name',
'host' => 'example.com',
'root' => '/path',
'uri' => 'default',
],
],
[
'/fixtures#mymultisite',
[
'root' => '/fixtures',
'uri' => 'mymultisite',
],
],
[
'#mymultisite',
[
'root' => '/fixtures',
'uri' => 'mymultisite',
],
],
[
'/fixtures#somemultisite',
[
],
],
[
'/path#somemultisite',
[
],
],
[
'/path#mymultisite',
[
],
],
[
'#somemultisite',
[
],
],
];
}
}