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!
"""
Comment on lines +32 to +38

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The scenario is named "Pretty permalinks", but the test uses curl ... /?p=1, which is a plain permalink. This doesn't fully validate that pretty permalinks are working as intended with the new router logic for non-existent files.

To make this test more robust and accurately reflect its name, I suggest testing an actual pretty URL like /hello-world/. This will require flushing the rewrite rules after setting the permalink structure. Using curl -L is also recommended to follow any potential redirects.

    And I run `wp option update permalink_structure '/%postname%/'`
    And I run `wp rewrite flush`

    When I run `curl -sSL http://localhost:8183/hello-world/`
    Then STDOUT should contain:
      """
      Hello world!
      """

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply feedback from this feedback

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