Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"test:appium-other": "mocha test/helper/Appium_test.js --grep 'second'",
"test:ios:appium-quick": "mocha test/helper/Appium_ios_test.js --grep 'quick'",
"test:ios:appium-other": "mocha test/helper/Appium_ios_test.js --grep 'second'",
"test-app:start": "php -S 127.0.0.1:8000 -t test/data/app",
"test-app:start": "php -S 127.0.0.1:8000 -t test/data/app test/data/app/index.php",
"test-app:stop": "kill -9 $(lsof -t -i:8000)",
"test:unit:webbapi:playwright": "mocha test/helper/Playwright_test.js",
"test:unit:webbapi:puppeteer": "mocha test/helper/Puppeteer_test.js",
Expand Down
13 changes: 13 additions & 0 deletions test/data/app/api/post-data.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
session_start();

header('Content-Type: application/json');

if (isset($_SESSION['post_data'])) {
echo json_encode($_SESSION['post_data']);
// Clear the POST data after serving
unset($_SESSION['post_data']);
} else {
echo json_encode([]);
}
?>
186 changes: 137 additions & 49 deletions test/data/app/index.php
Original file line number Diff line number Diff line change
@@ -1,52 +1,140 @@
<?php
// Main router for React SPA with PHP fallbacks
$request_uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$spa_path = __DIR__ . '/../spa/dist';

// Handle static assets (JS, CSS, images, etc.)
if (preg_match('/\.(js|css|png|jpg|jpeg|gif|svg|ico)$/', $request_uri)) {
$file_path = $spa_path . $request_uri;
if (file_exists($file_path)) {
$ext = pathinfo($file_path, PATHINFO_EXTENSION);
$content_types = [
'js' => 'application/javascript',
'css' => 'text/css',
'png' => 'image/png',
'jpg' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'gif' => 'image/gif',
'svg' => 'image/svg+xml',
'ico' => 'image/x-icon'
];

if (isset($content_types[$ext])) {
header('Content-Type: ' . $content_types[$ext]);
}
readfile($file_path);
exit;
} else {
// Asset not found
http_response_code(404);
echo "Asset not found: " . $request_uri;
exit;
}
}

// Handle API routes
if (strpos($request_uri, '/api/') === 0) {
$api_file = __DIR__ . $request_uri;
if (file_exists($api_file)) {
include $api_file;
exit;
} else {
http_response_code(404);
echo json_encode(['error' => 'API endpoint not found']);
exit;
}
}

// Handle POST data for React app
if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST)) {
// Store POST data in session for React app to display
session_start();
$_SESSION['post_data'] = $_POST;

// Redirect back to index with a flag
header('Location: /?posted=1');
exit;
}

// Handle special PHP routes that still need server-side processing
if (!headers_sent()) header('Content-Type: text/html; charset=UTF-8');

require_once('glue.php');
require_once('data.php');
require_once('controllers.php');

$urls = array(
'/' => 'index',
'/info' => 'info',
'/cookies' => 'cookies',
'/cookies2' => 'cookiesHeader',
'/search.*' => 'search',
'/login' => 'login',
'/redirect' => 'redirect',
'/redirect2' => 'redirect2',
'/redirect3' => 'redirect3',
'/redirect_long' => 'redirect_long',
'/redirect4' => 'redirect4',
'/redirect_params' => 'redirect_params',
'/redirect_interval' => 'redirect_interval',
'/redirect_header_interval' => 'redirect_header_interval',
'/redirect_self' => 'redirect_self',
'/relative_redirect' => 'redirect_relative',
'/relative/redirect' => 'redirect_relative',
'/redirect_twice' => 'redirect_twice',
'/relative/info' => 'info',
'/somepath/redirect_base_uri_has_path' => 'redirect_base_uri_has_path',
'/somepath/redirect_base_uri_has_path_302' => 'redirect_base_uri_has_path_302',
'/somepath/info' => 'info',
'/facebook\??.*' => 'facebookController',
'/form/(.*?)(#|\?.*?)?' => 'form',
'/articles\??.*' => 'articles',
'/auth' => 'httpAuth',
'/register' => 'register',
'/content-iso' => 'contentType1',
'/content-cp1251' => 'contentType2',
'/unset-cookie' => 'unsetCookie',
'/external_url' => 'external_url',
'/spinner' => 'spinner',
'/iframe' => 'iframe',
'/iframes' => 'iframes',
'/iframe_nested' => 'iframe_nested',
'/dynamic' => 'dynamic',
'/timeout' => 'timeout',
'/download' => 'download',
'/basic_auth' => 'basic_auth',
'/image' => 'basic_image',
'/invisible_elements' => 'invisible_elements'
);

glue::stick($urls);
// Routes that need special PHP processing
$special_routes = [
'/cookies', '/cookies2', '/login', '/auth', '/register',
'/content-iso', '/content-cp1251', '/unset-cookie',
'/download', '/basic_auth', '/redirect', '/redirect2',
'/redirect3', '/redirect_long', '/redirect4',
'/redirect_params', '/redirect_interval',
'/redirect_header_interval', '/redirect_self',
'/relative_redirect', '/relative/redirect', '/redirect_twice',
'/somepath/redirect_base_uri_has_path',
'/somepath/redirect_base_uri_has_path_302',
'/facebook', '/articles', '/external_url',
'/iframe', '/iframes', '/iframe_nested', '/dynamic',
'/timeout', '/image', '/invisible_elements'
];

foreach ($special_routes as $route) {
if (strpos($request_uri, $route) === 0) {
// Load the original PHP routing for these special cases
require_once('glue.php');
require_once('data.php');
require_once('controllers.php');

$urls = array(
'/' => 'index',
'/info' => 'info',
'/cookies' => 'cookies',
'/cookies2' => 'cookiesHeader',
'/search.*' => 'search',
'/login' => 'login',
'/redirect' => 'redirect',
'/redirect2' => 'redirect2',
'/redirect3' => 'redirect3',
'/redirect_long' => 'redirect_long',
'/redirect4' => 'redirect4',
'/redirect_params' => 'redirect_params',
'/redirect_interval' => 'redirect_interval',
'/redirect_header_interval' => 'redirect_header_interval',
'/redirect_self' => 'redirect_self',
'/relative_redirect' => 'redirect_relative',
'/relative/redirect' => 'redirect_relative',
'/redirect_twice' => 'redirect_twice',
'/relative/info' => 'info',
'/somepath/redirect_base_uri_has_path' => 'redirect_base_uri_has_path',
'/somepath/redirect_base_uri_has_path_302' => 'redirect_base_uri_has_path_302',
'/somepath/info' => 'info',
'/facebook\??.*' => 'facebookController',
'/form/(.*?)(#|\?.*?)?' => 'form',
'/articles\??.*' => 'articles',
'/auth' => 'httpAuth',
'/register' => 'register',
'/content-iso' => 'contentType1',
'/content-cp1251' => 'contentType2',
'/unset-cookie' => 'unsetCookie',
'/external_url' => 'external_url',
'/spinner' => 'spinner',
'/iframe' => 'iframe',
'/iframes' => 'iframes',
'/iframe_nested' => 'iframe_nested',
'/dynamic' => 'dynamic',
'/timeout' => 'timeout',
'/download' => 'download',
'/basic_auth' => 'basic_auth',
'/image' => 'basic_image',
'/invisible_elements' => 'invisible_elements'
);

glue::stick($urls);
exit;
}
}

// For all other routes (React SPA routes), serve the index.html
$index_file = $spa_path . '/index.html';
if (file_exists($index_file)) {
readfile($index_file);
} else {
echo "React SPA not built. Please run 'npm run build' in test/data/spa directory.";
}
28 changes: 13 additions & 15 deletions test/data/app/view/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,30 @@
<body>

<h1 data-testid="welcome">Welcome to test app!</h1>
<h2>With&nbsp;special&nbsp;space chars</h1>

<div class="notice" qa-id = "test"><?php if (isset($notice)) echo $notice; ?></div>
<h2>With&nbsp;special&nbsp;space chars</h2>
<div class="notice" qa-id="test"><?php if (isset($notice)) echo $notice; ?></div>

<p>
<a href="/info" id="link" qa-id = "test" qa-link = "test">More info</a>
<a href="/info" id="link" qa-id="test" qa-link="test">More info</a>
</p>


<div id="area1" qa-id = "test" qa-id = "test">
<a href="/form/file" qa-id = "test" qa-link = "test"> Test Link </a>
<div id="area1" qa-id="test">
<a href="/form/file" qa-id="test" qa-link="test"> Test Link </a>
</div>
<div id="area2" qa-id = "test">
<a href="/form/hidden" qa-id = "test" qa-link = "test">Test</a>
<div id="area2" qa-id="test">
<a href="/form/hidden" qa-id="test" qa-link="test">Test</a>
</div>
<div id="area3" qa-id = "test">
<a href="info" qa-id = "test" qa-link = "test">Document-Relative Link</a>
<div id="area3" qa-id="test">
<a href="info" qa-id="test" qa-link="test">Document-Relative Link</a>
</div>
<div id="area4" qa-id = "test">
<a href="/spinner" qa-id = "test" qa-link = "test">Spinner</a>
<div id="area4" qa-id="test">
<a href="/spinner" qa-id="test" qa-link="test">Spinner</a>
</div>

<div id="area5" qa-id = "test">
<input qa-id = "test" qa-link = "test" disabled>Hidden input</a>
<div id="area5" qa-id="test">
<input qa-id="test" qa-link="test" disabled>Hidden input</input>
</div>

A wise man said: "debug!"

<?php print_r($_POST); ?>
Expand Down
Binary file added test/data/spa/dist/avatar.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading