Files
FOSSBilling/tests/Modules/Cron/CronGuestTest.php
T
Belle Aerni 8f4d0d4cac More tests and CI improvements (#2078)
* Wrote a few more tests, improvements

* Ran Rector & PHP-CS-Fixer

* Append a capital letter to the test client passwords

* Minor tweaks

* Display more info after the tests run

* Oops, I forgot to set the dir

* Fix cron behavior for test env, dropped legacy tests

* Rename the empty test suite so PHPUnit ignores it

* Update cspell.json

* Minor tweaks to the tests

* Fixes
2024-01-17 18:11:45 -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]);
$result = Request::makeRequest('guest/cron/run');
$this->assertFalse($result->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)]);
$result = Request::makeRequest('guest/cron/run');
$this->assertTrue($result->wasSuccessful(), $result->generatePHPUnitMessage());
// Finally, ensure the rate limit is working
$result = Request::makeRequest('guest/cron/run');
$this->assertTrue($result->wasSuccessful(), 'Cron ran when it should have been rate limited');
$this->assertFalse($result->getResult()); // Returns false when rate-limited
}
}