Proyectos de Subversion Moodle

Rev

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

Rev 11 Rev 1441
Línea 34... Línea 34...
34
use core_course\test\mock_hooks;
34
use core_course\test\mock_hooks;
Línea 35... Línea 35...
35
 
35
 
36
/**
36
/**
37
 * Functional test for class core_course_category methods invoking hooks.
37
 * Functional test for class core_course_category methods invoking hooks.
38
 */
38
 */
Línea 39... Línea 39...
39
class category_hooks_test extends \advanced_testcase {
39
final class category_hooks_test extends \advanced_testcase {
-
 
40
 
40
 
41
    protected function setUp(): void {
41
    protected function setUp(): void {
42
        parent::setUp();
42
        $this->resetAfterTest();
43
        $this->resetAfterTest();
Línea 43... Línea 44...
43
        $this->setAdminUser();
44
        $this->setAdminUser();
Línea 183... Línea 184...
183
        $category2 = \core_course_category::create(array('name' => 'Cat2', 'parent' => $category1->id));
184
        $category2 = \core_course_category::create(array('name' => 'Cat2', 'parent' => $category1->id));
Línea 184... Línea 185...
184
 
185
 
Línea 185... Línea 186...
185
        $mockcategory2 = $this->get_mock_category($category2);
186
        $mockcategory2 = $this->get_mock_category($category2);
-
 
187
 
186
 
188
        // Define get_plugins_callback_function use in the mock, it is called twice for different callback in the form.
187
        // Define get_plugins_callback_function use in the mock, it is called twice for different callback in the form.
189
        $callbackinvocations = $this->exactly(2);
-
 
190
        $mockcategory2->expects($callbackinvocations)
-
 
191
            ->method('get_plugins_callback_function')
188
        $mockcategory2->expects($this->exactly(2))
192
            ->willReturnCallback(function ($method) use ($callbackinvocations): array {
189
            ->method('get_plugins_callback_function')
193
                switch (self::getInvocationCount($callbackinvocations)) {
190
            ->withConsecutive(
194
                    case 1:
191
                [$this->equalTo('can_course_category_delete')],
195
                        $this->assertEquals('can_course_category_delete', $method);
192
                [$this->equalTo('get_course_category_contents')]
196
                        return ['tool_unittest_can_course_category_delete'];
193
            )
197
                    case 2:
-
 
198
                        $this->assertEquals('get_course_category_contents', $method);
194
            ->willReturn(
199
                        return ['tool_unittest_get_course_category_contents'];
-
 
200
                    default:
195
                ['tool_unittest_can_course_category_delete'],
201
                        $this->fail('Unexpected callback invocation');
Línea 196... Línea 202...
196
                ['tool_unittest_get_course_category_contents']
202
                }
197
            );
203
            });
198
 
204