Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 24... Línea 24...
24
 * @package    mod_h5pactivity
24
 * @package    mod_h5pactivity
25
 * @category   test
25
 * @category   test
26
 * @copyright  2020 Ferran Recio <ferran@moodle.com>
26
 * @copyright  2020 Ferran Recio <ferran@moodle.com>
27
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28
 */
28
 */
29
class generator_test extends \advanced_testcase {
29
final class generator_test extends \advanced_testcase {
Línea 30... Línea 30...
30
 
30
 
31
    /**
31
    /**
32
     * Test on H5P activity creation.
32
     * Test on H5P activity creation.
33
     */
33
     */
34
    public function test_create_instance() {
34
    public function test_create_instance(): void {
35
        global $DB, $CFG, $USER;
35
        global $DB, $CFG, $USER;
36
        $this->resetAfterTest();
36
        $this->resetAfterTest();
Línea 37... Línea 37...
37
        $this->setAdminUser();
37
        $this->setAdminUser();
Línea 85... Línea 85...
85
 
85
 
86
    /**
86
    /**
87
     * Test that a new H5P activity cannot be generated without a valid file
87
     * Test that a new H5P activity cannot be generated without a valid file
88
     * other user.
88
     * other user.
89
     */
89
     */
90
    public function test_create_file_exception() {
90
    public function test_create_file_exception(): void {
91
        global $CFG;
91
        global $CFG;
92
        $this->resetAfterTest();
92
        $this->resetAfterTest();
Línea 93... Línea 93...
93
        $this->setAdminUser();
93
        $this->setAdminUser();
Línea 112... Línea 112...
112
     * @param int $attempts the final registered attempts
112
     * @param int $attempts the final registered attempts
113
     * @param int $results the final registered attempts results
113
     * @param int $results the final registered attempts results
114
     * @param bool $exception if an exception is expected
114
     * @param bool $exception if an exception is expected
115
     *
115
     *
116
     */
116
     */
117
    public function test_create_attempt(array $tracks, int $attempts, int $results, bool $exception) {
117
    public function test_create_attempt(array $tracks, int $attempts, int $results, bool $exception): void {
118
        global $DB;
118
        global $DB;
119
        $this->resetAfterTest();
119
        $this->resetAfterTest();
120
        $this->setAdminUser();
120
        $this->setAdminUser();
Línea 121... Línea 121...
121
 
121
 
Línea 156... Línea 156...
156
    /**
156
    /**
157
     * Data provider for create attempt test.
157
     * Data provider for create attempt test.
158
     *
158
     *
159
     * @return array
159
     * @return array
160
     */
160
     */
161
    public function create_attempt_data(): array {
161
    public static function create_attempt_data(): array {
162
        return [
162
        return [
163
            'Compound statement' => [
163
            'Compound statement' => [
164
                [
164
                [
165
                    [
165
                    [
166
                        'interactiontype' => 'compound', 'attempt' => 1, 'rawscore' => 2,
166
                        'interactiontype' => 'compound', 'attempt' => 1, 'rawscore' => 2,
Línea 222... Línea 222...
222
                        'interactiontype' => 'other', 'attempt' => 1, 'rawscore' => 2,
222
                        'interactiontype' => 'other', 'attempt' => 1, 'rawscore' => 2,
223
                        'maxscore' => 2, 'duration' => 1, 'completion' => 1, 'success' => 0
223
                        'maxscore' => 2, 'duration' => 1, 'completion' => 1, 'success' => 0
224
                    ],
224
                    ],
225
                ], 1, 1, false,
225
                ], 1, 1, false,
226
            ],
226
            ],
227
            'Other statement' => [
-
 
228
                [
-
 
229
                    [
-
 
230
                        'interactiontype' => 'other', 'attempt' => 1, 'rawscore' => 2,
-
 
231
                        'maxscore' => 2, 'duration' => 1, 'completion' => 1, 'success' => 0
-
 
232
                    ],
-
 
233
                ], 1, 1, false,
-
 
234
            ],
-
 
235
            'No graded statement' => [
227
            'No graded statement' => [
236
                [
228
                [
237
                    [
229
                    [
238
                        'interactiontype' => 'other', 'attempt' => 1, 'rawscore' => 0,
230
                        'interactiontype' => 'other', 'attempt' => 1, 'rawscore' => 0,
239
                        'maxscore' => 0, 'duration' => 1, 'completion' => 1, 'success' => 0
231
                        'maxscore' => 0, 'duration' => 1, 'completion' => 1, 'success' => 0
Línea 311... Línea 303...
311
     * @dataProvider create_attempt_exceptions_data
303
     * @dataProvider create_attempt_exceptions_data
312
     *
304
     *
313
     * @param bool $validmod if the activity id is provided
305
     * @param bool $validmod if the activity id is provided
314
     * @param bool $validuser if the user id is provided
306
     * @param bool $validuser if the user id is provided
315
     */
307
     */
316
    public function test_create_attempt_exceptions(bool $validmod, bool $validuser) {
308
    public function test_create_attempt_exceptions(bool $validmod, bool $validuser): void {
317
        global $DB;
309
        global $DB;
318
        $this->resetAfterTest();
310
        $this->resetAfterTest();
319
        $this->setAdminUser();
311
        $this->setAdminUser();
Línea 320... Línea 312...
320
 
312
 
Línea 349... Línea 341...
349
    /**
341
    /**
350
     * Data provider for data request creation tests.
342
     * Data provider for data request creation tests.
351
     *
343
     *
352
     * @return array
344
     * @return array
353
     */
345
     */
354
    public function create_attempt_exceptions_data(): array {
346
    public static function create_attempt_exceptions_data(): array {
355
        return [
347
        return [
356
            'Invalid user'                  => [true, false],
348
            'Invalid user'                  => [true, false],
357
            'Invalid activity'              => [false, true],
349
            'Invalid activity'              => [false, true],
358
            'Invalid user and activity'     => [false, false],
350
            'Invalid user and activity'     => [false, false],
359
        ];
351
        ];