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
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!
"""
13 changes: 12 additions & 1 deletion router.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,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