Skip to content
21 changes: 21 additions & 0 deletions features/server.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,24 @@ Feature: Serve WordPress locally
When I run `curl -sS localhost:8181/license.txt > /tmp/license.txt`
And I run `cmp /tmp/license.txt license.txt`
Then STDOUT should be empty

Scenario: Access wp-login.php
Given a WP install
And I launch in the background `wp server --host=localhost --port=8182`

When I run `curl -sS http://localhost:8182/wp-login.php`
Then STDOUT should contain:
"""
wp-login.php
"""

Scenario: Pretty permalinks
Given a WP install
And I launch in the background `wp server --host=localhost --port=8183`
And I run `wp option update permalink_structure '/%postname%/'`

When I run `curl -sS http://localhost:8183/?p=1`
Then STDOUT should contain:
"""
Hello world!
"""
Comment thread
swissspidy marked this conversation as resolved.
Comment thread
swissspidy marked this conversation as resolved.
13 changes: 12 additions & 1 deletion router.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,24 @@ function ( $url ) {
exit;
}

if ( strpos( $wpcli_server_path, '.php' ) !== false ) {
// Check if this is a PHP file by examining the extension
if ( pathinfo( $wpcli_server_path, PATHINFO_EXTENSION ) === 'php' ) {
// Set $_SERVER variables to mimic direct access to the PHP file
$_SERVER['SCRIPT_NAME'] = $wpcli_server_path;
$_SERVER['PHP_SELF'] = $wpcli_server_path;
$_SERVER['SCRIPT_FILENAME'] = $wpcli_server_root . $wpcli_server_path;

chdir( dirname( $wpcli_server_root . $wpcli_server_path ) );
require_once $wpcli_server_root . $wpcli_server_path;
} else {
return false;
}
} else {
// File doesn't exist - route to index.php for pretty permalinks
$_SERVER['SCRIPT_NAME'] = '/index.php';
$_SERVER['PHP_SELF'] = '/index.php';
$_SERVER['SCRIPT_FILENAME'] = $wpcli_server_root . '/index.php';

chdir( $wpcli_server_root );
require_once 'index.php';
}
Loading