Skip to content

Commit 4da2ed8

Browse files
committed
fixup! MDL-70854 core: Add javascript & external service for stored progress bars.
1 parent 593fa7b commit 4da2ed8

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
namespace core\external;
17+
18+
/**
19+
* Unit tests for poll_stored_progress
20+
*
21+
* @package core
22+
* @copyright 2024 onwards Catalyst IT EU {@link https://catalyst-eu.net}
23+
* @author Mark Johnson <[email protected]>
24+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25+
* @covers core\external\poll_stored_progress
26+
*/
27+
class test_poll_stored_progress extends \advanced_testcase {
28+
/**
29+
* Throw an exception if the wrong data type is passed for an ID.
30+
*/
31+
public function test_execute_invalid_id(): void {
32+
$debuginfo = 'Invalid external api parameter: the value is "foo", the server was expecting "int" type';
33+
$pollstoredprogress = new poll_stored_progress();
34+
$this->expectExceptionObject(new \invalid_parameter_exception($debuginfo));
35+
$pollstoredprogress->execute(['foo']);
36+
}
37+
38+
/**
39+
* Passing a list of IDs returns a corresponding list of records.
40+
*/
41+
public function test_execute(): void {
42+
$this->resetAfterTest();
43+
$generator = $this->getDataGenerator();
44+
$progress1 = $generator->create_stored_progress();
45+
$progress2 = $generator->create_stored_progress();
46+
$falseid = $progress2->id + 1;
47+
48+
$ids = [
49+
$progress1->id,
50+
$progress2->id,
51+
$falseid,
52+
];
53+
54+
$pollstoredprogress = new poll_stored_progress();
55+
$result = $pollstoredprogress->execute($ids);
56+
57+
$this->assertEquals($progress1->id, $result[$progress1->id]['id']);
58+
$this->assertEquals($progress1->idnumber, $result[$progress1->id]['uniqueid']);
59+
$this->assertEquals($progress2->id, $result[$progress2->id]['id']);
60+
$this->assertEquals($progress2->idnumber, $result[$progress2->id]['uniqueid']);
61+
$this->assertEquals($falseid, $result[$falseid]['id']);
62+
$this->assertEmpty($result[$falseid]['uniqueid']); // Empty when no matching record is found.
63+
}
64+
}

0 commit comments

Comments
 (0)