Added get a total count records
Signed-off-by: Valentin Popov <info@valentineus.link>
This commit is contained in:
parent
cb6d5c7e13
commit
d441f44698
@ -187,6 +187,18 @@ final class api {
|
|||||||
return $services;
|
return $services;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a total count of existing records.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
* @throws \dml_exception
|
||||||
|
*/
|
||||||
|
public static function get_total_count(): int {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
return $DB->count_records(LW_TABLE_SERVICES);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update an existing record in the database.
|
* Update an existing record in the database.
|
||||||
*
|
*
|
||||||
|
@ -306,6 +306,36 @@ final class local_webhooks_api_testcase extends advanced_testcase {
|
|||||||
self::assertNotEquals($service1->id, $service2->id);
|
self::assertNotEquals($service1->id, $service2->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Testing get a total count of existing records.
|
||||||
|
*
|
||||||
|
* @throws \coding_exception
|
||||||
|
* @throws \dml_exception
|
||||||
|
*/
|
||||||
|
public function test_total() {
|
||||||
|
$this->resetAfterTest();
|
||||||
|
|
||||||
|
$record = new record();
|
||||||
|
$record->header = 'application/json';
|
||||||
|
$record->status = true;
|
||||||
|
$record->token = '967b2286-0874-4938-b088-efdbcf8a79bc';
|
||||||
|
$record->events = [
|
||||||
|
'\core\event\course_created',
|
||||||
|
'\core\event\course_deleted',
|
||||||
|
'\core\event\course_updated',
|
||||||
|
'\core\event\course_viewed',
|
||||||
|
];
|
||||||
|
|
||||||
|
$total = random_int(5, 20);
|
||||||
|
for ($i = 0; $i < $total; $i++) {
|
||||||
|
$record->name = 'Example name #' . $i;
|
||||||
|
$record->point = 'http://example.org/test_' . $i;
|
||||||
|
api::create_service($record);
|
||||||
|
}
|
||||||
|
|
||||||
|
self::assertEquals($total, api::get_total_count());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Testing of the service update.
|
* Testing of the service update.
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user