diff options
author | Valentin Popov <info@valentineus.link> | 2019-05-11 02:45:50 +0300 |
---|---|---|
committer | Valentin Popov <info@valentineus.link> | 2019-05-11 02:45:50 +0300 |
commit | 7dc023b05a9292cb9e5ea4fa65e86668c857cd82 (patch) | |
tree | 8c882e9baff3a11f951f59c45c8f725a7a473c88 /tests/external_test.php | |
parent | 3a865453a46a2c0f7fcb0b35bd31948620e687d7 (diff) | |
download | local_webhooks-7dc023b05a9292cb9e5ea4fa65e86668c857cd82.tar.xz local_webhooks-7dc023b05a9292cb9e5ea4fa65e86668c857cd82.zip |
Added external function update existing service
Signed-off-by: Valentin Popov <info@valentineus.link>
Diffstat (limited to 'tests/external_test.php')
-rw-r--r-- | tests/external_test.php | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/external_test.php b/tests/external_test.php index 387db86..e5374f6 100644 --- a/tests/external_test.php +++ b/tests/external_test.php @@ -311,4 +311,76 @@ final class local_webhooks_external_testcase extends externallib_advanced_testca self::assertNotEquals($service1['id'], $service2['id']); } + + /** + * Testing full update parameters of the service. + * + * @throws \ReflectionException + * @throws \coding_exception + * @throws \dml_exception + * @throws \invalid_parameter_exception + * @throws \restricted_context_exception + */ + public function test_updating_full() { + $this->resetAfterTest(); + self::setAdminUser(); + + $record = self::get_random_record(); + $record2 = self::get_random_record(); + $record2->id = api::add_service($record); + + $return = local_webhooks_external::set_service((array) $record2); + $return = external_api::validate_parameters(local_webhooks_external::set_service_returns(), $return); + self::assertInternalType('bool', $return); + + $service = api::get_service($record2->id); + self::assertEquals($record2->id, $service->id); + self::assertEquals($record2->header, $service->header); + self::assertEquals($record2->name, $service->name); + self::assertEquals($record2->point, $service->point); + self::assertEquals($record2->status, $service->status); + self::assertEquals($record2->token, $service->token); + + self::assertInternalType('array', $service->events); + self::assertCount(count($record2->events), $service->events); + foreach ($service->events as $event) { + self::assertContains($event, $record2->events); + } + } + + /** + * Testing selective update parameters of the service. + * + * @throws \ReflectionException + * @throws \coding_exception + * @throws \dml_exception + * @throws \invalid_parameter_exception + * @throws \restricted_context_exception + */ + public function test_updating_short() { + $this->resetAfterTest(); + self::setAdminUser(); + + $record = self::get_random_record(); + $record2 = self::get_random_record(); + $record->id = api::add_service($record); + + $return = local_webhooks_external::set_service(['id' => $record->id, 'name' => $record2->name, 'point' => $record2->point]); + $return = external_api::validate_parameters(local_webhooks_external::set_service_returns(), $return); + self::assertInternalType('bool', $return); + + $service = api::get_service($record->id); + self::assertEquals($record->header, $service->header); + self::assertEquals($record->id, $service->id); + self::assertEquals($record->status, $service->status); + self::assertEquals($record->token, $service->token); + self::assertEquals($record2->name, $service->name); + self::assertEquals($record2->point, $service->point); + + self::assertInternalType('array', $service->events); + self::assertCount(count($record->events), $service->events); + foreach ($service->events as $event) { + self::assertContains($event, $record->events); + } + } }
\ No newline at end of file |