|
25 | 25 | require_once __DIR__ . "/../resources/lib/exceptions/EncodingConversionException.php"; |
26 | 26 |
|
27 | 27 | use UnityWebPortal\lib\UnityGroup; |
| 28 | +use UnityWebPortal\lib\UnityHTTPD; |
| 29 | +use UnityWebPortal\lib\UnityHTTPDMessageSeverity; |
| 30 | +use PHPUnit\Framework\TestCase; |
28 | 31 |
|
29 | 32 | $_SERVER["HTTP_HOST"] = "phpunit"; // used for config override |
30 | 33 | require_once __DIR__ . "/../resources/config.php"; |
@@ -323,3 +326,29 @@ function getAdminUser() |
323 | 326 | { |
324 | 327 | |
325 | 328 | } |
| 329 | + |
| 330 | +function assertMessageExists( |
| 331 | + TestCase $test_case, |
| 332 | + UnityHTTPDMessageSeverity $severity, |
| 333 | + string $title_regex, |
| 334 | + string $body_regex, |
| 335 | +) { |
| 336 | + $messages = UnityHTTPD::getMessages(); |
| 337 | + $error_msg = sprintf( |
| 338 | + "message(severity='%s' title_regex='%s' body_regex='%s'), not found. found messages: %s", |
| 339 | + $severity->value, |
| 340 | + $title_regex, |
| 341 | + $body_regex, |
| 342 | + jsonEncode($messages), |
| 343 | + ); |
| 344 | + $messages_with_title = array_filter($messages, fn($x) => preg_match($title_regex, $x[0])); |
| 345 | + $messages_with_title_and_body = array_filter( |
| 346 | + $messages_with_title, |
| 347 | + fn($x) => preg_match($body_regex, $x[1]), |
| 348 | + ); |
| 349 | + $messages_with_title_and_body_and_severity = array_filter( |
| 350 | + $messages_with_title_and_body, |
| 351 | + fn($x) => $x[2] == $severity, |
| 352 | + ); |
| 353 | + $test_case->assertNotEmpty($messages_with_title_and_body_and_severity, $error_msg); |
| 354 | +} |
0 commit comments