1441 |
ariadna |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
namespace core\external\output;
|
|
|
18 |
|
|
|
19 |
/**
|
|
|
20 |
* Unit tests for poll_stored_progress
|
|
|
21 |
*
|
|
|
22 |
* @package core
|
|
|
23 |
* @copyright 2024 onwards Catalyst IT EU {@link https://catalyst-eu.net}
|
|
|
24 |
* @author Mark Johnson <mark.johnson@catalyst-eu.net>
|
|
|
25 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
26 |
* @covers \core\external\poll_stored_progress_test
|
|
|
27 |
*/
|
|
|
28 |
final class poll_stored_progress_test extends \advanced_testcase {
|
|
|
29 |
/**
|
|
|
30 |
* Throw an exception if the wrong data type is passed for an ID.
|
|
|
31 |
*/
|
|
|
32 |
public function test_execute_invalid_id(): void {
|
|
|
33 |
$debuginfo = 'Invalid external api parameter: the value is "foo", the server was expecting "int" type';
|
|
|
34 |
$pollstoredprogress = new poll_stored_progress();
|
|
|
35 |
$this->expectExceptionObject(new \invalid_parameter_exception($debuginfo));
|
|
|
36 |
$pollstoredprogress->execute(['foo']);
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
/**
|
|
|
40 |
* Passing a list of IDs returns a corresponding list of records.
|
|
|
41 |
*/
|
|
|
42 |
public function test_execute(): void {
|
|
|
43 |
$this->resetAfterTest();
|
|
|
44 |
$generator = $this->getDataGenerator();
|
|
|
45 |
$progress1 = $generator->create_stored_progress();
|
|
|
46 |
$progress2 = $generator->create_stored_progress();
|
|
|
47 |
$falseid = $progress2->id + 1;
|
|
|
48 |
|
|
|
49 |
$ids = [
|
|
|
50 |
$progress1->id,
|
|
|
51 |
$progress2->id,
|
|
|
52 |
$falseid,
|
|
|
53 |
];
|
|
|
54 |
|
|
|
55 |
$pollstoredprogress = new poll_stored_progress();
|
|
|
56 |
$result = $pollstoredprogress->execute($ids);
|
|
|
57 |
|
|
|
58 |
$this->assertEquals($progress1->id, $result[$progress1->id]['id']);
|
|
|
59 |
$this->assertEquals($progress1->idnumber, $result[$progress1->id]['uniqueid']);
|
|
|
60 |
$this->assertEquals($progress2->id, $result[$progress2->id]['id']);
|
|
|
61 |
$this->assertEquals($progress2->idnumber, $result[$progress2->id]['uniqueid']);
|
|
|
62 |
$this->assertEquals($falseid, $result[$falseid]['id']);
|
|
|
63 |
$this->assertEmpty($result[$falseid]['uniqueid']); // Empty when no matching record is found.
|
|
|
64 |
}
|
|
|
65 |
}
|