1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Tests for the AddonBuilder |
4
|
|
|
* |
5
|
|
|
* @package mysite |
6
|
|
|
*/ |
7
|
|
|
class AddonBuilderTest extends SapphireTest |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @var AddonBuilder |
11
|
|
|
*/ |
12
|
|
|
protected $builder; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Get the test subject |
16
|
|
|
*/ |
17
|
|
|
public function setUp() |
18
|
|
|
{ |
19
|
|
|
parent::setUp(); |
20
|
|
|
|
21
|
|
|
// Partially mocked as we don't care about the PackagistService at this point |
22
|
|
|
$this->builder = $this->getMockBuilder('AddonBuilder') |
|
|
|
|
23
|
|
|
->setMethods(null) |
24
|
|
|
->disableOriginalConstructor() |
25
|
|
|
->getMock(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Test that a GitHub repository can be identified, and have its context returned if it matches |
30
|
|
|
* |
31
|
|
|
* @param string $input |
32
|
|
|
* @param string|false $expected |
33
|
|
|
* @dataProvider repositoryContextProvider |
34
|
|
|
*/ |
35
|
|
|
public function testGetGitHubContext($input, $expected) |
36
|
|
|
{ |
37
|
|
|
$addon = new Addon(array('Repository' => $input)); |
38
|
|
|
$builder = Injector::inst()->create('AddonBuilder'); |
39
|
|
|
$result = $builder->getGitHubContext($addon); |
40
|
|
|
$this->assertSame($expected, $result); |
|
|
|
|
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function repositoryContextProvider() |
44
|
|
|
{ |
45
|
|
|
return array( |
46
|
|
|
array('https://github.com/silverstripe/addons.org.git', 'silverstripe/addons.org'), |
47
|
|
|
array('http://github.com/silverstripe/addons.org.git', 'silverstripe/addons.org'), |
48
|
|
|
array('https://github.com/silverstripe/sspak.git', 'silverstripe/sspak'), |
49
|
|
|
array('http://github.com/silverstripe/sspak.git', 'silverstripe/sspak') |
50
|
|
|
); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Test that the GitHub-ness of an addon's repository can be correctly established |
55
|
|
|
* |
56
|
|
|
* @param string $repository |
57
|
|
|
* @param bool $expected |
58
|
|
|
* @covers ::hasGitHubRepository |
59
|
|
|
* @dataProvider hasGitHubProvider |
60
|
|
|
*/ |
61
|
|
|
public function testHasGitHubRepository($repository, $expected) |
62
|
|
|
{ |
63
|
|
|
$addon = Addon::create(); |
64
|
|
|
$addon->Repository = $repository; |
|
|
|
|
65
|
|
|
|
66
|
|
|
$result = $this->builder->hasGitHubRepository($addon); |
67
|
|
|
$this->assertSame($expected, $result); |
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return array |
72
|
|
|
*/ |
73
|
|
|
public function hasGitHubProvider() |
74
|
|
|
{ |
75
|
|
|
return array( |
76
|
|
|
array( |
77
|
|
|
'https://github.com/silverstripe/silverstripe-framework', |
78
|
|
|
true |
79
|
|
|
), |
80
|
|
|
array( |
81
|
|
|
'https://bitbucket.org/some/otherrepo', |
82
|
|
|
false |
83
|
|
|
) |
84
|
|
|
); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Test that we can determine the differece between a relative-ish URI and one that isn't, so we know |
89
|
|
|
* when to insert the GitHub repository URL into the mix. |
90
|
|
|
* |
91
|
|
|
* @param string $uri |
92
|
|
|
* @param bool $expected |
93
|
|
|
* @covers ::isRelativeUri |
94
|
|
|
* @dataProvider uriProvider() |
95
|
|
|
*/ |
96
|
|
|
public function testIsRelativeUri($uri, $expected) |
97
|
|
|
{ |
98
|
|
|
$this->assertSame($expected, $this->builder->isRelativeUri($uri)); |
|
|
|
|
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @return array |
103
|
|
|
*/ |
104
|
|
|
public function uriProvider() |
105
|
|
|
{ |
106
|
|
|
return array( |
107
|
|
|
array('/add-ons/silverstripe/sapphire#-preview', false), |
108
|
|
|
array('#installation-with-composer', false), |
109
|
|
|
array('resources/example.png?raw=true', true), |
110
|
|
|
array('add-ons/silverstripe/sapphire#usage', true), |
111
|
|
|
array('//add-ons/silverstripe/sapphire#usage', false), |
112
|
|
|
array('https://silverstripe.mit-license.org/', false), |
113
|
|
|
array('http://silverstripe.mit-license.org/', false) |
114
|
|
|
); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Ensure that a HTML readme can have its relative links rewritten according to the Addon is belongs to |
119
|
|
|
* |
120
|
|
|
* @covers ::replaceRelativeLinks |
121
|
|
|
*/ |
122
|
|
View Code Duplication |
public function testRewriteRelativeLinksAndImages() |
|
|
|
|
123
|
|
|
{ |
124
|
|
|
$addon = Addon::create(); |
125
|
|
|
$addon->Repository = 'https://github.com/silverstripe/silverstripe-framework'; |
|
|
|
|
126
|
|
|
// phpcs:disable |
127
|
|
|
$input = <<<HTML |
128
|
|
|
<h1>Heading</h1> |
129
|
|
|
|
130
|
|
|
<p><a href="relative">Relative</a> and <a href="//absolute.com">absolute</a>.</p> |
131
|
|
|
|
132
|
|
|
<p><img src="relative.png"><img src="https://www.whatever.com/image.png"></p> |
133
|
|
|
HTML; |
134
|
|
|
|
135
|
|
|
$expected = <<<HTML |
136
|
|
|
<h1>Heading</h1> |
137
|
|
|
|
138
|
|
|
<p><a href="https://github.com/silverstripe/silverstripe-framework/blob/master/relative">Relative</a> and <a href="//absolute.com">absolute</a>.</p> |
139
|
|
|
|
140
|
|
|
<p><img src="https://github.com/silverstripe/silverstripe-framework/raw/master/relative.png"><img src="https://www.whatever.com/image.png"></p> |
141
|
|
|
HTML; |
142
|
|
|
// phpcs:enable |
143
|
|
|
|
144
|
|
|
$this->assertSame($expected, $this->builder->replaceRelativeLinks($addon, $input)); |
|
|
|
|
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* For non GitHub repositories, the readme input should simply be returned as is from the "replaceRelativeLinks" |
149
|
|
|
* method |
150
|
|
|
*/ |
151
|
|
View Code Duplication |
public function testDoNotRewriteRelativeLinksForNonGitHubRepositories() |
|
|
|
|
152
|
|
|
{ |
153
|
|
|
$addon = Addon::create(); |
154
|
|
|
$addon->Repository = 'https://gitlab.com/not-a/github-repo.git'; |
|
|
|
|
155
|
|
|
$readme = '<p>Please do not touch me.</p>'; |
156
|
|
|
$this->assertSame($readme, $this->builder->replaceRelativeLinks($addon, $readme)); |
|
|
|
|
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.