Files
FOSSBilling/tests/Modules/Cron/CronAdminTest.php
T
Belle Aerni 1b0fba1922 Various additional tests (#2069)
* Various additional tests

* Fixes

* More fixes

* Fixed my other mistakes

* Final fix
2024-01-15 00:46:19 -08:00

36 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
use APIHelper\Request;
use PHPUnit\Framework\TestCase;
final class CronAdminTest extends TestCase
{
public function testDoesCronWork(): void
{
// Get when cron was last run
$response = Request::makeRequest('admin/cron/info');
$this->assertTrue($response->wasSuccessful(), $response->generatePHPUnitMessage());
if (!empty($response->getResult()['last_cron_exec'])) {
$firstDate = new DateTime($response->getResult()['last_cron_exec']);
} else {
// Cron didn't have a last execution set, so let's just make up that it was an hour ago
$firstDate = new DateTime();
$firstDate->modify('-1 hour');
}
// Then run it
$response = Request::makeRequest('admin/cron/run');
$this->assertTrue($response->wasSuccessful(), $response->generatePHPUnitMessage());
// Validate the last run date was moved up
$response = Request::makeRequest('admin/cron/info');
$this->assertTrue($response->wasSuccessful(), $response->generatePHPUnitMessage());
$this->assertNotEmpty($response->getResult()['last_cron_exec']);
$newDate = new DateTime($response->getResult()['last_cron_exec']);
$this->assertGreaterThan($firstDate, $newDate, "Cron's last execution time was not incremented");
}
}