1 |
efrain |
1 |
<?php
|
|
|
2 |
// phpcs:ignoreFile
|
|
|
3 |
// @codeCoverageIgnoreStart
|
|
|
4 |
|
|
|
5 |
// This file is part of Moodle - http://moodle.org/
|
|
|
6 |
//
|
|
|
7 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
8 |
// it under the terms of the GNU General Public License as published by
|
|
|
9 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
10 |
// (at your option) any later version.
|
|
|
11 |
//
|
|
|
12 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
13 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
14 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
15 |
// GNU General Public License for more details.
|
|
|
16 |
//
|
|
|
17 |
// You should have received a copy of the GNU General Public License
|
|
|
18 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
19 |
|
|
|
20 |
/**
|
|
|
21 |
* Unit tests for behat manager.
|
|
|
22 |
*
|
|
|
23 |
* @package tool_behat
|
|
|
24 |
* @copyright 2016 Rajesh Taneja
|
|
|
25 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
26 |
*/
|
|
|
27 |
|
|
|
28 |
namespace tool_behat;
|
|
|
29 |
|
|
|
30 |
use behat_config_util;
|
|
|
31 |
|
|
|
32 |
defined('MOODLE_INTERNAL') || die();
|
|
|
33 |
|
|
|
34 |
global $CFG;
|
|
|
35 |
require_once($CFG->dirroot . '/' . $CFG->admin .'/tool/behat/locallib.php');
|
|
|
36 |
require_once($CFG->libdir . '/behat/classes/util.php');
|
|
|
37 |
require_once($CFG->libdir . '/behat/classes/behat_config_manager.php');
|
|
|
38 |
|
|
|
39 |
/**
|
|
|
40 |
* Behat manager tests.
|
|
|
41 |
*
|
|
|
42 |
* @package tool_behat
|
|
|
43 |
* @copyright 2016 Rajesh Taneja
|
|
|
44 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
45 |
*/
|
|
|
46 |
class manager_util_test extends \advanced_testcase {
|
|
|
47 |
|
|
|
48 |
/** @var array Fixtures features which are available. */
|
|
|
49 |
private $featurepaths = array(
|
|
|
50 |
'default' => array(
|
|
|
51 |
'test_1.feature',
|
|
|
52 |
'test_2.feature',
|
|
|
53 |
),
|
|
|
54 |
'withfeatures' => array(
|
|
|
55 |
'theme_test_1.feature',
|
|
|
56 |
'theme_test_2.feature',
|
|
|
57 |
'theme_test_3.feature',
|
|
|
58 |
'theme_test_4.feature',
|
|
|
59 |
'theme_test_5.feature',
|
|
|
60 |
),
|
|
|
61 |
'nofeatures' => array()
|
|
|
62 |
);
|
|
|
63 |
|
|
|
64 |
/** @var array Fixture contexts which are available */
|
|
|
65 |
private $contextspath = array(
|
|
|
66 |
'default' => array(
|
|
|
67 |
'behat_test_context_1',
|
|
|
68 |
'behat_test_context_2',
|
|
|
69 |
'behat_theme_defaulttheme_test_context_1'
|
|
|
70 |
),
|
|
|
71 |
'withfeatures' => array(
|
|
|
72 |
'behat_test_context_2',
|
|
|
73 |
'behat_theme_withfeatures_test_context_2',
|
|
|
74 |
'behat_theme_withfeatures_behat_test_context_1'
|
|
|
75 |
),
|
|
|
76 |
'nofeatures' => array(
|
|
|
77 |
'behat_test_context_1',
|
|
|
78 |
'behat_theme_nofeatures_test_context_1',
|
|
|
79 |
'behat_theme_nofeatures_behat_test_context_2'
|
|
|
80 |
),
|
|
|
81 |
);
|
|
|
82 |
|
|
|
83 |
/** @var array List of core features. */
|
|
|
84 |
private $corefeatures = array('test_1_core_fixtures_tests_behat_tool' => __DIR__.'/fixtures/core/test_1.feature',
|
|
|
85 |
'test_2_core_fixtures_tests_behat_tool' => __DIR__.'/fixtures/core/test_2.feature');
|
|
|
86 |
|
|
|
87 |
/** @var array List of core contexts. */
|
|
|
88 |
private $corecontexts = array('behat_test_context_1' => __DIR__.'/fixtures/core/behat_test_context_1.php',
|
|
|
89 |
'behat_test_context_2' => __DIR__.'/fixtures/core/behat_test_context_2.php');
|
|
|
90 |
|
|
|
91 |
/**
|
|
|
92 |
* Setup test.
|
|
|
93 |
*/
|
|
|
94 |
public function setUp(): void {
|
|
|
95 |
global $CFG;
|
|
|
96 |
|
|
|
97 |
$this->resetAfterTest();
|
|
|
98 |
$CFG->behat_wwwroot = 'http://example.com/behat';
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
/**
|
|
|
102 |
* Utility function to build mock object.
|
|
|
103 |
*
|
|
|
104 |
* @param behat_config_util $behatconfigutil
|
|
|
105 |
* @param bool $notheme
|
|
|
106 |
* @return mixed
|
|
|
107 |
*/
|
|
|
108 |
private function get_behat_config_util($behatconfigutil, $notheme = false) {
|
|
|
109 |
// Create a map of arguments to return values.
|
|
|
110 |
$map = array(
|
|
|
111 |
array('withfeatures', __DIR__.'/fixtures/theme/withfeatures'),
|
|
|
112 |
array('nofeatures', __DIR__.'/fixtures/theme/nofeatures'),
|
|
|
113 |
array('defaulttheme', __DIR__.'/fixtures/theme/defaulttheme'),
|
|
|
114 |
);
|
|
|
115 |
// List of themes is const for test.
|
|
|
116 |
if ($notheme) {
|
|
|
117 |
$themelist = array('defaulttheme');
|
|
|
118 |
} else {
|
|
|
119 |
$themelist = array('withfeatures', 'nofeatures', 'defaulttheme');
|
|
|
120 |
}
|
|
|
121 |
|
|
|
122 |
$thememap = [];
|
|
|
123 |
foreach ($themelist as $themename) {
|
|
|
124 |
$mock = $this->getMockBuilder('theme_config');
|
|
|
125 |
$mock->disableOriginalConstructor();
|
|
|
126 |
$thememap[] = [$themename, $mock->getMock()];
|
|
|
127 |
}
|
|
|
128 |
|
|
|
129 |
$behatconfigutil->expects($this->any())
|
|
|
130 |
->method('get_list_of_themes')
|
|
|
131 |
->will($this->returnValue($themelist));
|
|
|
132 |
|
|
|
133 |
// Theme directory for testing.
|
|
|
134 |
$behatconfigutil->expects($this->any())
|
|
|
135 |
->method('get_theme_test_directory')
|
|
|
136 |
->will($this->returnValueMap($map));
|
|
|
137 |
|
|
|
138 |
// Theme directory for testing.
|
|
|
139 |
$behatconfigutil->expects($this->any())
|
|
|
140 |
->method('get_theme_config')
|
|
|
141 |
->will($this->returnValueMap($thememap));
|
|
|
142 |
|
|
|
143 |
$behatconfigutil->expects($this->any())
|
|
|
144 |
->method('get_default_theme')
|
|
|
145 |
->will($this->returnValue('defaulttheme'));
|
|
|
146 |
|
|
|
147 |
return $behatconfigutil;
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
/**
|
|
|
151 |
* Behat config for single run.
|
|
|
152 |
*/
|
|
|
153 |
public function test_get_config_file_contents_with_single_run() {
|
|
|
154 |
|
|
|
155 |
$mockbuilder = $this->getMockBuilder('behat_config_util');
|
|
|
156 |
$mockbuilder->onlyMethods(array('get_theme_test_directory', 'get_list_of_themes', 'get_default_theme', 'get_theme_config'));
|
|
|
157 |
|
|
|
158 |
$behatconfigutil = $mockbuilder->getMock();
|
|
|
159 |
|
|
|
160 |
$behatconfigutil = $this->get_behat_config_util($behatconfigutil);
|
|
|
161 |
$config = $behatconfigutil->get_config_file_contents($this->corefeatures, $this->corecontexts);
|
|
|
162 |
|
|
|
163 |
// Two suites should be present.
|
|
|
164 |
$suites = $config['default']['suites'];
|
|
|
165 |
$this->assertCount(3, $suites);
|
|
|
166 |
|
|
|
167 |
// Check features.
|
|
|
168 |
foreach ($this->featurepaths as $themename => $paths) {
|
|
|
169 |
$this->assertCount(count($paths), $suites[$themename]['paths']);
|
|
|
170 |
|
|
|
171 |
foreach ($paths as $key => $feature) {
|
|
|
172 |
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
|
|
|
173 |
}
|
|
|
174 |
}
|
|
|
175 |
|
|
|
176 |
// Check contexts.
|
|
|
177 |
foreach ($this->contextspath as $themename => $paths) {
|
|
|
178 |
$this->assertCount(count($paths), $suites[$themename]['contexts']);
|
|
|
179 |
|
|
|
180 |
foreach ($paths as $key => $context) {
|
|
|
181 |
$this->assertTrue(in_array($context, $suites[$themename]['contexts']));
|
|
|
182 |
}
|
|
|
183 |
}
|
|
|
184 |
|
|
|
185 |
// There are 7 step definitions.
|
|
|
186 |
$this->assertCount(7, $config['default']['extensions']['Moodle\BehatExtension']['steps_definitions']);
|
|
|
187 |
}
|
|
|
188 |
|
|
|
189 |
/**
|
|
|
190 |
* Behat config for single run with no theme installed.
|
|
|
191 |
*/
|
|
|
192 |
public function test_get_config_file_contents_with_single_run_no_theme() {
|
|
|
193 |
|
|
|
194 |
$mockbuilder = $this->getMockBuilder('behat_config_util');
|
|
|
195 |
$mockbuilder->onlyMethods(array('get_theme_test_directory', 'get_list_of_themes', 'get_default_theme', 'get_theme_config'));
|
|
|
196 |
|
|
|
197 |
$behatconfigutil = $mockbuilder->getMock();
|
|
|
198 |
|
|
|
199 |
$behatconfigutil = $this->get_behat_config_util($behatconfigutil, true);
|
|
|
200 |
$config = $behatconfigutil->get_config_file_contents($this->corefeatures, $this->corecontexts);
|
|
|
201 |
|
|
|
202 |
// Two suites should be present.
|
|
|
203 |
$suites = $config['default']['suites'];
|
|
|
204 |
$this->assertCount(1, $suites);
|
|
|
205 |
|
|
|
206 |
$featurepaths = array(
|
|
|
207 |
'default' => array(
|
|
|
208 |
'test_1.feature',
|
|
|
209 |
'test_2.feature',
|
|
|
210 |
)
|
|
|
211 |
);
|
|
|
212 |
|
|
|
213 |
$contextspath = array(
|
|
|
214 |
'default' => array(
|
|
|
215 |
'behat_test_context_1',
|
|
|
216 |
'behat_test_context_2',
|
|
|
217 |
'behat_theme_defaulttheme_test_context_1',
|
|
|
218 |
)
|
|
|
219 |
);
|
|
|
220 |
|
|
|
221 |
// Check features.
|
|
|
222 |
foreach ($featurepaths as $themename => $paths) {
|
|
|
223 |
$this->assertCount(count($paths), $suites[$themename]['paths']);
|
|
|
224 |
|
|
|
225 |
foreach ($paths as $key => $feature) {
|
|
|
226 |
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
|
|
|
227 |
}
|
|
|
228 |
}
|
|
|
229 |
|
|
|
230 |
// Check contexts.
|
|
|
231 |
foreach ($contextspath as $themename => $paths) {
|
|
|
232 |
$this->assertCount(count($paths), $suites[$themename]['contexts']);
|
|
|
233 |
|
|
|
234 |
foreach ($paths as $key => $context) {
|
|
|
235 |
$this->assertTrue(in_array($context, $suites[$themename]['contexts']));
|
|
|
236 |
}
|
|
|
237 |
}
|
|
|
238 |
|
|
|
239 |
// There are 3 step definitions.
|
|
|
240 |
$this->assertCount(3, $config['default']['extensions']['Moodle\BehatExtension']['steps_definitions']);
|
|
|
241 |
}
|
|
|
242 |
|
|
|
243 |
/**
|
|
|
244 |
* Behat config for parallel run.
|
|
|
245 |
*/
|
|
|
246 |
public function test_get_config_file_contents_with_parallel_run() {
|
|
|
247 |
|
|
|
248 |
$mockbuilder = $this->getMockBuilder('behat_config_util');
|
|
|
249 |
$mockbuilder->onlyMethods(array('get_theme_test_directory', 'get_list_of_themes', 'get_default_theme', 'get_theme_config'));
|
|
|
250 |
|
|
|
251 |
$behatconfigutil = $mockbuilder->getMock();
|
|
|
252 |
|
|
|
253 |
$behatconfigutil = $this->get_behat_config_util($behatconfigutil);
|
|
|
254 |
|
|
|
255 |
// Test first run out of 3.
|
|
|
256 |
$config = $behatconfigutil->get_config_file_contents($this->corefeatures, $this->corecontexts, '', 3, 1);
|
|
|
257 |
// Three suites should be present.
|
|
|
258 |
$suites = $config['default']['suites'];
|
|
|
259 |
$this->assertCount(3, $suites);
|
|
|
260 |
// There is first feature file in first run.
|
|
|
261 |
$featurepaths = array(
|
|
|
262 |
'default' => array('test_1.feature'),
|
|
|
263 |
'withfeatures' => array('theme_test_1.feature', 'theme_test_2.feature'),
|
|
|
264 |
'nofeatures' => array()
|
|
|
265 |
);
|
|
|
266 |
// Check features.
|
|
|
267 |
foreach ($featurepaths as $themename => $paths) {
|
|
|
268 |
$this->assertCount(count($paths), $suites[$themename]['paths']);
|
|
|
269 |
|
|
|
270 |
foreach ($paths as $key => $feature) {
|
|
|
271 |
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
|
|
|
272 |
}
|
|
|
273 |
}
|
|
|
274 |
|
|
|
275 |
// Check contexts.
|
|
|
276 |
foreach ($this->contextspath as $themename => $paths) {
|
|
|
277 |
$this->assertCount(count($paths), $suites[$themename]['contexts']);
|
|
|
278 |
|
|
|
279 |
foreach ($paths as $key => $context) {
|
|
|
280 |
$this->assertTrue(in_array($context, $suites[$themename]['contexts']));
|
|
|
281 |
}
|
|
|
282 |
}
|
|
|
283 |
// There are 7 step definitions.
|
|
|
284 |
$this->assertCount(7, $config['default']['extensions']['Moodle\BehatExtension']['steps_definitions']);
|
|
|
285 |
|
|
|
286 |
// Test second run out of 3.
|
|
|
287 |
$config = $behatconfigutil->get_config_file_contents('', '', '', 3, 2);
|
|
|
288 |
// Three suites should be present.
|
|
|
289 |
$suites = $config['default']['suites'];
|
|
|
290 |
$this->assertCount(3, $suites);
|
|
|
291 |
// There is second feature file in first run.
|
|
|
292 |
$featurepaths = array(
|
|
|
293 |
'default' => array('test_2.feature'),
|
|
|
294 |
'withfeatures' => array('theme_test_3.feature', 'theme_test_4.feature'),
|
|
|
295 |
'nofeatures' => array()
|
|
|
296 |
);
|
|
|
297 |
// Check features.
|
|
|
298 |
foreach ($featurepaths as $themename => $paths) {
|
|
|
299 |
$this->assertCount(count($paths), $suites[$themename]['paths']);
|
|
|
300 |
|
|
|
301 |
foreach ($paths as $key => $feature) {
|
|
|
302 |
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
|
|
|
303 |
}
|
|
|
304 |
}
|
|
|
305 |
// Check contexts.
|
|
|
306 |
foreach ($this->contextspath as $themename => $paths) {
|
|
|
307 |
$this->assertCount(count($paths), $suites[$themename]['contexts']);
|
|
|
308 |
|
|
|
309 |
foreach ($paths as $key => $context) {
|
|
|
310 |
$this->assertTrue(in_array($context, $suites[$themename]['contexts']));
|
|
|
311 |
}
|
|
|
312 |
}
|
|
|
313 |
// There are 7 step definitions.
|
|
|
314 |
$this->assertCount(7, $config['default']['extensions']['Moodle\BehatExtension']['steps_definitions']);
|
|
|
315 |
|
|
|
316 |
// Test third run out of 3.
|
|
|
317 |
$config = $behatconfigutil->get_config_file_contents('', '', '', 3, 3);
|
|
|
318 |
$suites = $config['default']['suites'];
|
|
|
319 |
$this->assertCount(3, $suites);
|
|
|
320 |
// There is second feature file in first run.
|
|
|
321 |
$featurepaths = array(
|
|
|
322 |
'default' => array(),
|
|
|
323 |
'withfeatures' => array('theme_test_5.feature'),
|
|
|
324 |
'nofeatures' => array()
|
|
|
325 |
);
|
|
|
326 |
// Check features.
|
|
|
327 |
foreach ($featurepaths as $themename => $paths) {
|
|
|
328 |
$this->assertCount(count($paths), $suites[$themename]['paths']);
|
|
|
329 |
|
|
|
330 |
foreach ($paths as $key => $feature) {
|
|
|
331 |
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
|
|
|
332 |
}
|
|
|
333 |
}
|
|
|
334 |
// Check contexts.
|
|
|
335 |
foreach ($this->contextspath as $themename => $paths) {
|
|
|
336 |
$this->assertCount(count($paths), $suites[$themename]['contexts']);
|
|
|
337 |
|
|
|
338 |
foreach ($paths as $key => $context) {
|
|
|
339 |
$this->assertTrue(in_array($context, $suites[$themename]['contexts']));
|
|
|
340 |
}
|
|
|
341 |
}
|
|
|
342 |
// There are 7 step definitions.
|
|
|
343 |
$this->assertCount(7, $config['default']['extensions']['Moodle\BehatExtension']['steps_definitions']);
|
|
|
344 |
}
|
|
|
345 |
|
|
|
346 |
/**
|
|
|
347 |
* Behat config for parallel run.
|
|
|
348 |
*/
|
|
|
349 |
public function test_get_config_file_contents_with_parallel_run_optimize_tags() {
|
|
|
350 |
|
|
|
351 |
$mockbuilder = $this->getMockBuilder('behat_config_util');
|
|
|
352 |
$mockbuilder->onlyMethods(array('get_theme_test_directory', 'get_list_of_themes', 'get_default_theme', 'get_theme_config'));
|
|
|
353 |
|
|
|
354 |
$behatconfigutil = $mockbuilder->getMock();
|
|
|
355 |
|
|
|
356 |
$behatconfigutil = $this->get_behat_config_util($behatconfigutil);
|
|
|
357 |
|
|
|
358 |
// Test first run out of 3.
|
|
|
359 |
$config = $behatconfigutil->get_config_file_contents($this->corefeatures, $this->corecontexts, '@commontag', 3, 1);
|
|
|
360 |
|
|
|
361 |
// Three suites should be present.
|
|
|
362 |
$suites = $config['default']['suites'];
|
|
|
363 |
$this->assertCount(3, $suites);
|
|
|
364 |
// There is first feature file in first run.
|
|
|
365 |
$featurepaths = array(
|
|
|
366 |
'default' => array('test_1.feature'),
|
|
|
367 |
'withfeatures' => array('theme_test_1.feature', 'theme_test_3.feature'),
|
|
|
368 |
'nofeatures' => array()
|
|
|
369 |
);
|
|
|
370 |
// Check features.
|
|
|
371 |
foreach ($featurepaths as $themename => $paths) {
|
|
|
372 |
$this->assertCount(count($paths), $suites[$themename]['paths']);
|
|
|
373 |
|
|
|
374 |
foreach ($paths as $key => $feature) {
|
|
|
375 |
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
|
|
|
376 |
}
|
|
|
377 |
}
|
|
|
378 |
// Check contexts.
|
|
|
379 |
foreach ($this->contextspath as $themename => $paths) {
|
|
|
380 |
$this->assertCount(count($paths), $suites[$themename]['contexts']);
|
|
|
381 |
|
|
|
382 |
foreach ($paths as $key => $context) {
|
|
|
383 |
$this->assertTrue(in_array($context, $suites[$themename]['contexts']));
|
|
|
384 |
}
|
|
|
385 |
}
|
|
|
386 |
// There are 7step definitions.
|
|
|
387 |
$this->assertCount(7, $config['default']['extensions']['Moodle\BehatExtension']['steps_definitions']);
|
|
|
388 |
|
|
|
389 |
// Test second run out of 3.
|
|
|
390 |
$config = $behatconfigutil->get_config_file_contents('', '', '@commontag', 3, 2);
|
|
|
391 |
|
|
|
392 |
// Three suites should be present.
|
|
|
393 |
$suites = $config['default']['suites'];
|
|
|
394 |
$this->assertCount(3, $suites);
|
|
|
395 |
// There is second feature file in first run.
|
|
|
396 |
$featurepaths = array(
|
|
|
397 |
'default' => array('test_2.feature'),
|
|
|
398 |
'withfeatures' => array('theme_test_2.feature', 'theme_test_4.feature'),
|
|
|
399 |
'nofeatures' => array()
|
|
|
400 |
);
|
|
|
401 |
// Check features.
|
|
|
402 |
foreach ($featurepaths as $themename => $paths) {
|
|
|
403 |
$this->assertCount(count($paths), $suites[$themename]['paths']);
|
|
|
404 |
|
|
|
405 |
foreach ($paths as $key => $feature) {
|
|
|
406 |
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
|
|
|
407 |
}
|
|
|
408 |
}
|
|
|
409 |
// Check contexts.
|
|
|
410 |
foreach ($this->contextspath as $themename => $paths) {
|
|
|
411 |
$this->assertCount(count($paths), $suites[$themename]['contexts']);
|
|
|
412 |
|
|
|
413 |
foreach ($paths as $key => $context) {
|
|
|
414 |
$this->assertTrue(in_array($context, $suites[$themename]['contexts']));
|
|
|
415 |
}
|
|
|
416 |
}
|
|
|
417 |
// There are 7 step definitions.
|
|
|
418 |
$this->assertCount(7, $config['default']['extensions']['Moodle\BehatExtension']['steps_definitions']);
|
|
|
419 |
|
|
|
420 |
// Test third run out of 3.
|
|
|
421 |
$config = $behatconfigutil->get_config_file_contents('', '', '', 3, 3);
|
|
|
422 |
$suites = $config['default']['suites'];
|
|
|
423 |
$this->assertCount(3, $suites);
|
|
|
424 |
// There is second feature file in first run.
|
|
|
425 |
$featurepaths = array(
|
|
|
426 |
'default' => array(),
|
|
|
427 |
'withfeatures' => array('theme_test_5.feature'),
|
|
|
428 |
'nofeatures' => array()
|
|
|
429 |
);
|
|
|
430 |
// Check features.
|
|
|
431 |
foreach ($featurepaths as $themename => $paths) {
|
|
|
432 |
$this->assertCount(count($paths), $suites[$themename]['paths']);
|
|
|
433 |
|
|
|
434 |
foreach ($paths as $key => $feature) {
|
|
|
435 |
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
|
|
|
436 |
}
|
|
|
437 |
}
|
|
|
438 |
// Check contexts.
|
|
|
439 |
foreach ($this->contextspath as $themename => $paths) {
|
|
|
440 |
$this->assertCount(count($paths), $suites[$themename]['contexts']);
|
|
|
441 |
|
|
|
442 |
foreach ($paths as $key => $context) {
|
|
|
443 |
$this->assertTrue(in_array($context, $suites[$themename]['contexts']));
|
|
|
444 |
}
|
|
|
445 |
}
|
|
|
446 |
// There are 7 step definitions.
|
|
|
447 |
$this->assertCount(7, $config['default']['extensions']['Moodle\BehatExtension']['steps_definitions']);
|
|
|
448 |
}
|
|
|
449 |
|
|
|
450 |
/**
|
|
|
451 |
* Test if clean features key and path is returned.
|
|
|
452 |
* @dataProvider clean_features_path_list
|
|
|
453 |
*/
|
|
|
454 |
public function test_get_clean_feature_key_and_path($featurepath, $key, $cleanfeaturepath) {
|
|
|
455 |
global $CFG;
|
|
|
456 |
|
|
|
457 |
// This is a hack so directory name is correctly detected in tests.
|
|
|
458 |
//FIXME: MDL-55722 work out why this is necessary..
|
|
|
459 |
$oldroot = $CFG->dirroot;
|
|
|
460 |
$CFG->dirroot = 'C:';
|
|
|
461 |
|
|
|
462 |
$behatconfigutil = new behat_config_util();
|
|
|
463 |
|
|
|
464 |
// Fix expected directory path for OS.
|
|
|
465 |
$cleanfeaturepath = testing_cli_fix_directory_separator($cleanfeaturepath);
|
|
|
466 |
|
|
|
467 |
list($retkey, $retcleanfeaturepath) = $behatconfigutil->get_clean_feature_key_and_path($featurepath);
|
|
|
468 |
|
|
|
469 |
$this->assertEquals($key, $retkey);
|
|
|
470 |
$this->assertEquals($cleanfeaturepath, $retcleanfeaturepath);
|
|
|
471 |
//FIXME: MDL-55722 work out why this is necessary..
|
|
|
472 |
$CFG->dirroot = $oldroot;
|
|
|
473 |
}
|
|
|
474 |
|
|
|
475 |
public function clean_features_path_list() {
|
|
|
476 |
return array(
|
|
|
477 |
['/home/test/this/that/test/behat/mod_assign.feature', 'mod_assign_behat_test_that_this_test', '/home/test/this/that/test/behat/mod_assign.feature'],
|
|
|
478 |
['/home/this/that/test/behat/mod_assign.feature', 'mod_assign_behat_test_that_this_home', '/home/this/that/test/behat/mod_assign.feature'],
|
|
|
479 |
['/home/that/test/behat/mod_assign.feature', 'mod_assign_behat_test_that_home', '/home/that/test/behat/mod_assign.feature'],
|
|
|
480 |
['/home/test/behat/mod_assign.feature', 'mod_assign_behat_test_home', '/home/test/behat/mod_assign.feature'],
|
|
|
481 |
['mod_assign.feature', 'mod_assign', 'mod_assign.feature'],
|
|
|
482 |
['C:\test\this\that\test\behat\mod_assign.feature', 'mod_assign_behat_test_that_this_test', 'C:\test\this\that\test\behat\mod_assign.feature'],
|
|
|
483 |
['C:\this\that\test\behat\mod_assign.feature', 'mod_assign_behat_test_that_this', 'C:\this\that\test\behat\mod_assign.feature'],
|
|
|
484 |
['C:\that\test\behat\mod_assign.feature', 'mod_assign_behat_test_that', 'C:\that\test\behat\mod_assign.feature'],
|
|
|
485 |
['C:\test\behat\mod_assign.feature', 'mod_assign_behat_test', 'C:\test\behat\mod_assign.feature'],
|
|
|
486 |
['C:\mod_assign.feature', 'mod_assign', 'C:\mod_assign.feature'],
|
|
|
487 |
);
|
|
|
488 |
}
|
|
|
489 |
|
|
|
490 |
/**
|
|
|
491 |
* Behat config for blacklisted tags.
|
|
|
492 |
*/
|
|
|
493 |
public function test_get_config_file_contents_with_blacklisted_tags() {
|
|
|
494 |
|
|
|
495 |
$mockbuilder = $this->getMockBuilder('behat_config_util');
|
|
|
496 |
$mockbuilder->onlyMethods(array('get_theme_test_directory', 'get_list_of_themes', 'get_blacklisted_tests_for_theme',
|
|
|
497 |
'get_default_theme', 'get_theme_config'));
|
|
|
498 |
|
|
|
499 |
$behatconfigutil = $mockbuilder->getMock();
|
|
|
500 |
|
|
|
501 |
$behatconfigutil = $this->get_behat_config_util($behatconfigutil);
|
|
|
502 |
|
|
|
503 |
// Blacklisted tags.
|
|
|
504 |
$map = array(
|
|
|
505 |
array('withfeatures', 'tags', array('@test1')),
|
|
|
506 |
array('nofeatures', 'tags', array('@test2')),
|
|
|
507 |
array('defaulttheme', 'tags', array()),
|
|
|
508 |
array('withfeatures', 'features', array()),
|
|
|
509 |
array('nofeatures', 'features', array()),
|
|
|
510 |
array('defaulttheme', 'features', array()),
|
|
|
511 |
array('withfeatures', 'contexts', array()),
|
|
|
512 |
array('nofeatures', 'contexts', array()),
|
|
|
513 |
array('defaulttheme', 'contexts', array())
|
|
|
514 |
);
|
|
|
515 |
|
|
|
516 |
$behatconfigutil->expects($this->any())
|
|
|
517 |
->method('get_blacklisted_tests_for_theme')
|
|
|
518 |
->will($this->returnValueMap($map));
|
|
|
519 |
|
|
|
520 |
$behatconfigutil->set_theme_suite_to_include_core_features(true);
|
|
|
521 |
$config = $behatconfigutil->get_config_file_contents($this->corefeatures, $this->corecontexts);
|
|
|
522 |
|
|
|
523 |
// Three suites should be present.
|
|
|
524 |
$suites = $config['default']['suites'];
|
|
|
525 |
$this->assertCount(3, $suites);
|
|
|
526 |
|
|
|
527 |
$featurepaths = array(
|
|
|
528 |
'default' => array('test_1.feature', 'test_2.feature'),
|
|
|
529 |
'withfeatures' => array('test_2.feature', 'theme_test_1.feature', 'theme_test_2.feature', 'theme_test_3.feature',
|
|
|
530 |
'theme_test_4.feature', 'theme_test_5.feature'),
|
|
|
531 |
'nofeatures' => array('test_1.feature')
|
|
|
532 |
);
|
|
|
533 |
|
|
|
534 |
// Check features.
|
|
|
535 |
foreach ($featurepaths as $themename => $paths) {
|
|
|
536 |
$this->assertCount(count($paths), $suites[$themename]['paths']);
|
|
|
537 |
|
|
|
538 |
foreach ($paths as $key => $feature) {
|
|
|
539 |
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
|
|
|
540 |
}
|
|
|
541 |
}
|
|
|
542 |
// Check contexts.
|
|
|
543 |
foreach ($this->contextspath as $themename => $paths) {
|
|
|
544 |
$this->assertCount(count($paths), $suites[$themename]['contexts']);
|
|
|
545 |
|
|
|
546 |
foreach ($paths as $key => $context) {
|
|
|
547 |
$this->assertTrue(in_array($context, $suites[$themename]['contexts']));
|
|
|
548 |
}
|
|
|
549 |
}
|
|
|
550 |
// There are 7 step definitions.
|
|
|
551 |
$this->assertCount(7, $config['default']['extensions']['Moodle\BehatExtension']['steps_definitions']);
|
|
|
552 |
}
|
|
|
553 |
|
|
|
554 |
/**
|
|
|
555 |
* Behat config for blacklisted features.
|
|
|
556 |
*/
|
|
|
557 |
public function test_get_config_file_contents_with_blacklisted_features_contexts() {
|
|
|
558 |
|
|
|
559 |
$mockbuilder = $this->getMockBuilder('behat_config_util');
|
|
|
560 |
$mockbuilder->onlyMethods(array('get_theme_test_directory', 'get_list_of_themes', 'get_blacklisted_tests_for_theme',
|
|
|
561 |
'get_default_theme', 'get_theme_config'));
|
|
|
562 |
|
|
|
563 |
$behatconfigutil = $mockbuilder->getMock();
|
|
|
564 |
|
|
|
565 |
$behatconfigutil = $this->get_behat_config_util($behatconfigutil);
|
|
|
566 |
|
|
|
567 |
// Blacklisted features and contexts.
|
|
|
568 |
$map = array(
|
|
|
569 |
array('withfeatures', 'tags', array()),
|
|
|
570 |
array('nofeatures', 'tags', array()),
|
|
|
571 |
array('defaulttheme', 'tags', array()),
|
|
|
572 |
array('withfeatures', 'features', array('admin/tool/behat/tests/fixtures/core/test_1.feature')),
|
|
|
573 |
array('nofeatures', 'features', array('admin/tool/behat/tests/fixtures/core/test_2.feature')),
|
|
|
574 |
array('defaulttheme', 'features', array()),
|
|
|
575 |
array('withfeatures', 'contexts', array('admin/tool/behat/tests/fixtures/core/behat_test_context_2.php')),
|
|
|
576 |
array('nofeatures', 'contexts', array('admin/tool/behat/tests/fixtures/core/behat_test_context_1.php')),
|
|
|
577 |
array('defaulttheme', 'contexts', array()),
|
|
|
578 |
);
|
|
|
579 |
|
|
|
580 |
$behatconfigutil->expects($this->any())
|
|
|
581 |
->method('get_blacklisted_tests_for_theme')
|
|
|
582 |
->will($this->returnValueMap($map));
|
|
|
583 |
|
|
|
584 |
$behatconfigutil->set_theme_suite_to_include_core_features(true);
|
|
|
585 |
$config = $behatconfigutil->get_config_file_contents($this->corefeatures, $this->corecontexts);
|
|
|
586 |
|
|
|
587 |
// Three suites should be present.
|
|
|
588 |
$suites = $config['default']['suites'];
|
|
|
589 |
$this->assertCount(3, $suites);
|
|
|
590 |
|
|
|
591 |
$featurepaths = array(
|
|
|
592 |
'default' => array('test_1.feature', 'test_2.feature'),
|
|
|
593 |
'withfeatures' => array('test_2.feature', 'theme_test_1.feature', 'theme_test_2.feature', 'theme_test_3.feature',
|
|
|
594 |
'theme_test_4.feature', 'theme_test_5.feature'),
|
|
|
595 |
'nofeatures' => array('test_1.feature')
|
|
|
596 |
);
|
|
|
597 |
$contextspath = array(
|
|
|
598 |
'default' => array(
|
|
|
599 |
'behat_test_context_1',
|
|
|
600 |
'behat_test_context_2',
|
|
|
601 |
'behat_theme_defaulttheme_test_context_1',
|
|
|
602 |
),
|
|
|
603 |
'withfeatures' => array(
|
|
|
604 |
'behat_theme_withfeatures_test_context_2',
|
|
|
605 |
'behat_theme_withfeatures_behat_test_context_1'
|
|
|
606 |
),
|
|
|
607 |
'nofeatures' => array(
|
|
|
608 |
'behat_theme_nofeatures_test_context_1',
|
|
|
609 |
'behat_theme_nofeatures_behat_test_context_2'
|
|
|
610 |
),
|
|
|
611 |
);
|
|
|
612 |
|
|
|
613 |
// Check features.
|
|
|
614 |
foreach ($featurepaths as $themename => $paths) {
|
|
|
615 |
$this->assertCount(count($paths), $suites[$themename]['paths']);
|
|
|
616 |
|
|
|
617 |
foreach ($paths as $key => $feature) {
|
|
|
618 |
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
|
|
|
619 |
}
|
|
|
620 |
}
|
|
|
621 |
// Check contexts.
|
|
|
622 |
foreach ($contextspath as $themename => $paths) {
|
|
|
623 |
$this->assertCount(count($paths), $suites[$themename]['contexts']);
|
|
|
624 |
|
|
|
625 |
foreach ($paths as $key => $context) {
|
|
|
626 |
$this->assertTrue(in_array($context, $suites[$themename]['contexts']));
|
|
|
627 |
}
|
|
|
628 |
}
|
|
|
629 |
// There are 7 step definitions.
|
|
|
630 |
$this->assertCount(7, $config['default']['extensions']['Moodle\BehatExtension']['steps_definitions']);
|
|
|
631 |
}
|
|
|
632 |
|
|
|
633 |
/**
|
|
|
634 |
* Behat config for blacklisted tags.
|
|
|
635 |
*/
|
|
|
636 |
public function test_core_features_to_include_in_specified_theme() {
|
|
|
637 |
|
|
|
638 |
$mockbuilder = $this->getMockBuilder('behat_config_util');
|
|
|
639 |
$mockbuilder->onlyMethods(array('get_theme_test_directory', 'get_list_of_themes', 'get_default_theme', 'get_theme_config'));
|
|
|
640 |
|
|
|
641 |
$behatconfigutil = $mockbuilder->getMock();
|
|
|
642 |
|
|
|
643 |
$behatconfigutil = $this->get_behat_config_util($behatconfigutil);
|
|
|
644 |
|
|
|
645 |
// Check features when, no theme is specified.
|
|
|
646 |
$behatconfigutil->set_theme_suite_to_include_core_features('');
|
|
|
647 |
$config = $behatconfigutil->get_config_file_contents($this->corefeatures, $this->corecontexts);
|
|
|
648 |
$suites = $config['default']['suites'];
|
|
|
649 |
foreach ($this->featurepaths as $themename => $paths) {
|
|
|
650 |
$this->assertCount(count($paths), $suites[$themename]['paths']);
|
|
|
651 |
|
|
|
652 |
foreach ($paths as $key => $feature) {
|
|
|
653 |
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
|
|
|
654 |
}
|
|
|
655 |
}
|
|
|
656 |
|
|
|
657 |
// Check features when all themes are specified.
|
|
|
658 |
$featurepaths = $this->featurepaths;
|
|
|
659 |
$featurepaths['withfeatures'] = array_merge ($featurepaths['default'], $featurepaths['withfeatures']);
|
|
|
660 |
$featurepaths['nofeatures'] = array_merge ($featurepaths['default'], $featurepaths['nofeatures']);
|
|
|
661 |
|
|
|
662 |
$behatconfigutil->set_theme_suite_to_include_core_features('ALL');
|
|
|
663 |
$config = $behatconfigutil->get_config_file_contents($this->corefeatures, $this->corecontexts);
|
|
|
664 |
$suites = $config['default']['suites'];
|
|
|
665 |
foreach ($featurepaths as $themename => $paths) {
|
|
|
666 |
$this->assertCount(count($paths), $suites[$themename]['paths']);
|
|
|
667 |
|
|
|
668 |
foreach ($paths as $key => $feature) {
|
|
|
669 |
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
|
|
|
670 |
}
|
|
|
671 |
}
|
|
|
672 |
|
|
|
673 |
// Check features when all themes are specified.
|
|
|
674 |
$featurepaths = $this->featurepaths;
|
|
|
675 |
$featurepaths['withfeatures'] = array_merge ($featurepaths['default'], $featurepaths['withfeatures']);
|
|
|
676 |
$featurepaths['nofeatures'] = array_merge ($featurepaths['default'], $featurepaths['nofeatures']);
|
|
|
677 |
|
|
|
678 |
$behatconfigutil->set_theme_suite_to_include_core_features('withfeatures, nofeatures');
|
|
|
679 |
$config = $behatconfigutil->get_config_file_contents($this->corefeatures, $this->corecontexts);
|
|
|
680 |
$suites = $config['default']['suites'];
|
|
|
681 |
foreach ($featurepaths as $themename => $paths) {
|
|
|
682 |
$this->assertCount(count($paths), $suites[$themename]['paths']);
|
|
|
683 |
|
|
|
684 |
foreach ($paths as $key => $feature) {
|
|
|
685 |
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
|
|
|
686 |
}
|
|
|
687 |
}
|
|
|
688 |
|
|
|
689 |
// Check features when specified themes are passed..
|
|
|
690 |
$featurepaths = $this->featurepaths;
|
|
|
691 |
$featurepaths['nofeatures'] = array_merge ($featurepaths['default'], $featurepaths['nofeatures']);
|
|
|
692 |
|
|
|
693 |
$behatconfigutil->set_theme_suite_to_include_core_features('nofeatures');
|
|
|
694 |
$config = $behatconfigutil->get_config_file_contents($this->corefeatures, $this->corecontexts);
|
|
|
695 |
$suites = $config['default']['suites'];
|
|
|
696 |
foreach ($featurepaths as $themename => $paths) {
|
|
|
697 |
$this->assertCount(count($paths), $suites[$themename]['paths']);
|
|
|
698 |
|
|
|
699 |
foreach ($paths as $key => $feature) {
|
|
|
700 |
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
|
|
|
701 |
}
|
|
|
702 |
}
|
|
|
703 |
}
|
|
|
704 |
}
|
|
|
705 |
// @codeCoverageIgnoreEnd
|