| Línea 22... |
Línea 22... |
| 22 |
* @package tool_generator
|
22 |
* @package tool_generator
|
| 23 |
* @copyright 2023 Ferran Recio <ferran@moodel.com>
|
23 |
* @copyright 2023 Ferran Recio <ferran@moodel.com>
|
| 24 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
24 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
| 25 |
* @coversDefaultClass \tool_generator\local\testscenario\runner
|
25 |
* @coversDefaultClass \tool_generator\local\testscenario\runner
|
| 26 |
*/
|
26 |
*/
|
| 27 |
class runner_test extends \advanced_testcase {
|
27 |
final class runner_test extends \advanced_testcase {
|
| Línea 28... |
Línea 28... |
| 28 |
|
28 |
|
| 29 |
/**
|
29 |
/**
|
| 30 |
* Test for parse_feature.
|
30 |
* Test for parse_feature.
|
| 31 |
* @covers ::parse_feature
|
31 |
* @covers ::parse_feature
|
| Línea 44... |
Línea 44... |
| 44 |
$featurefile = $CFG->dirroot . '/admin/tool/generator/tests/fixtures/testscenario/scenario.feature';
|
44 |
$featurefile = $CFG->dirroot . '/admin/tool/generator/tests/fixtures/testscenario/scenario.feature';
|
| 45 |
$contents = file_get_contents($featurefile);
|
45 |
$contents = file_get_contents($featurefile);
|
| 46 |
$feature = $runner->parse_feature($contents);
|
46 |
$feature = $runner->parse_feature($contents);
|
| Línea 47... |
Línea 47... |
| 47 |
|
47 |
|
| 48 |
$this->assertEquals(2, count($feature->get_scenarios()));
|
48 |
$this->assertEquals(2, count($feature->get_scenarios()));
|
| 49 |
$this->assertEquals(6, count($feature->get_all_steps()));
|
49 |
$this->assertEquals(7, count($feature->get_all_steps()));
|
| Línea 50... |
Línea 50... |
| 50 |
$this->assertTrue($feature->is_valid());
|
50 |
$this->assertTrue($feature->is_valid());
|
| 51 |
|
51 |
|
| Línea 102... |
Línea 102... |
| 102 |
|
102 |
|
| 103 |
$result = $runner->execute($feature);
|
103 |
$result = $runner->execute($feature);
|
| 104 |
$this->assertFalse($result);
|
104 |
$this->assertFalse($result);
|
| 105 |
$this->assertEquals(0, $DB->count_records('course', ['shortname' => 'C1']));
|
105 |
$this->assertEquals(0, $DB->count_records('course', ['shortname' => 'C1']));
|
| - |
|
106 |
}
|
| - |
|
107 |
|
| - |
|
108 |
/**
|
| - |
|
109 |
* Test for parse_feature.
|
| - |
|
110 |
* @covers ::parse_feature
|
| - |
|
111 |
* @covers ::execute
|
| - |
|
112 |
*/
|
| - |
|
113 |
public function test_parse_and_execute_outline_feature(): void {
|
| - |
|
114 |
global $CFG, $DB;
|
| - |
|
115 |
|
| - |
|
116 |
$this->resetAfterTest();
|
| - |
|
117 |
$this->setAdminUser();
|
| - |
|
118 |
|
| - |
|
119 |
// Call the init method to include all behat libraries and attributes.
|
| - |
|
120 |
$runner = new runner();
|
| - |
|
121 |
$runner->init();
|
| - |
|
122 |
|
| - |
|
123 |
$featurefile = $CFG->dirroot . '/admin/tool/generator/tests/fixtures/testscenario/scenario_outline.feature';
|
| - |
|
124 |
$contents = file_get_contents($featurefile);
|
| - |
|
125 |
$feature = $runner->parse_feature($contents);
|
| - |
|
126 |
|
| - |
|
127 |
$this->assertEquals(3, count($feature->get_scenarios()));
|
| - |
|
128 |
$this->assertEquals(3, count($feature->get_all_steps()));
|
| - |
|
129 |
$this->assertTrue($feature->is_valid());
|
| - |
|
130 |
|
| - |
|
131 |
$result = $runner->execute($feature);
|
| - |
|
132 |
$this->assertTrue($result);
|
| - |
|
133 |
|
| - |
|
134 |
// Validate everything is created.
|
| - |
|
135 |
$course = $DB->get_record('course', ['shortname' => 'C1']);
|
| - |
|
136 |
$this->assertEquals('C1', $course->shortname);
|
| - |
|
137 |
$this->assertEquals('Course 1', $course->fullname);
|
| - |
|
138 |
$course = $DB->get_record('course', ['shortname' => 'C2']);
|
| - |
|
139 |
$this->assertEquals('C2', $course->shortname);
|
| - |
|
140 |
$this->assertEquals('Course 2', $course->fullname);
|
| - |
|
141 |
$course = $DB->get_record('course', ['shortname' => 'C3']);
|
| - |
|
142 |
$this->assertEquals('C3', $course->shortname);
|
| - |
|
143 |
$this->assertEquals('Course 3', $course->fullname);
|
| 106 |
}
|
144 |
}
|