aboutsummaryrefslogtreecommitdiff
path: root/tests/external_test.php
diff options
context:
space:
mode:
authorValentin Popov <info@valentineus.link>2019-05-10 23:17:20 +0300
committerValentin Popov <info@valentineus.link>2019-05-10 23:17:20 +0300
commited0ce52060690eff5459c037338d26796307ef79 (patch)
treeb555dc3316a47296a71c32149766889d53b0dd55 /tests/external_test.php
parent6b18cffc970a69a292c2d9836ff5b460a5d1005a (diff)
downloadlocal_webhooks-ed0ce52060690eff5459c037338d26796307ef79.tar.xz
local_webhooks-ed0ce52060690eff5459c037338d26796307ef79.zip
Added external function delete service
Signed-off-by: Valentin Popov <info@valentineus.link>
Diffstat (limited to 'tests/external_test.php')
-rw-r--r--tests/external_test.php50
1 files changed, 44 insertions, 6 deletions
diff --git a/tests/external_test.php b/tests/external_test.php
index ea2b362..517f370 100644
--- a/tests/external_test.php
+++ b/tests/external_test.php
@@ -65,7 +65,7 @@ final class local_webhooks_external_testcase extends externallib_advanced_testca
}
/**
- * Testing external get record's data.
+ * Testing the external delete service.
*
* @throws \ReflectionException
* @throws \coding_exception
@@ -74,10 +74,50 @@ final class local_webhooks_external_testcase extends externallib_advanced_testca
* @throws \invalid_response_exception
* @throws \restricted_context_exception
*/
- public function test_get_service() {
+ public function test_deleting() {
+ $this->resetAfterTest();
self::setAdminUser();
+ // Testing correct delete record of the database.
+ $record = self::get_random_record();
+ $record->id = api::add_service($record);
+
+ $return = local_webhooks_external::del_service($record->id);
+ $return = external_api::clean_returnvalue(local_webhooks_external::del_service_returns(), $return);
+
+ self::assertEquals(0, api::get_total_count());
+ self::assertInternalType('bool', $return);
+
+ $ids = [];
+ $total = random_int(5, 20);
+
+ // Testing correct delete record of the record's list.
+ for ($i = 0; $i < $total; $i++) {
+ $record = self::get_random_record();
+ $ids[] = api::add_service($record);
+ }
+
+ self::assertEquals(count($ids), api::get_total_count());
+ $return = local_webhooks_external::del_service($ids[array_rand($ids, 1)]);
+ $return = external_api::clean_returnvalue(local_webhooks_external::del_service_returns(), $return);
+
+ self::assertEquals(count($ids) - 1, api::get_total_count());
+ self::assertInternalType('bool', $return);
+ }
+
+ /**
+ * Testing external get record's data.
+ *
+ * @throws \ReflectionException
+ * @throws \coding_exception
+ * @throws \dml_exception
+ * @throws \invalid_parameter_exception
+ * @throws \invalid_response_exception
+ * @throws \restricted_context_exception
+ */
+ public function test_get_service() {
$this->resetAfterTest();
+ self::setAdminUser();
// Creating a new record.
$record = self::get_random_record();
@@ -114,9 +154,8 @@ final class local_webhooks_external_testcase extends externallib_advanced_testca
* @throws \restricted_context_exception
*/
public function test_get_services() {
- self::setAdminUser();
-
$this->resetAfterTest();
+ self::setAdminUser();
$records = [];
$total = random_int(5, 10);
@@ -168,9 +207,8 @@ final class local_webhooks_external_testcase extends externallib_advanced_testca
* @throws \restricted_context_exception
*/
public function test_get_services_with_conditions() {
- self::setAdminUser();
-
$this->resetAfterTest();
+ self::setAdminUser();
$records = [];
$total = random_int(5, 10);