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+         $ pollstoredprogressnew  poll_stored_progress ();
34+         $ this expectExceptionObject (new  \invalid_parameter_exception ($ debuginfo
35+         $ pollstoredprogressexecute (['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$ generatorcreate_stored_progress ();
45+         $ progress2$ generatorcreate_stored_progress ();
46+         $ falseid$ progress2id  + 1 ;
47+ 
48+         $ ids
49+             $ progress1id ,
50+             $ progress2id ,
51+             $ falseid
52+         ];
53+ 
54+         $ pollstoredprogressnew  poll_stored_progress ();
55+         $ result$ pollstoredprogressexecute ($ ids
56+ 
57+         $ this assertEquals ($ progress1id , $ result$ progress1id ]['id ' ]);
58+         $ this assertEquals ($ progress1idnumber , $ result$ progress1id ]['uniqueid ' ]);
59+         $ this assertEquals ($ progress2id , $ result$ progress2id ]['id ' ]);
60+         $ this assertEquals ($ progress2idnumber , $ result$ progress2id ]['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