Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 14... Línea 14...
14
// You should have received a copy of the GNU General Public License
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/>.
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
Línea 16... Línea 16...
16
 
16
 
Línea -... Línea 17...
-
 
17
namespace core_external;
-
 
18
 
17
namespace core_external;
19
use core\tests\fake_plugins_test_trait;
18
 
20
 
19
/**
21
/**
20
 * Unit tests for core_external\external_api.
22
 * Unit tests for core_external\external_api.
21
 *
23
 *
22
 * @package     core_external
24
 * @package     core_external
23
 * @category    test
25
 * @category    test
24
 * @copyright   2022 Andrew Lyons <andrew@nicols.co.uk>
26
 * @copyright   2022 Andrew Lyons <andrew@nicols.co.uk>
25
 * @license     http://www.gnu.org/copyleft/gpl.html GNU Public License
27
 * @license     http://www.gnu.org/copyleft/gpl.html GNU Public License
26
 * @covers      \core_external\external_api
28
 * @covers      \core_external\external_api
-
 
29
 */
-
 
30
final class external_api_test extends \advanced_testcase {
-
 
31
 
27
 */
32
    use fake_plugins_test_trait;
28
class external_api_test extends \advanced_testcase {
33
 
29
    /**
34
    /**
30
     * Test the validate_parameters method.
35
     * Test the validate_parameters method.
31
     *
36
     *
Línea 330... Línea 335...
330
    }
335
    }
Línea 331... Línea 336...
331
 
336
 
332
    /**
337
    /**
333
     * Test \core_external\external_api::get_context()_from_params parameter validation.
338
     * Test \core_external\external_api::get_context()_from_params parameter validation.
334
     *
339
     *
335
     * @covers \core_external\external_api::get_context
340
     * @covers \core_external\external_api::get_context_from_params
336
     */
341
     */
337
    public function test_get_context_params(): void {
342
    public function test_get_context_params(): void {
Línea 338... Línea 343...
338
        global $USER;
343
        global $USER;
Línea 343... Línea 348...
343
    }
348
    }
Línea 344... Línea 349...
344
 
349
 
345
    /**
350
    /**
346
     * Test \core_external\external_api::get_context()_from_params parameter validation.
351
     * Test \core_external\external_api::get_context()_from_params parameter validation.
347
     *
352
     *
348
     * @covers \core_external\external_api::get_context
353
     * @covers \core_external\external_api::get_context_from_params
349
     */
354
     */
350
    public function test_get_context_params2(): void {
355
    public function test_get_context_params2(): void {
Línea 351... Línea 356...
351
        global $USER;
356
        global $USER;
Línea 355... Línea 360...
355
        $this->get_context_from_params(['roleid' => 3, 'userid' => $USER->id, 'contextlevel' => "course"]);
360
        $this->get_context_from_params(['roleid' => 3, 'userid' => $USER->id, 'contextlevel' => "course"]);
356
    }
361
    }
Línea 357... Línea 362...
357
 
362
 
358
    /**
363
    /**
359
     * Test \core_external\external_api::get_context()_from_params parameter validation.
364
     * Test \core_external\external_api::get_context()_from_params parameter validation.
360
     * @covers \core_external\external_api::get_context
365
     * @covers \core_external\external_api::get_context_from_params
361
     */
366
     */
362
    public function test_get_context_params3(): void {
367
    public function test_get_context_params3(): void {
Línea 363... Línea 368...
363
        global $USER;
368
        global $USER;
Línea 372... Línea 377...
372
    /**
377
    /**
373
     * Data provider for the test_all_external_info test.
378
     * Data provider for the test_all_external_info test.
374
     *
379
     *
375
     * @return array
380
     * @return array
376
     */
381
     */
377
    public function all_external_info_provider(): array {
382
    public static function all_external_info_provider(): array {
378
        global $DB;
383
        global $DB;
Línea 379... Línea 384...
379
 
384
 
380
        // We are testing here that all the external function descriptions can be generated without
385
        // We are testing here that all the external function descriptions can be generated without
381
        // producing warnings. E.g. misusing optional params will generate a debugging message which
386
        // producing warnings. E.g. misusing optional params will generate a debugging message which
Línea 389... Línea 394...
389
    }
394
    }
Línea 390... Línea 395...
390
 
395
 
391
    /**
396
    /**
392
     * Test \core_external\external_api::external_function_info.
397
     * Test \core_external\external_api::external_function_info.
-
 
398
     *
393
     *
399
     * @group plugin_checks
394
     * @runInSeparateProcess
400
     * @runInSeparateProcess
395
     * @dataProvider all_external_info_provider
401
     * @dataProvider all_external_info_provider
396
     * @covers \core_external\external_api::external_function_info
402
     * @covers \core_external\external_api::external_function_info
397
     * @param \stdClass $definition
403
     * @param \stdClass $definition
Línea 460... Línea 466...
460
        $this->assertArrayHasKey('exception', $result);
466
        $this->assertArrayHasKey('exception', $result);
461
        $this->assertEquals($result['exception']->message, 'Exception - Modulo by zero');
467
        $this->assertEquals($result['exception']->message, 'Exception - Modulo by zero');
462
    }
468
    }
Línea 463... Línea 469...
463
 
469
 
-
 
470
    /**
-
 
471
     * Test verifying external API for a deprecated plugin type.
-
 
472
     *
-
 
473
     * @runInSeparateProcess
-
 
474
     * @return void
-
 
475
     */
-
 
476
    public function test_external_api_deprecated_plugintype(): void {
-
 
477
        $this->resetAfterTest();
-
 
478
        global $CFG;
-
 
479
        require_once($CFG->libdir . '/upgradelib.php'); // Needed for external_update_descriptions().
-
 
480
 
-
 
481
        // Inject the 'fake' plugin type and deprecate it.
-
 
482
        // Note: this method of injection is required to ensure core_component fully builds all caches from the ground up,
-
 
483
        // which is necessary to test things like class autoloading.
-
 
484
        $this->add_full_mocked_plugintype(
-
 
485
            plugintype: 'fake',
-
 
486
            path: 'lib/tests/fixtures/fakeplugins/fake',
-
 
487
        );
-
 
488
        $this->deprecate_full_mocked_plugintype('fake');
-
 
489
        external_update_descriptions('fake_fullfeatured');
-
 
490
 
-
 
491
        $this->assertNotFalse(
-
 
492
            \core_external\external_api::external_function_info('fake_fullfeatured_service_test', IGNORE_MISSING)
-
 
493
        );
-
 
494
 
-
 
495
        $result = \core_external\external_api::call_external_function('fake_fullfeatured_service_test', []);
-
 
496
        $this->assertArrayHasKey('error', $result);
-
 
497
        $this->assertFalse($result['error']);
-
 
498
        $this->assertArrayHasKey('data', $result);
-
 
499
        $this->assertEquals('fake_fullfeatured service result', $result['data']['result']);
-
 
500
    }
-
 
501
 
-
 
502
    /**
-
 
503
     * Test verifying external API for a phase 2 deprecated (deleted) plugin type.
-
 
504
     *
-
 
505
     * @runInSeparateProcess
-
 
506
     * @return void
-
 
507
     */
-
 
508
    public function test_external_api_deleted_plugintype(): void {
-
 
509
        $this->resetAfterTest();
-
 
510
        global $CFG;
-
 
511
        require_once($CFG->libdir . '/upgradelib.php'); // Needed for external_update_descriptions().
-
 
512
 
-
 
513
        // Inject the 'fake' plugin type and flag it as deleted.
-
 
514
        // Note: this method of injection is required to ensure core_component fully builds all caches from the ground up,
-
 
515
        // which is necessary to test things like class autoloading.
-
 
516
        $this->add_full_mocked_plugintype(
-
 
517
            plugintype: 'fake',
-
 
518
            path: 'lib/tests/fixtures/fakeplugins/fake',
-
 
519
        );
-
 
520
        $this->delete_full_mocked_plugintype('fake');
-
 
521
        external_update_descriptions('fake_fullfeatured');
-
 
522
 
-
 
523
        $this->assertFalse(\core_external\external_api::external_function_info('fake_fullfeatured_service_test', IGNORE_MISSING));
-
 
524
    }
-
 
525
 
464
    /**
526
    /**
465
     * Call the get_contect_from_params methods on the api class.
527
     * Call the get_contect_from_params methods on the api class.
466
     *
528
     *
467
     * @return mixed
529
     * @return mixed
468
     */
530
     */