toBeTrue(); expect(CactiValidator::isValid('0', $constraints))->toBeTrue(); expect(CactiValidator::isValid('', $constraints))->toBeFalse(); expect(CactiValidator::isValid(null, $constraints))->toBeFalse(); expect(CactiValidator::isValid('abc', $constraints))->toBeFalse(); }); it('validates availability_method (NotBlank + Regex)', function () { $constraints = [new Assert\NotBlank(), new Assert\Regex('/^[0-9]+$/')]; expect(CactiValidator::isValid('1', $constraints))->toBeTrue(); expect(CactiValidator::isValid('0', $constraints))->toBeTrue(); expect(CactiValidator::isValid('', $constraints))->toBeFalse(); expect(CactiValidator::isValid(null, $constraints))->toBeFalse(); expect(CactiValidator::isValid('abc', $constraints))->toBeFalse(); }); it('verifies CactiValidator::validateInput populates session and raises message on failure', function () { // Define constants if not present if (!defined('SESS_FIELD_VALUES')) define('SESS_FIELD_VALUES', 'sess_field_values'); if (!defined('SESS_ERROR_FIELDS')) define('SESS_ERROR_FIELDS', 'sess_error_fields'); // Mock raise_message if it doesn't exist (a full-suite run may have already // loaded the real one from lib/functions.php; either is safe to call here). if (!function_exists('raise_message')) { function raise_message($id) {} } $_SESSION = []; $constraints = [new Assert\NotBlank(), new Assert\Regex('/^[0-9]+$/')]; // Test valid input CactiValidator::validateInput('123', 'host_template', $constraints); expect($_SESSION[SESS_FIELD_VALUES]['host_template'])->toBe('123'); expect(isset($_SESSION[SESS_ERROR_FIELDS]['host_template']))->toBeFalse(); // Test invalid input $_SESSION = []; CactiValidator::validateInput('', 'host_template', $constraints, 3); expect($_SESSION[SESS_FIELD_VALUES]['host_template'])->toBe(''); expect($_SESSION[SESS_ERROR_FIELDS]['host_template'])->toBe(3); });