Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 28... Línea 28...
28
 * @package tool_generator
28
 * @package tool_generator
29
 * @copyright 2023 Ferran Recio <ferran@moodel.com>
29
 * @copyright 2023 Ferran Recio <ferran@moodel.com>
30
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31
 * @coversDefaultClass \tool_generator\local\testscenario\steprunner
31
 * @coversDefaultClass \tool_generator\local\testscenario\steprunner
32
 */
32
 */
33
class steprunner_test extends \advanced_testcase {
33
final class steprunner_test extends \advanced_testcase {
34
    public static function setUpBeforeClass(): void {
34
    public static function setUpBeforeClass(): void {
-
 
35
        parent::setUpBeforeClass();
35
        // Call the init method to include all behat libraries and attributes.
36
        // Call the init method to include all behat libraries and attributes.
36
        $runner = new runner();
37
        $runner = new runner();
37
        $runner->init();
38
        $runner->init();
38
    }
39
    }
Línea 56... Línea 57...
56
        $steps = $scenario->getSteps();
57
        $steps = $scenario->getSteps();
57
        return $steps[0];
58
        return $steps[0];
58
    }
59
    }
Línea 59... Línea 60...
59
 
60
 
-
 
61
    /**
-
 
62
     * Get the list of valid behat steps for the tests.
-
 
63
     * @return array the valid steps details.
-
 
64
     */
-
 
65
    private function get_valid_steps(): array {
-
 
66
        $generator = new behat_data_generators();
-
 
67
        return [
-
 
68
            '/^the following "(?P<element_string>(?:[^"]|\\")*)" exist:$/' => (object) [
-
 
69
                'name' => 'the_following_entities_exist',
-
 
70
                'given' => '/^the following "(?P<element_string>(?:[^"]|\\")*)" exist:$/',
-
 
71
                'generator' => $generator,
-
 
72
            ],
-
 
73
            ':count :entitytype exist with the following data:' => (object) [
-
 
74
                'name' => 'the_following_repeated_entities_exist',
-
 
75
                'given' => ':count :entitytype exist with the following data:',
-
 
76
                'generator' => $generator,
-
 
77
            ],
-
 
78
            'the following :entitytype exists:' => (object) [
-
 
79
                'name' => 'the_following_entity_exists',
-
 
80
                'given' => 'the following :entitytype exists:',
-
 
81
                'generator' => $generator,
-
 
82
            ],
-
 
83
        ];
-
 
84
    }
-
 
85
 
60
    /**
86
    /**
61
     * Test for parse_feature.
87
     * Test for parse_feature.
62
     * @covers ::is_valid
88
     * @covers ::is_valid
63
     * @param string $step the step to validate.
89
     * @param string $step the step to validate.
64
     * @param bool $expected if the step is expected to be valid.
90
     * @param bool $expected if the step is expected to be valid.
65
     * @dataProvider execute_steps_provider
91
     * @dataProvider execute_steps_provider
66
     */
92
     */
67
    public function test_is_valid(string $step, bool $expected): void {
93
    public function test_is_valid(string $step, bool $expected): void {
68
        $generator = new behat_data_generators();
-
 
69
        $validsteps = [
-
 
70
            '/^the following "(?P<element_string>(?:[^"]|\\")*)" exist:$/' => 'the_following_entities_exist',
-
 
71
            ':count :entitytype exist with the following data:' => 'the_following_repeated_entities_exist',
-
 
72
            'the following :entitytype exists:' => 'the_following_entity_exists',
-
 
73
        ];
-
 
74
 
94
        $validsteps = $this->get_valid_steps();
75
        $step = $this->get_step($step);
95
        $step = $this->get_step($step);
76
        $steprunner = new steprunner($generator, $validsteps, $step);
96
        $steprunner = new steprunner(null, $validsteps, $step);
77
        $this->assertEquals($expected, $steprunner->is_valid());
97
        $this->assertEquals($expected, $steprunner->is_valid());
Línea 78... Línea 98...
78
    }
98
    }
79
 
99
 
Línea 89... Línea 109...
89
    public function test_execute(string $step, bool $expected): void {
109
    public function test_execute(string $step, bool $expected): void {
90
        global $DB;
110
        global $DB;
Línea 91... Línea 111...
91
 
111
 
Línea 92... Línea 112...
92
        $this->resetAfterTest();
112
        $this->resetAfterTest();
93
 
-
 
94
        $generator = new behat_data_generators();
-
 
95
        $validsteps = [
-
 
96
            '/^the following "(?P<element_string>(?:[^"]|\\")*)" exist:$/' => 'the_following_entities_exist',
-
 
97
            ':count :entitytype exist with the following data:' => 'the_following_repeated_entities_exist',
-
 
Línea 98... Línea 113...
98
            'the following :entitytype exists:' => 'the_following_entity_exists',
113
 
99
        ];
114
        $validsteps = $this->get_valid_steps();
Línea 100... Línea 115...
100
 
115
 
Línea 101... Línea 116...
101
        $step = $this->get_step($step);
116
        $step = $this->get_step($step);
Línea 160... Línea 175...
160
    public function test_execute_duplicated(): void {
175
    public function test_execute_duplicated(): void {
161
        global $DB;
176
        global $DB;
Línea 162... Línea 177...
162
 
177
 
Línea 163... Línea 178...
163
        $this->resetAfterTest();
178
        $this->resetAfterTest();
164
 
-
 
165
        $generator = new behat_data_generators();
-
 
166
        $validsteps = [
-
 
167
            '/^the following "(?P<element_string>(?:[^"]|\\")*)" exist:$/' => 'the_following_entities_exist',
-
 
168
            ':count :entitytype exist with the following data:' => 'the_following_repeated_entities_exist',
-
 
Línea 169... Línea 179...
169
            'the following :entitytype exists:' => 'the_following_entity_exists',
179
 
170
        ];
180
        $validsteps = $this->get_valid_steps();
171
 
181
 
172
        $step = $this->get_step('Given the following "course" exists:
182
        $step = $this->get_step('Given the following "course" exists:
173
            | fullname         | Course test |
183
            | fullname         | Course test |
Línea 174... Línea 184...
174
            | shortname        | C1          |
184
            | shortname        | C1          |
Línea 175... Línea 185...
175
            | category         | 0           |');
185
            | category         | 0           |');
Línea 188... Línea 198...
188
            1,
198
            1,
189
            $DB->count_records('course', ['shortname' => 'C1'])
199
            $DB->count_records('course', ['shortname' => 'C1'])
190
        );
200
        );
Línea 191... Línea 201...
191
 
201
 
192
        // Execute the same course creation.
202
        // Execute the same course creation.
193
        $steprunner = new steprunner($generator, $validsteps, $step);
203
        $steprunner = new steprunner(null, $validsteps, $step);
194
        $this->assertFalse($steprunner->is_executed());
204
        $this->assertFalse($steprunner->is_executed());
195
        $result = $steprunner->execute();
205
        $result = $steprunner->execute();
196
        $this->assertFalse($result);
206
        $this->assertFalse($result);
197
        $this->assertTrue($steprunner->is_executed());
207
        $this->assertTrue($steprunner->is_executed());
Línea 202... Línea 212...
202
     * Test for parse_feature.
212
     * Test for parse_feature.
203
     * @covers ::get_text
213
     * @covers ::get_text
204
     * @covers ::get_arguments_string
214
     * @covers ::get_arguments_string
205
     */
215
     */
206
    public function test_get_step_content(): void {
216
    public function test_get_step_content(): void {
207
        $generator = new behat_data_generators();
-
 
208
        $validsteps = [
-
 
209
            '/^the following "(?P<element_string>(?:[^"]|\\")*)" exist:$/' => 'the_following_entities_exist',
-
 
210
            ':count :entitytype exist with the following data:' => 'the_following_repeated_entities_exist',
-
 
211
            'the following :entitytype exists:' => 'the_following_entity_exists',
-
 
212
        ];
-
 
213
 
-
 
214
        $step = $this->get_step('Given the following "course" exists:
217
        $step = $this->get_step('Given the following "course" exists:
215
            | fullname    | Course test |
218
        | fullname    | Course test |
216
            | shortname   | C1          |
219
        | shortname   | C1          |
217
            | category    | 0           |
220
        | category    | 0           |
218
            | numsections | 3           |');
221
        | numsections | 3           |');
-
 
222
 
-
 
223
        $validsteps = $this->get_valid_steps();
219
        $steprunner = new steprunner($generator, $validsteps, $step);
224
        $steprunner = new steprunner(null, $validsteps, $step);
Línea 220... Línea 225...
220
 
225
 
221
        $this->assertEquals(
226
        $this->assertEquals(
222
            'the following "course" exists:',
227
            'the following "course" exists:',
223
            $steprunner->get_text()
228
            $steprunner->get_text()