diff options
author | Valentin Popov <info@valentineus.link> | 2019-05-11 01:40:47 +0300 |
---|---|---|
committer | Valentin Popov <info@valentineus.link> | 2019-05-11 01:40:47 +0300 |
commit | 3a865453a46a2c0f7fcb0b35bd31948620e687d7 (patch) | |
tree | 89a9b9f4d9dbf0a51489f9d81889ef6415b3e0e1 | |
parent | 747055f9d199ea53ae066f1844d24885052f0030 (diff) | |
download | local_webhooks-3a865453a46a2c0f7fcb0b35bd31948620e687d7.tar.xz local_webhooks-3a865453a46a2c0f7fcb0b35bd31948620e687d7.zip |
Added external function get the event's list
Signed-off-by: Valentin Popov <info@valentineus.link>
-rw-r--r-- | externallib.php | 47 | ||||
-rw-r--r-- | tests/external_test.php | 28 |
2 files changed, 74 insertions, 1 deletions
diff --git a/externallib.php b/externallib.php index baef051..d6e3604 100644 --- a/externallib.php +++ b/externallib.php @@ -131,6 +131,51 @@ final class local_webhooks_external extends external_api { } /** + * Get the event's list. + * + * @return array + * + * @throws \ReflectionException + * @throws \dml_exception + * @throws \invalid_parameter_exception + * @throws \restricted_context_exception + */ + public static function get_events(): array { + $context = context_system::instance(); + self::validate_context($context); + + return api::get_events(); + } + + /** + * Returns description of the method parameters. + * + * @return \external_function_parameters + */ + public static function get_events_parameters(): external_function_parameters { + return new external_function_parameters([], ''); + } + + /** + * Returns description of the method result value. + * + * @return \external_multiple_structure + */ + public static function get_events_returns(): external_multiple_structure { + return new external_multiple_structure( + new external_single_structure([ + 'action' => new external_value(PARAM_ALPHANUMEXT, ''), + 'component' => new external_value(PARAM_COMPONENT, ''), + 'crud' => new external_value(PARAM_ALPHA, ''), + 'edulevel' => new external_value(PARAM_INT, ''), + 'eventname' => new external_value(PARAM_RAW, ''), + 'objecttable' => new external_value(PARAM_RAW, ''), + 'target' => new external_value(PARAM_RAW, ''), + ], ''), '' + ); + } + + /** * Get data by service. * * @param int $serviceid @@ -252,7 +297,7 @@ final class local_webhooks_external extends external_api { 'point' => new external_value(PARAM_URL, 'The service\'s endpoint.'), 'status' => new external_value(PARAM_BOOL, 'The service\'s status.'), 'token' => new external_value(PARAM_RAW, 'The service\'s secret key.'), - ], '') + ], ''), '' ); } }
\ No newline at end of file diff --git a/tests/external_test.php b/tests/external_test.php index c0e4cd7..387db86 100644 --- a/tests/external_test.php +++ b/tests/external_test.php @@ -142,6 +142,34 @@ final class local_webhooks_external_testcase extends externallib_advanced_testca } /** + * Testing external function get the event's list. + * + * @throws \ReflectionException + * @throws \dml_exception + * @throws \invalid_parameter_exception + * @throws \invalid_response_exception + * @throws \restricted_context_exception + */ + public function test_get_events() { + $this->resetAfterTest(); + self::setAdminUser(); + + $return = local_webhooks_external::get_events(); + $return = external_api::clean_returnvalue(local_webhooks_external::get_events_returns(), $return); + + self::assertInternalType('array', $return); + self::assertCount(count(api::get_events()), $return); + + foreach ($return as $item) { + self::assertInternalType('array', $item); + + self::assertEquals([ + 'action', 'component', 'crud', 'edulevel', 'eventname', 'objecttable', 'target', + ], array_keys($item)); + } + } + + /** * Testing external get record's data. * * @throws \ReflectionException |