Skip to content

Commit c5c64ee

Browse files
authored
Tests: improve Windows compatibility (#100)
1 parent 4e1cce5 commit c5c64ee

2 files changed

Lines changed: 19 additions & 12 deletions

File tree

features/server.feature

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ Feature: Serve WordPress locally
1212
Just another WordPress site
1313
"""
1414

15-
When I run `curl -sS localhost:8181/license.txt > /tmp/license.txt`
16-
And I run `cmp /tmp/license.txt license.txt`
17-
Then STDOUT should be empty
15+
When I run `curl -sSL http://localhost:8181/license.txt`
16+
Then STDOUT should contain:
17+
"""
18+
WordPress - Web publishing software
19+
"""
1820

1921
Scenario: Passthrough arguments to PHP binary
2022
Given a WP install
@@ -43,8 +45,8 @@ Feature: Serve WordPress locally
4345
Scenario: Pretty permalinks
4446
Given a WP install
4547
And I launch in the background `wp server --host=localhost --port=8183`
46-
And I run `wp option update permalink_structure '/%postname%/'`
47-
And I run `wp rewrite flush`
48+
# No leading slash for Windows compatibility on CI.
49+
And I run `wp rewrite structure "%postname%/"`
4850

4951
When I run `curl -sSL http://localhost:8183/hello-world/`
5052
Then STDOUT should contain:

router.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,29 +137,34 @@ static function ( $buffer ) {
137137
// phpcs:ignore WordPress.WP.AlternativeFunctions.parse_url_parse_url
138138
$wpcli_server_path = '/' . ltrim( parse_url( urldecode( $_SERVER['REQUEST_URI'] ) )['path'], '/' );
139139

140-
if ( file_exists( $wpcli_server_root . $wpcli_server_path ) ) {
141-
if ( is_dir( $wpcli_server_root . $wpcli_server_path ) && substr( $wpcli_server_path, -1 ) !== '/' ) {
140+
$wpcli_server_file = $wpcli_server_root . $wpcli_server_path;
141+
// Normalize slashes for file operations
142+
$wpcli_server_file = str_replace( array( '/', '\\' ), DIRECTORY_SEPARATOR, $wpcli_server_file );
143+
144+
if ( file_exists( $wpcli_server_file ) ) {
145+
if ( is_dir( $wpcli_server_file ) && substr( $wpcli_server_path, -1 ) !== '/' ) {
142146
header( "Location: $wpcli_server_path/" );
143147
exit;
144148
}
145149

146150
// Check if this is a PHP file by examining the extension
147-
if ( pathinfo( $wpcli_server_path, PATHINFO_EXTENSION ) === 'php' ) {
151+
if ( pathinfo( $wpcli_server_file, PATHINFO_EXTENSION ) === 'php' ) {
148152
// Set $_SERVER variables to mimic direct access to the PHP file
149153
$_SERVER['SCRIPT_NAME'] = $wpcli_server_path;
150154
$_SERVER['PHP_SELF'] = $wpcli_server_path;
151-
$_SERVER['SCRIPT_FILENAME'] = $wpcli_server_root . $wpcli_server_path;
155+
$_SERVER['SCRIPT_FILENAME'] = $wpcli_server_file;
152156

153-
chdir( dirname( $wpcli_server_root . $wpcli_server_path ) );
154-
require_once $wpcli_server_root . $wpcli_server_path;
157+
chdir( dirname( $wpcli_server_file ) );
158+
require_once $wpcli_server_file;
155159
} else {
156160
return false;
157161
}
158162
} else {
159163
// File doesn't exist - route to index.php for pretty permalinks
160164
$_SERVER['SCRIPT_NAME'] = '/index.php';
161165
$_SERVER['PHP_SELF'] = '/index.php';
162-
$_SERVER['SCRIPT_FILENAME'] = $wpcli_server_root . '/index.php';
166+
$_SERVER['SCRIPT_FILENAME'] = $wpcli_server_root . DIRECTORY_SEPARATOR . 'index.php';
167+
$_SERVER['PATH_INFO'] = $wpcli_server_path; // Help WordPress parse request
163168

164169
chdir( $wpcli_server_root );
165170
require_once 'index.php';

0 commit comments

Comments
 (0)