Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 40... Línea 40...
40
 *
40
 *
41
 * @package    mod_h5pactivity
41
 * @package    mod_h5pactivity
42
 * @copyright  2020 Ilya Tregubov <ilya@moodle.com>
42
 * @copyright  2020 Ilya Tregubov <ilya@moodle.com>
43
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
43
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
44
 */
44
 */
45
class get_user_attempts_test extends externallib_advanced_testcase {
45
final class get_user_attempts_test extends externallib_advanced_testcase {
Línea 46... Línea 46...
46
 
46
 
47
    /**
47
    /**
48
     * Test the behaviour of get_user_attempts getting more than one user at once.
48
     * Test the behaviour of get_user_attempts getting more than one user at once.
49
     *
49
     *
Línea 78... Línea 78...
78
 
78
 
79
        // Generate attempts (student1 with 1 attempt, student2 with 2 etc).
79
        // Generate attempts (student1 with 1 attempt, student2 with 2 etc).
Línea 80... Línea 80...
80
        $generator = $this->getDataGenerator()->get_plugin_generator('mod_h5pactivity');
80
        $generator = $this->getDataGenerator()->get_plugin_generator('mod_h5pactivity');
-
 
81
 
81
 
82
        $attemptcount = 1;
82
        $attemptcount = 1;
83
        $totalattempts = 0;
83
        foreach ($users as $key => $user) {
84
        foreach ($users as $key => $user) {
84
            if (($key == 'noattempts') || ($key == 'noenrolled') || ($key == 'editingteacher')) {
85
            if (($key == 'noattempts') || ($key == 'noenrolled') || ($key == 'editingteacher')) {
85
                $countattempts[$user->id] = 0;
86
                $countattempts[$user->id] = 0;
86
            } else {
87
            } else {
87
                $params = ['cmid' => $cm->id, 'userid' => $user->id];
88
                $params = ['cmid' => $cm->id, 'userid' => $user->id];
-
 
89
                for ($i = 1; $i <= $attemptcount; $i++) {
88
                for ($i = 1; $i <= $attemptcount; $i++) {
90
                    $generator->create_content($activity, $params);
89
                    $generator->create_content($activity, $params);
91
                    $totalattempts++;
90
                }
92
                }
91
                $countattempts[$user->id] = $attemptcount;
93
                $countattempts[$user->id] = $attemptcount;
92
                $attemptcount++;
94
                $attemptcount++;
Línea 105... Línea 107...
105
        $result = external_api::clean_returnvalue(
107
        $result = external_api::clean_returnvalue(
106
            get_user_attempts::execute_returns(),
108
            get_user_attempts::execute_returns(),
107
            $result
109
            $result
108
        );
110
        );
Línea -... Línea 111...
-
 
111
 
109
 
112
        $this->assertEquals($totalattempts, $result['totalattempts']);
110
        $this->assertCount(count($warnings), $result['warnings']);
113
        $this->assertCount(count($warnings), $result['warnings']);
111
        // Teacher is excluded.
114
        // Teacher is excluded.
Línea 112... Línea 115...
112
        $this->assertCount(count($resultusers), $result['usersattempts']);
115
        $this->assertCount(count($resultusers), $result['usersattempts']);
Línea 143... Línea 146...
143
    /**
146
    /**
144
     * Data provider for the test_execute_multipleusers.
147
     * Data provider for the test_execute_multipleusers.
145
     *
148
     *
146
     * @return  array
149
     * @return  array
147
     */
150
     */
148
    public function execute_multipleusers_data(): array {
151
    public static function execute_multipleusers_data(): array {
149
        return [
152
        return [
150
            // Teacher checks.
153
            // Teacher checks.
151
            'Teacher checking students with attempts' => [
154
            'Teacher checking students with attempts' => [
152
                'editingteacher',
155
                'editingteacher',
153
                ['student1', 'student2', 'student3', 'student4', 'student5'],
156
                ['student1', 'student2', 'student3', 'student4', 'student5'],
Línea 186... Línea 189...
186
    /**
189
    /**
187
     * Data provider for {@see test_execute_with_sortorder}
190
     * Data provider for {@see test_execute_with_sortorder}
188
     *
191
     *
189
     * @return array[]
192
     * @return array[]
190
     */
193
     */
191
    public function execute_with_sortorder(): array {
194
    public static function execute_with_sortorder(): array {
192
        return [
195
        return [
193
            'Sort by id' => ['id', ['user01', 'user02']],
196
            'Sort by id' => ['id', ['user01', 'user02']],
194
            'Sort by id desc' => ['id desc', ['user02', 'user01']],
197
            'Sort by id desc' => ['id desc', ['user02', 'user01']],
195
            'Sort by id asc' => ['id asc', ['user01', 'user02']],
198
            'Sort by id asc' => ['id asc', ['user01', 'user02']],
196
            'Sort by firstname' => ['firstname', ['user01', 'user02']],
199
            'Sort by firstname' => ['firstname', ['user01', 'user02']],