diff options
author | Valentin Popov <info@valentineus.link> | 2019-05-10 14:34:57 +0300 |
---|---|---|
committer | Valentin Popov <info@valentineus.link> | 2019-05-10 14:34:57 +0300 |
commit | 46711c9942ebdcf6bbb8472f6893050e48f35f7d (patch) | |
tree | 9a2e8e1ad92c4e8e3e2188de93c5aa862858126e /tests/api_test.php | |
parent | e84ac6859a9eebe185b44ddb7ee44eafdfff5be1 (diff) | |
download | local_webhooks-46711c9942ebdcf6bbb8472f6893050e48f35f7d.tar.xz local_webhooks-46711c9942ebdcf6bbb8472f6893050e48f35f7d.zip |
Added correct test delete record
Signed-off-by: Valentin Popov <info@valentineus.link>
Diffstat (limited to 'tests/api_test.php')
-rw-r--r-- | tests/api_test.php | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/tests/api_test.php b/tests/api_test.php index 2da6a3d..a2900e4 100644 --- a/tests/api_test.php +++ b/tests/api_test.php @@ -52,6 +52,7 @@ final class local_webhooks_api_testcase extends advanced_testcase { */ private static function get_random_record(): record { $record = new record(); + $record->events = self::get_random_events(); $record->header = 'application/json'; $record->name = uniqid('', false); @@ -102,8 +103,6 @@ final class local_webhooks_api_testcase extends advanced_testcase { /** * Test deletion of the service. * - * @todo It's no testing all conditional. - * * @group local_webhooks * * @throws \dml_exception @@ -115,12 +114,26 @@ final class local_webhooks_api_testcase extends advanced_testcase { $this->resetAfterTest(); + // Testing correct delete record of the database. $record = self::get_random_record(); $record->id = api::add_service($record); self::assertTrue(api::del_service($record->id)); self::assertCount(0, $DB->get_records(LW_TABLE_EVENTS)); self::assertCount(0, $DB->get_records(LW_TABLE_SERVICES)); + + // Testing correct delete record of the record's list. + $ids = []; + $total = random_int(5, 20); + + for ($i = 0; $i < $total; $i++) { + $record = self::get_random_record(); + $ids[] = api::add_service($record); + } + + self::assertEquals(count($ids), api::get_total_count()); + self::assertTrue(api::del_service($ids[array_rand($ids, 1)])); + self::assertEquals(count($ids) - 1, api::get_total_count()); } /** |