Completed
Push — adminicons ( 220b8a...d1a314 )
by Andreas
03:46
created

helper_plugin_extension_extension_test::testFindFoldersTemplates()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 68
Code Lines 59

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 59
nc 1
nop 0
dl 0
loc 68
rs 9.2447
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * Class mock_helper_plugin_extension_extension
5
 *
6
 * makes protected methods accessible
7
 */
8
class mock_helper_plugin_extension_extension extends helper_plugin_extension_extension {
9
    public function find_folders(&$result, $base, $default_type = 'plugin', $dir = '') {
10
        return parent::find_folders($result, $base, $default_type, $dir);
11
    }
12
13
}
14
15
/**
16
 * @group plugin_extension
17
 * @group admin_plugins
18
 * @group plugins
19
 * @group bundled_plugins
20
 */
21
class helper_plugin_extension_extension_test extends DokuWikiTest {
22
23
    protected $pluginsEnabled = array('extension');
24
25
    /**
26
     * FIXME should we test this without internet first?
27
     *
28
     * @group internet
29
     */
30
    public function testExtensionParameters() {
31
        $extension = new helper_plugin_extension_extension();
32
33
        $extension->setExtension('extension');
34
        $this->assertEquals('extension', $extension->getID());
35
        $this->assertEquals('extension', $extension->getBase());
36
        $this->assertEquals('Extension Manager', $extension->getDisplayName());
37
        $this->assertEquals('Michael Hamann', $extension->getAuthor());
38
        $this->assertEquals('[email protected]', $extension->getEmail());
39
        $this->assertEquals(md5('[email protected]'), $extension->getEmailID());
40
        $this->assertEquals('https://www.dokuwiki.org/plugin:extension', $extension->getURL());
41
        $this->assertEquals('Allows managing and installing plugins and templates', $extension->getDescription());
42
        $this->assertFalse($extension->isTemplate());
43
        $this->assertTrue($extension->isEnabled());
44
        $this->assertTrue($extension->isInstalled());
45
        $this->assertTrue($extension->isBundled());
46
47
        $extension->setExtension('testing');
48
        $this->assertEquals('testing', $extension->getID());
49
        $this->assertEquals('testing', $extension->getBase());
50
        $this->assertEquals('Testing Plugin', $extension->getDisplayName());
51
        $this->assertEquals('Tobias Sarnowski', $extension->getAuthor());
52
        $this->assertEquals('[email protected]', $extension->getEmail());
53
        $this->assertEquals(md5('[email protected]'), $extension->getEmailID());
54
        $this->assertEquals('http://www.dokuwiki.org/plugin:testing', $extension->getURL());
55
        $this->assertEquals('Used to test the test framework. Should always be disabled.', $extension->getDescription());
56
        $this->assertFalse($extension->isTemplate());
57
        $this->assertFalse($extension->isEnabled());
58
        $this->assertTrue($extension->isInstalled());
59
        $this->assertTrue($extension->isBundled());
60
61
        $extension->setExtension('template:dokuwiki');
62
        $this->assertEquals('template:dokuwiki', $extension->getID());
63
        $this->assertEquals('dokuwiki', $extension->getBase());
64
        $this->assertEquals('DokuWiki Template', $extension->getDisplayName());
65
        $this->assertEquals('Anika Henke', $extension->getAuthor());
66
        $this->assertEquals('[email protected]', $extension->getEmail());
67
        $this->assertEquals(md5('[email protected]'), $extension->getEmailID());
68
        $this->assertEquals('http://www.dokuwiki.org/template:dokuwiki', $extension->getURL());
69
        $this->assertEquals('DokuWiki\'s default template since 2012', $extension->getDescription());
70
        $this->assertTrue($extension->isTemplate());
71
        $this->assertTrue($extension->isEnabled());
72
        $this->assertTrue($extension->isInstalled());
73
        $this->assertTrue($extension->isBundled());
74
    }
75
76
    public function testFindFoldersPlugins() {
77
        $extension = new mock_helper_plugin_extension_extension();
78
        $tdir      = dirname(__FILE__).'/testdata';
79
80
        $result = array('old' => array(), 'new' => array());
81
        $ok     = $extension->find_folders($result, "$tdir/plugin1", 'plugin');
82
        $this->assertTrue($ok);
83
        $this->assertEquals(0, count($result['new']));
84
        $this->assertEquals(1, count($result['old']));
85
        $this->assertEquals('plugin', $result['old'][0]['type']);
86
        $this->assertEquals('plugin1', $this->extdir($result['old'][0]['tmp']));
87
88
        $result = array('old' => array(), 'new' => array());
89
        $ok     = $extension->find_folders($result, "$tdir/plugin2", 'plugin');
90
        $this->assertTrue($ok);
91
        $this->assertEquals(1, count($result['new']));
92
        $this->assertEquals('plugin', $result['new'][0]['type']);
93
        $this->assertEquals('plugin2', $result['new'][0]['base']);
94
        $this->assertEquals('plugin2', $this->extdir($result['new'][0]['tmp']));
95
96
        $result = array('old' => array(), 'new' => array());
97
        $ok     = $extension->find_folders($result, "$tdir/plgsub3", 'plugin');
98
        $this->assertTrue($ok);
99
        $this->assertEquals(0, count($result['new']));
100
        $this->assertEquals(1, count($result['old']));
101
        $this->assertEquals('plugin', $result['old'][0]['type']);
102
        $this->assertEquals('plgsub3/plugin3', $this->extdir($result['old'][0]['tmp']));
103
104
        $result = array('old' => array(), 'new' => array());
105
        $ok     = $extension->find_folders($result, "$tdir/plgsub4", 'plugin');
106
        $this->assertTrue($ok);
107
        $this->assertEquals(1, count($result['new']));
108
        $this->assertEquals('plugin', $result['new'][0]['type']);
109
        $this->assertEquals('plugin4', $result['new'][0]['base']);
110
        $this->assertEquals('plgsub4/plugin4', $this->extdir($result['new'][0]['tmp']));
111
112
        $result = array('old' => array(), 'new' => array());
113
        $ok     = $extension->find_folders($result, "$tdir/plgfoo5", 'plugin');
114
        $this->assertTrue($ok);
115
        $this->assertEquals(1, count($result['new']));
116
        $this->assertEquals('plugin', $result['new'][0]['type']);
117
        $this->assertEquals('plugin5', $result['new'][0]['base']);
118
        $this->assertEquals('plgfoo5', $this->extdir($result['new'][0]['tmp']));
119
120
        $result = array('old' => array(), 'new' => array());
121
        $ok     = $extension->find_folders($result, "$tdir/plgsub6/plgfoo6", 'plugin');
122
        $this->assertTrue($ok);
123
        $this->assertEquals(1, count($result['new']));
124
        $this->assertEquals('plugin', $result['new'][0]['type']);
125
        $this->assertEquals('plugin6', $result['new'][0]['base']);
126
        $this->assertEquals('plgsub6/plgfoo6', $this->extdir($result['new'][0]['tmp']));
127
128
        $result = array('old' => array(), 'new' => array());
129
        $ok     = $extension->find_folders($result, "$tdir/either1", 'plugin');
130
        $this->assertTrue($ok);
131
        $this->assertEquals(0, count($result['new']));
132
        $this->assertEquals(1, count($result['old']));
133
        $this->assertEquals('plugin', $result['old'][0]['type']);
134
        $this->assertEquals('either1', $this->extdir($result['old'][0]['tmp']));
135
136
        $result = array('old' => array(), 'new' => array());
137
        $ok     = $extension->find_folders($result, "$tdir/eithersub2/either2", 'plugin');
138
        $this->assertTrue($ok);
139
        $this->assertEquals(0, count($result['new']));
140
        $this->assertEquals(1, count($result['old']));
141
        $this->assertEquals('plugin', $result['old'][0]['type']);
142
        $this->assertEquals('eithersub2/either2', $this->extdir($result['old'][0]['tmp']));
143
    }
144
145
    public function testFindFoldersTemplates() {
146
        $extension = new mock_helper_plugin_extension_extension();
147
        $tdir      = dirname(__FILE__).'/testdata';
148
149
        $result = array('old' => array(), 'new' => array());
150
        $ok     = $extension->find_folders($result, "$tdir/template1", 'template');
151
        $this->assertTrue($ok);
152
        $this->assertEquals(0, count($result['new']));
153
        $this->assertEquals(1, count($result['old']));
154
        $this->assertEquals('template', $result['old'][0]['type']);
155
        $this->assertEquals('template1', $this->extdir($result['old'][0]['tmp']));
156
157
        $result = array('old' => array(), 'new' => array());
158
        $ok     = $extension->find_folders($result, "$tdir/template2", 'template');
159
        $this->assertTrue($ok);
160
        $this->assertEquals(1, count($result['new']));
161
        $this->assertEquals('template', $result['new'][0]['type']);
162
        $this->assertEquals('template2', $result['new'][0]['base']);
163
        $this->assertEquals('template2', $this->extdir($result['new'][0]['tmp']));
164
165
        $result = array('old' => array(), 'new' => array());
166
        $ok     = $extension->find_folders($result, "$tdir/tplsub3", 'template');
167
        $this->assertTrue($ok);
168
        $this->assertEquals(0, count($result['new']));
169
        $this->assertEquals(1, count($result['old']));
170
        $this->assertEquals('template', $result['old'][0]['type']);
171
        $this->assertEquals('tplsub3/template3', $this->extdir($result['old'][0]['tmp']));
172
173
        $result = array('old' => array(), 'new' => array());
174
        $ok     = $extension->find_folders($result, "$tdir/tplsub4", 'template');
175
        $this->assertTrue($ok);
176
        $this->assertEquals(1, count($result['new']));
177
        $this->assertEquals('template', $result['new'][0]['type']);
178
        $this->assertEquals('template4', $result['new'][0]['base']);
179
        $this->assertEquals('tplsub4/template4', $this->extdir($result['new'][0]['tmp']));
180
181
        $result = array('old' => array(), 'new' => array());
182
        $ok     = $extension->find_folders($result, "$tdir/tplfoo5", 'template');
183
        $this->assertTrue($ok);
184
        $this->assertEquals(1, count($result['new']));
185
        $this->assertEquals('template', $result['new'][0]['type']);
186
        $this->assertEquals('template5', $result['new'][0]['base']);
187
        $this->assertEquals('tplfoo5', $this->extdir($result['new'][0]['tmp']));
188
189
        $result = array('old' => array(), 'new' => array());
190
        $ok     = $extension->find_folders($result, "$tdir/tplsub6/tplfoo6", 'template');
191
        $this->assertTrue($ok);
192
        $this->assertEquals(1, count($result['new']));
193
        $this->assertEquals('template', $result['new'][0]['type']);
194
        $this->assertEquals('template6', $result['new'][0]['base']);
195
        $this->assertEquals('tplsub6/tplfoo6', $this->extdir($result['new'][0]['tmp']));
196
197
        $result = array('old' => array(), 'new' => array());
198
        $ok     = $extension->find_folders($result, "$tdir/either1", 'template');
199
        $this->assertTrue($ok);
200
        $this->assertEquals(0, count($result['new']));
201
        $this->assertEquals(1, count($result['old']));
202
        $this->assertEquals('template', $result['old'][0]['type']);
203
        $this->assertEquals('either1', $this->extdir($result['old'][0]['tmp']));
204
205
        $result = array('old' => array(), 'new' => array());
206
        $ok     = $extension->find_folders($result, "$tdir/eithersub2/either2", 'template');
207
        $this->assertTrue($ok);
208
        $this->assertEquals(0, count($result['new']));
209
        $this->assertEquals(1, count($result['old']));
210
        $this->assertEquals('template', $result['old'][0]['type']);
211
        $this->assertEquals('eithersub2/either2', $this->extdir($result['old'][0]['tmp']));
212
    }
213
214
    public function testFindFoldersTemplatesAutodetect() {
215
        $extension = new mock_helper_plugin_extension_extension();
216
        $tdir      = dirname(__FILE__).'/testdata';
217
218
        $result = array('old' => array(), 'new' => array());
219
        $ok     = $extension->find_folders($result, "$tdir/template1");
220
        $this->assertTrue($ok);
221
        $this->assertEquals(0, count($result['new']));
222
        $this->assertEquals(1, count($result['old']));
223
        $this->assertEquals('template', $result['old'][0]['type']);
224
        $this->assertEquals('template1', $this->extdir($result['old'][0]['tmp']));
225
226
        $result = array('old' => array(), 'new' => array());
227
        $ok     = $extension->find_folders($result, "$tdir/template2");
228
        $this->assertTrue($ok);
229
        $this->assertEquals(1, count($result['new']));
230
        $this->assertEquals('template', $result['new'][0]['type']);
231
        $this->assertEquals('template2', $result['new'][0]['base']);
232
        $this->assertEquals('template2', $this->extdir($result['new'][0]['tmp']));
233
234
        $result = array('old' => array(), 'new' => array());
235
        $ok     = $extension->find_folders($result, "$tdir/tplsub3");
236
        $this->assertTrue($ok);
237
        $this->assertEquals(0, count($result['new']));
238
        $this->assertEquals(1, count($result['old']));
239
        $this->assertEquals('template', $result['old'][0]['type']);
240
        $this->assertEquals('tplsub3/template3', $this->extdir($result['old'][0]['tmp']));
241
242
        $result = array('old' => array(), 'new' => array());
243
        $ok     = $extension->find_folders($result, "$tdir/tplsub4");
244
        $this->assertTrue($ok);
245
        $this->assertEquals(1, count($result['new']));
246
        $this->assertEquals('template', $result['new'][0]['type']);
247
        $this->assertEquals('template4', $result['new'][0]['base']);
248
        $this->assertEquals('tplsub4/template4', $this->extdir($result['new'][0]['tmp']));
249
250
        $result = array('old' => array(), 'new' => array());
251
        $ok     = $extension->find_folders($result, "$tdir/tplfoo5");
252
        $this->assertTrue($ok);
253
        $this->assertEquals(1, count($result['new']));
254
        $this->assertEquals('template', $result['new'][0]['type']);
255
        $this->assertEquals('template5', $result['new'][0]['base']);
256
        $this->assertEquals('tplfoo5', $this->extdir($result['new'][0]['tmp']));
257
258
        $result = array('old' => array(), 'new' => array());
259
        $ok     = $extension->find_folders($result, "$tdir/tplsub6/tplfoo6");
260
        $this->assertTrue($ok);
261
        $this->assertEquals(1, count($result['new']));
262
        $this->assertEquals('template', $result['new'][0]['type']);
263
        $this->assertEquals('template6', $result['new'][0]['base']);
264
        $this->assertEquals('tplsub6/tplfoo6', $this->extdir($result['new'][0]['tmp']));
265
266
        $result = array('old' => array(), 'new' => array());
267
        $ok     = $extension->find_folders($result, "$tdir/either1");
268
        $this->assertTrue($ok);
269
        $this->assertEquals(0, count($result['new']));
270
        $this->assertEquals(1, count($result['old']));
271
        $this->assertEquals('plugin', $result['old'][0]['type']);
272
        $this->assertEquals('either1', $this->extdir($result['old'][0]['tmp']));
273
274
        $result = array('old' => array(), 'new' => array());
275
        $ok     = $extension->find_folders($result, "$tdir/eithersub2/either2");
276
        $this->assertTrue($ok);
277
        $this->assertEquals(0, count($result['new']));
278
        $this->assertEquals(1, count($result['old']));
279
        $this->assertEquals('plugin', $result['old'][0]['type']);
280
        $this->assertEquals('eithersub2/either2', $this->extdir($result['old'][0]['tmp']));
281
    }
282
283
    /**
284
     * remove the test data directory from a dir name for cross install comparison
285
     *
286
     * @param string $dir
287
     * @return string
288
     */
289
    protected function extdir($dir) {
290
        $tdir = dirname(__FILE__).'/testdata';
291
        $len  = strlen($tdir);
292
        $dir  = trim(substr($dir, $len), '/');
293
        return $dir;
294
    }
295
}