Skip to content
Merged
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
49 changes: 49 additions & 0 deletions features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,23 @@ public function theFieldOfSiteShouldBe( $field, $site, $not, $expected )
}
}

/**
* Simulates a site record that disagrees with what nginx serves.
*
* @When /^I set the "([a-z_]+)" field of site "([^"]*)" in the database to "(.*)"$/
*/
public function iSetTheFieldOfSite( $field, $site, $value )
{
$site = $this->v( $site );
$this->assert_own_name( $site );
$row = $this->get_site_row( $site );
if ( false === $row || ! array_key_exists( $field, $row ) ) {
throw new Exception( "No $field for site $site in the EasyEngine database." );
}
$stmt = self::db()->prepare( "UPDATE sites SET $field = ? WHERE site_url = ?" );
$stmt->execute( [ $this->v( $value ), $site ] );
}

/* ----- files ----- */

/**
Expand Down Expand Up @@ -950,6 +967,38 @@ public function iWriteToTheFile( $mode, $content, $path )
}
}

/**
* @When /^I link "([^"]*)" to "([^"]*)"$/
*/
public function iLinkTo( $path, $target )
{
$path = $this->v( $path );
$this->assert_writable_path( $path );
if ( ! is_dir( dirname( $path ) ) ) {
mkdir( dirname( $path ), 0755, true );
}
if ( ! symlink( $this->v( $target ), $path ) ) {
throw new Exception( "Could not link $path" );
}
}

/**
* Puts /dev/null back before failing, so a regression can't break the rest of the run.
*
* @Then /^\/dev\/null should still be the null device$/
*/
public function devNullShouldStillBeTheNullDevice()
{
clearstatcache( true, '/dev/null' );
$stat = @lstat( '/dev/null' );
if ( $stat && 0020000 === ( $stat['mode'] & 0170000 ) && 259 === $stat['rdev'] ) {
return;
}
@unlink( '/dev/null' );
exec( 'mknod -m 666 /dev/null c 1 3' );
throw new Exception( '/dev/null was replaced (restored now): ' . var_export( $stat, true ) );
}

/**
* @When /^I remove the (?:file|directory) "([^"]*)"$/
*/
Expand Down
102 changes: 102 additions & 0 deletions features/php-compat.feature
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,108 @@ Feature: Check the PHP compatibility of a site's code
And what was appended to the file "{EE_ROOT_DIR}/logs/ee.log" since its size was noted should not contain "RemovedFunctions"
And what was appended to the file "{EE_ROOT_DIR}/logs/ee.log" since its size was noted should not contain "legacy.php"

Scenario: --output refuses /dev/null and other paths that aren't regular files, before anything runs
Given the site "bh-site-command-181.test" exists, created with "--type=php"
And I link "{TMP}/null-link" to "/dev/null"
When I run 'bin/ee site php-compat bh-site-command-181.test --php=8.4 --output=/dev/null'
Then the command should fail
And STDERR should contain "--output can't be in /dev: /dev/null"
And /dev/null should still be the null device
When I run 'bin/ee site php-compat bh-site-command-181.test --php=8.4 --output=/dev/stdout'
Then the command should fail
And STDERR should contain "--output can't be in /dev: /dev/stdout"
When I run 'bin/ee site php-compat bh-site-command-181.test --php=8.4 --output={TMP}/null-link'
Then the command should fail
And STDERR should contain "--output is not a regular file: {TMP}/null-link"
And /dev/null should still be the null device
And the symlink "{TMP}/null-link" should exist
And the docker container "ee-php-compat-bh-site-command-181.test" should not exist

@wp
Scenario: A --public-dir site whose record lost its public dir is checked where nginx serves it, from inside the site directory
Given the compat-scanner image is available
And the site "bh-site-command-185.test" exists, created with "--type=wp --public-dir=current"
And I write "<?php\n/**\n * Plugin Name: Compat Fixture\n * Version: 1.0\n */\n$f = create_function( '', 'return 1;' );\n" to the file "{SITES_DIR}/bh-site-command-185.test/app/htdocs/current/wp-content/plugins/compat-fixture/compat-fixture.php"
And I make everything under "{SITES_DIR}/bh-site-command-185.test/app/htdocs/current/wp-content/plugins/compat-fixture" readable by everyone
# The record a user's server had: nginx still serves htdocs/current.
And I set the "site_container_fs_path" field of site "bh-site-command-185.test" in the database to "/var/www/htdocs"
When I run 'cd {SITES_DIR}/bh-site-command-185.test && {EE} site php-compat --php=8.4 --format=json'
Then the command should succeed
And STDOUT should match "/^\{.*\}\n?$/"
And the JSON field "status" in STDOUT should be "ok"
And the JSON field "site" in STDOUT should be "bh-site-command-185.test"
And the JSON field "safe_to_upgrade" in STDOUT should be "false"
And STDERR should contain "EE's record of bh-site-command-185.test has /var/www/htdocs as its public directory, but nginx serves /var/www/htdocs/current"
When I run 'cd {SITES_DIR}/bh-site-command-185.test/app/htdocs && {EE} site php-compat --php=8.4 --estimate --format=json'
Then the command should succeed
And the JSON field "status" in STDOUT should be "ok"
And STDOUT should match "/"php_files":[1-9]/"
When I run 'cd {SITES_DIR}/bh-site-command-185.test && {EE} site php-compat --php=8.4'
Then the command should succeed
And STDOUT should match "/^Not safe to upgrade bh-site-command-185\.test to PHP 8\.4: /"
And STDOUT should contain "Compat Fixture 1.0 (plugin compat-fixture): 1 error"

@wp
Scenario: A nested --public-dir is checked from a directory inside the site
Given the compat-scanner image is available
And the site "bh-site-command-186.test" exists, created with "--type=wp --public-dir=/current/public/"
And I write "<?php\n/**\n * Plugin Name: Compat Fixture\n * Version: 1.0\n */\neach( $a );\n" to the file "{SITES_DIR}/bh-site-command-186.test/app/htdocs/current/public/wp-content/plugins/compat-fixture/compat-fixture.php"
And I make everything under "{SITES_DIR}/bh-site-command-186.test/app/htdocs/current/public/wp-content/plugins/compat-fixture" readable by everyone
Then the "site_container_fs_path" field of site "bh-site-command-186.test" in the database should be "/var/www/htdocs/current/public"
When I run 'cd {SITES_DIR}/bh-site-command-186.test/app/htdocs/current/public/wp-content && {EE} site php-compat --php=8.4 --format=json'
Then the command should succeed
And the JSON field "status" in STDOUT should be "ok"
And the JSON field "safe_to_upgrade" in STDOUT should be "false"
And STDERR should not contain "nginx serves"

Scenario: A php site whose record lost its public dir is checked with a warning
Given the compat-scanner image is available
And the site "bh-site-command-187.test" exists, created with "--type=php --public-dir=public"
And I write "<?php\n$f = create_function( '', 'return 1;' );\neach( $a );\n" to the file "{SITES_DIR}/bh-site-command-187.test/app/htdocs/public/legacy.php"
And I make everything under "{SITES_DIR}/bh-site-command-187.test/app/htdocs/public" readable by everyone
And I set the "site_container_fs_path" field of site "bh-site-command-187.test" in the database to "/var/www/htdocs"
When I run 'cd {SITES_DIR}/bh-site-command-187.test && {EE} site php-compat --php=8.4 --format=json'
Then the command should succeed
And the JSON field "status" in STDOUT should be "ok"
And the JSON field "errors" in STDOUT should be "2"
And STDERR should contain "but nginx serves /var/www/htdocs/public"

@wp
Scenario: A WP_CONTENT_DIR the check can't follow gives no verdict
Given the site "bh-site-command-188.test" exists, created with "--type=wp"
And I write "<?php\n/**\n * Plugin Name: Compat Fixture\n */\neach( $a );\n" to the file "{SITES_DIR}/bh-site-command-188.test/app/htdocs/content/plugins/compat-fixture/compat-fixture.php"
# Before wp-settings.php is loaded, where WordPress reads it.
When I run 'sed -i "s#^require_once ABSPATH#define( \"WP_CONTENT_DIR\", __DIR__ . \"/htdocs/content\" );\nrequire_once ABSPATH#" {SITES_DIR}/bh-site-command-188.test/app/wp-config.php'
Then the command should succeed
And the file "{SITES_DIR}/bh-site-command-188.test/app/wp-config.php" should contain "/htdocs/content"
When I run 'bin/ee site php-compat bh-site-command-188.test --php=8.4 --format=json'
Then the command should succeed
And the JSON field "status" in STDOUT should be "tool_error"
And the JSON field "safe_to_upgrade" in STDOUT should be null
And the JSON field "detail" in STDOUT should contain "WordPress loads plugins and themes from {SITES_DIR}/bh-site-command-188.test/app/htdocs/content (WP_CONTENT_DIR in {SITES_DIR}/bh-site-command-188.test/app/wp-config.php); this check can't scan that layout yet"
And the docker container "ee-php-compat-bh-site-command-188.test" should not exist
When I run 'bin/ee site php-compat bh-site-command-188.test --php=8.4'
Then the command should succeed
And STDOUT should match "/^The check of bh-site-command-188\.test for PHP 8\.4 didn't finish: WordPress loads plugins and themes from /"
And STDOUT should not contain "Safe to upgrade"

@wp
Scenario: Without wp-content the message names the directory checked, and a release layout under htdocs is found
Given the compat-scanner image is available
And the site "bh-site-command-189.test" exists, created with "--type=wp"
When I run 'mv {SITES_DIR}/bh-site-command-189.test/app/htdocs/wp-content {SITES_DIR}/bh-site-command-189.test/app/htdocs/wp-content-off'
And I run 'cd {SITES_DIR}/bh-site-command-189.test && {EE} site php-compat --php=8.4'
Then the command should succeed
And STDOUT should contain "No PHP code found to check in bh-site-command-189.test. Looked for plugins, themes and other WordPress code in {SITES_DIR}/bh-site-command-189.test/app/htdocs/wp-content. The check follows the directory nginx serves (root in {SITES_DIR}/bh-site-command-189.test/config/nginx/conf.d/main.conf)"
# A CI/CD deploy: WordPress in releases/1, current links to it, wp-cli.yml points there, the record still says htdocs.
When I run 'cd {SITES_DIR}/bh-site-command-189.test/app/htdocs && mkdir -p releases/1 && mv wp-content-off releases/1/wp-content && mv wp-admin wp-includes index.php wp-settings.php releases/1/ && ln -s /var/www/htdocs/releases/1 current && printf "path: current/\n" > wp-cli.yml'
And I write "<?php\n/**\n * Plugin Name: Compat Fixture\n */\neach( $a );\n" to the file "{SITES_DIR}/bh-site-command-189.test/app/htdocs/releases/1/wp-content/plugins/compat-fixture/compat-fixture.php"
And I make everything under "{SITES_DIR}/bh-site-command-189.test/app/htdocs/releases" readable by everyone
And I run 'cd {SITES_DIR}/bh-site-command-189.test && {EE} site php-compat --php=8.4 --format=json'
Then the command should succeed
And the JSON field "status" in STDOUT should be "ok"
And the JSON field "safe_to_upgrade" in STDOUT should be "false"

Scenario: An html site is refused
Given the html site "bh-site-command-182.test" exists
When I run 'bin/ee site php-compat bh-site-command-182.test --php=8.4'
Expand Down
2 changes: 1 addition & 1 deletion src/helper/Site_Backup_Restore.php
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ private function get_wp_root_rel( $real = true ) {
$rel = trim( str_replace( '/var/www/', '', $this->site_data['site_container_fs_path'] ), '/' );
$app_dir = $this->get_site_app_dir();

foreach ( [ $rel, $rel . '/current' ] as $candidate ) {
foreach ( \EE\Site\Utils\get_wp_root_candidates( $rel ) as $candidate ) {
if ( ! $this->fs->exists( $app_dir . '/' . $candidate . '/wp-content' ) ) {
continue;
}
Expand Down
Loading