MDL-79843 core_external: test covering services for deprecated plugins

This just asserts that web services provided by deprecated plugins can
still be used (similar to how their APIs can still be used during the
deprecation period).
This commit is contained in:
Jake Dallimore 2024-07-25 12:28:24 +08:00
parent 995c5489b7
commit 36ab70c64a
No known key found for this signature in database

View file

@ -16,6 +16,8 @@
namespace core_external; namespace core_external;
use core\tests\fake_plugins_test_trait;
/** /**
* Unit tests for core_external\external_api. * Unit tests for core_external\external_api.
* *
@ -26,6 +28,9 @@ namespace core_external;
* @covers \core_external\external_api * @covers \core_external\external_api
*/ */
final class external_api_test extends \advanced_testcase { final class external_api_test extends \advanced_testcase {
use fake_plugins_test_trait;
/** /**
* Test the validate_parameters method. * Test the validate_parameters method.
* *
@ -461,6 +466,62 @@ final class external_api_test extends \advanced_testcase {
$this->assertEquals($result['exception']->message, 'Exception - Modulo by zero'); $this->assertEquals($result['exception']->message, 'Exception - Modulo by zero');
} }
/**
* Test verifying external API for a deprecated plugin type.
*
* @runInSeparateProcess
* @return void
*/
public function test_external_api_deprecated_plugintype(): void {
$this->resetAfterTest();
global $CFG;
require_once($CFG->libdir . '/upgradelib.php'); // Needed for external_update_descriptions().
// Inject the 'fake' plugin type and deprecate it.
// Note: this method of injection is required to ensure core_component fully builds all caches from the ground up,
// which is necessary to test things like class autoloading.
$this->add_full_mocked_plugintype(
plugintype: 'fake',
path: 'lib/tests/fixtures/fakeplugins/fake',
);
$this->deprecate_full_mocked_plugintype('fake');
external_update_descriptions('fake_fullfeatured');
$this->assertNotFalse(
\core_external\external_api::external_function_info('fake_fullfeatured_service_test', IGNORE_MISSING)
);
$result = \core_external\external_api::call_external_function('fake_fullfeatured_service_test', []);
$this->assertArrayHasKey('error', $result);
$this->assertFalse($result['error']);
$this->assertArrayHasKey('data', $result);
$this->assertEquals('fake_fullfeatured service result', $result['data']['result']);
}
/**
* Test verifying external API for a phase 2 deprecated (deleted) plugin type.
*
* @runInSeparateProcess
* @return void
*/
public function test_external_api_deleted_plugintype(): void {
$this->resetAfterTest();
global $CFG;
require_once($CFG->libdir . '/upgradelib.php'); // Needed for external_update_descriptions().
// Inject the 'fake' plugin type and flag it as deleted.
// Note: this method of injection is required to ensure core_component fully builds all caches from the ground up,
// which is necessary to test things like class autoloading.
$this->add_full_mocked_plugintype(
plugintype: 'fake',
path: 'lib/tests/fixtures/fakeplugins/fake',
);
$this->delete_full_mocked_plugintype('fake');
external_update_descriptions('fake_fullfeatured');
$this->assertFalse(\core_external\external_api::external_function_info('fake_fullfeatured_service_test', IGNORE_MISSING));
}
/** /**
* Call the get_contect_from_params methods on the api class. * Call the get_contect_from_params methods on the api class.
* *