Files
FOSSBilling/tests/Modules/Cron/CronGuestTest.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

29 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
use APIHelper\Request;
use PHPUnit\Framework\TestCase;
final class CronGuestTest extends TestCase
{
public function testCronGuestBehavior(): void
{
// Ensure cron does not run for guests when disabled
Request::makeRequest('admin/extension/config_save', ['ext' => 'mod_cron', 'guest_cron' => false]);
$response = Request::makeRequest('guest/cron/run');
$this->assertFalse($response->wasSuccessful(), 'Cron was run when it was not supposed to');
// Now enable it, set the last exec back into the past, and then validate it does run
Request::makeRequest('admin/extension/config_save', ['ext' => 'mod_cron', 'guest_cron' => true]);
Request::makeRequest('admin/system/update_params', ['last_cron_exec' => date('Y-m-d H:i:s', time() - 6400)]);
$response = Request::makeRequest('guest/cron/run');
$this->assertTrue($response->wasSuccessful(), $response->generatePHPUnitMessage());
// Finally, ensure the rate limit is working
$response = Request::makeRequest('guest/cron/run');
$this->assertTrue($response->wasSuccessful(), 'Cron ran when it should have been rate limited');
$this->assertFalse($response->getResult()); // Returns false when rate-limited
}
}