From eb0b81356761978f14091c62ce78085e5b372a65 Mon Sep 17 00:00:00 2001 From: n0nag0n Date: Sun, 18 Feb 2024 21:56:26 -0700 Subject: [PATCH] added more tests for ui testing --- tests/server-v2/index.php | 32 +++++++++++++++++++++++++++++++- tests/server/index.php | 17 ++++++++--------- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/tests/server-v2/index.php b/tests/server-v2/index.php index 1ebdd13..3eb765f 100644 --- a/tests/server-v2/index.php +++ b/tests/server-v2/index.php @@ -20,6 +20,9 @@ Flight::set('flight.v2.output_buffering', true); // Test 1: Root route Flight::route('/', function () { echo 'Route text: Root route works!'; + if (Flight::request()->query->redirected) { + echo '
Redirected from /redirect route successfully!'; + } }); Flight::route('/querytestpath', function () { echo 'Route text: This ir query route
'; @@ -93,9 +96,32 @@ Flight::route('/protected', function () { Flight::route('/template/@name', function ($name) { Flight::render('template.phtml', ['name' => $name]); }); + +// Test 8: Throw an error +Flight::route('/error', function () { + trigger_error('This is a successful error'); +}); + +// Test 9: JSON output (should not output any other html) +Flight::route('/json', function () { + echo "\n\n\n\n\n"; + Flight::json(['message' => 'JSON renders successfully!']); + echo "\n\n\n\n\n"; +}); + +// Test 10: Halt +Flight::route('/halt', function () { + Flight::halt(400, 'Halt worked successfully'); +}); + +// Test 11: Redirect +Flight::route('/redirect', function () { + Flight::redirect('/?redirected=1'); +}); + Flight::set('flight.views.path', './'); Flight::map('error', function (Throwable $error) { - echo "

An error occurred, mapped error method worked, error bellow

"; + echo "

An error occurred, mapped error method worked, error below

"; echo '
';
     echo str_replace(getenv('PWD'), "***CLASSIFIED*****", $error->getTraceAsString());
     echo "
"; @@ -164,6 +190,10 @@ echo '
  • Query path
  • Post method test page - should be 404
  • Mega group
  • +
  • Error
  • +
  • JSON
  • +
  • Halt
  • +
  • Redirect
  • '; Flight::before('start', function ($params) { echo '
    '; diff --git a/tests/server/index.php b/tests/server/index.php index 80efa6a..30c1176 100644 --- a/tests/server/index.php +++ b/tests/server/index.php @@ -28,8 +28,8 @@ Flight::group('', function () { } }); Flight::route('/querytestpath', function () { - echo 'Route text: This ir query route
    '; - echo "I got such query parameters:
    ";
    +        echo 'Route text: This is query route
    '; + echo "Query parameters:
    ";
             print_r(Flight::request()->query);
             echo "
    "; }, false, "querytestpath"); @@ -103,19 +103,18 @@ Flight::group('', function () { Flight::route('/halt', function () { Flight::halt(400, 'Halt worked successfully'); }); + + // Test 11: Redirect + Flight::route('/redirect', function () { + Flight::redirect('/?redirected=1'); + }); }, [ new LayoutMiddleware() ]); -// Test 9: JSON output +// Test 9: JSON output (should not output any other html) Flight::route('/json', function () { Flight::json(['message' => 'JSON renders successfully!']); }); - -// Test 11: Redirect -Flight::route('/redirect', function () { - Flight::redirect('/?redirected=1'); -}); - Flight::map('error', function (Throwable $e) { echo sprintf( '

    500 Internal Server Error

    ' .