diff --git a/CHANGELOG.md b/CHANGELOG.md index ae58a8b07..1b4e27f27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [unreleased] Unreleased +### Changed + +- Fix non standard installation handling, hello Bedrock! (#716) + ## [4.1.6] 2024-04-07; ### Changed diff --git a/bin/update_sqlite_plugin b/bin/update_sqlite_plugin index f7724f1aa..e29fa6719 100755 --- a/bin/update_sqlite_plugin +++ b/bin/update_sqlite_plugin @@ -11,4 +11,5 @@ unzip -o "$root_dir/includes/sqlite-database-integration.zip" -d "$root_dir/incl # Remove the zip file rm "$root_dir/includes/sqlite-database-integration.zip" git apply "${root_dir}"/config/patches/sqlite-database-integration/db.copy.patch +git apply "${root_dir}"/config/patches/sqlite-database-integration/load.php.patch diff --git a/config/patches/sqlite-database-integration/load.php.patch b/config/patches/sqlite-database-integration/load.php.patch new file mode 100644 index 000000000..ca7363978 --- /dev/null +++ b/config/patches/sqlite-database-integration/load.php.patch @@ -0,0 +1,15 @@ +diff --git a/includes/sqlite-database-integration/load.php b/includes/sqlite-database-integration/load.php +index 3af80903..ddc5a9b6 100644 +--- a/includes/sqlite-database-integration/load.php ++++ b/includes/sqlite-database-integration/load.php +@@ -12,7 +12,9 @@ + * @package wp-sqlite-integration + */ + +-define( 'SQLITE_MAIN_FILE', __FILE__ ); ++if (!defined('SQLITE_MAIN_FILE')) { ++ define('SQLITE_MAIN_FILE', __FILE__); ++} + + require_once __DIR__ . '/admin-page.php'; + require_once __DIR__ . '/activate.php'; diff --git a/docs/modules/WPLoader.md b/docs/modules/WPLoader.md index 5c541e98c..31523f0e9 100644 --- a/docs/modules/WPLoader.md +++ b/docs/modules/WPLoader.md @@ -48,7 +48,10 @@ When used in this mode, the module supports the following configuration paramete `WP_PLUGIN_DIR` constant. * `plugins` - a list of plugins to activate and load in the WordPress installation. Each plugin must be specified in a format like `hello.php` or `my-plugin/my-plugin.php` format. -* `silentlyActivatePlugins` - a list of plugins to activate **silently**, without firing their activation hooks. Depending on the plugin, a silent activation might cause the plugin to not work correctly. The list must be in the same format as the `plugins` parameter and plugin should be activated silently only if they are not working correctly during normal activation and are known to work correctly when activated silently. +* `silentlyActivatePlugins` - a list of plugins to activate **silently**, without firing their activation hooks. + Depending on the plugin, a silent activation might cause the plugin to not work correctly. The list must be in the + same format as the `plugins` parameter and plugin should be activated silently only if they are not working correctly + during normal activation and are known to work correctly when activated silently. * `bootstrapActions` - a list of actions or callables to call **after** WordPress is loaded and before the tests run. * `theme` - the theme to activate and load in the WordPress installation. The theme must be specified in slug format like @@ -83,11 +86,29 @@ When used in this mode, the module supports the following configuration paramete * `WP_HTTP_BLOCK_EXTERNAL` - the `WP_HTTP_BLOCK_EXTERNAL` constant value to use when loading WordPress. If the `wpRootFolder` path points at a configured installation, containing the `wp-config.php` file, then the value of the constant in the configuration file will be used, else it will be randomly generated. -* `backupGlobals` - a boolean value to indicate if the global environment should be backed up before each test. Defaults to `true`. The globals' backup involves serialization of the global state, plugins or themes that define classes developed to prevent serialization of the global state will cause the tests to fail. Set this parameter to `false` to disable the global environment backup, or use a more refined approach setting the `backupGlobalsExcludeList` parameter below. Note that a test case that is explicitly setting the `backupGlobals` property will override this configuration parameter. -* `backupGlobalsExcludeList` - a list of global variables to exclude from the global environment backup. The list must be in the form of array, and it will be merged to the list of globals excluded by default. -* `backupStaticAttributes` - a boolean value to indicate if static attributes of classes should be backed up before each test. Defaults to `true`. The static attributes' backup involves serialization of the global state, plugins or themes that define classes developed to prevent serialization of the global state will cause the tests to fail. Set this parameter to `false` to disable the static attributes backup, or use a more refined approanch setting the `backupStaticAttributesExcludeList` parameter below. Note that a test case that is explicitly setting the `backupStaticAttributes` property will override this configuration parameter. -* `backupStaticAttributesExcludeList` - a list of classes to exclude from the static attributes backup. The list must be in the form of map from class names to the array of method names to exclude from the backup. See an example below. -* `skipInstall` - a boolean value to indicate if the WordPress installation should be skipped between runs, when already installed. Defaults to `false`. During boot, the `WPLoader` module will re-install WordPress and activate, on top of the fresh installation, any plugin and theme specified in the `plugins` and `theme` configuration parameters: this can be a time-consuming operation. Set this parameter to `true` to run the WordPress installation once and just load it on the following runs. To force the installation to run again, rerun the suite using the WPLoader module using the `--debug` flag or delete the `_wploader-state.sql` file in the suite directory. This configuration parameter is ignored when the `loadOnly` parameter is set to `true`. +* `backupGlobals` - a boolean value to indicate if the global environment should be backed up before each test. Defaults + to `true`. The globals' backup involves serialization of the global state, plugins or themes that define classes + developed to prevent serialization of the global state will cause the tests to fail. Set this parameter to `false` to + disable the global environment backup, or use a more refined approach setting the `backupGlobalsExcludeList` parameter + below. Note that a test case that is explicitly setting the `backupGlobals` property will override this configuration + parameter. +* `backupGlobalsExcludeList` - a list of global variables to exclude from the global environment backup. The list must + be in the form of array, and it will be merged to the list of globals excluded by default. +* `backupStaticAttributes` - a boolean value to indicate if static attributes of classes should be backed up before each + test. Defaults to `true`. The static attributes' backup involves serialization of the global state, plugins or themes + that define classes developed to prevent serialization of the global state will cause the tests to fail. Set this + parameter to `false` to disable the static attributes backup, or use a more refined approanch setting + the `backupStaticAttributesExcludeList` parameter below. Note that a test case that is explicitly setting + the `backupStaticAttributes` property will override this configuration parameter. +* `backupStaticAttributesExcludeList` - a list of classes to exclude from the static attributes backup. The list must be + in the form of map from class names to the array of method names to exclude from the backup. See an example below. +* `skipInstall` - a boolean value to indicate if the WordPress installation should be skipped between runs, when already + installed. Defaults to `false`. During boot, the `WPLoader` module will re-install WordPress and activate, on top of + the fresh installation, any plugin and theme specified in the `plugins` and `theme` configuration parameters: this can + be a time-consuming operation. Set this parameter to `true` to run the WordPress installation once and just load it on + the following runs. To force the installation to run again, rerun the suite using the WPLoader module using + the `--debug` flag or delete the `_wploader-state.sql` file in the suite directory. This configuration parameter is + ignored when the `loadOnly` parameter is set to `true`. This is an example of an integration suite configured to use the module: @@ -159,7 +180,8 @@ modules: theme: twentytwentythree ``` -The follow example configuration prevents the backup of globals and static attributes in all the tests of the suite that are not explicitly overriding the `backupGlobals` and `backupStaticAttributes` properties: +The follow example configuration prevents the backup of globals and static attributes in all the tests of the suite that +are not explicitly overriding the `backupGlobals` and `backupStaticAttributes` properties: ```yaml actor: IntegrationTester @@ -219,45 +241,16 @@ modules: - instance - anotherStaticAttributeThatWillExplodeOnWakeup - AnotherPlugin\AnotherClass: - - instance - - yetAnotherStaticAttributeThatWillExplodeOnWakeup + - instance + - yetAnotherStaticAttributeThatWillExplodeOnWakeup ``` ### Handling a custom site structure -If you're working on a site project using a custom file structure, e.g. [Bedrock][4], you should -use [a custom configuration](./../custom-configuration.md) and, together with that, configure the `WPLoader` module to -load WordPress, plugins and themes code from the correct locations. -Take care to point the `wpRootFolder` parameter to the directory containing the `wp-load.php` file, -the `/var/my-site/web/wp` one in the following example, and the module will read the project configuration file to load -the WordPress code from the correct location. - -Here's an example of how the module should be configured to run integration tests on a Bedrock installation: - -```yaml -actor: IntegrationTester -bootstrap: _bootstrap.php -modules: - enabled: - - \Helper\Integration - - lucatume\WPBrowser\Module\WPLoader: - wpRootFolder: /var/my-site/web/wp - dbUrl: mysql://root:root@mysql:3306/wordpress - tablePrefix: test_ - domain: my-project.test - adminEmail: admin@my-project.test - title: 'Integration Tests' - plugins: - - hello.php - - woocommerce/woocommerce.php - - my-plugin/my-plugin.php - theme: twentytwentythree -``` +The setup process should _just work_ for standard and non-standard WordPress installations alike. -In general, pointing the `wpRootFolder` parameter to the directory containing the `wp-load.php` file should take care of -loading WordPress code from the correct location. -Should that not be the case, use the `configFile` parameter to point the module to the project test configuration file: -a PHP file defining the constants and environment variables to use to load WordPress, plugins and themes correctly. +Even if you're working on a site project using a custom file structure, e.g. [Bedrock][4], you will be able to set up +your site to run tests using the default configuration based on PHP built-in server, Chromedriver and SQLite database. ## Configuration with loadOnly: true @@ -330,23 +323,26 @@ The module provides the following methods: #### factory -Signature: `factory()` : `lucatume\WPBrowser\Module\WPLoader\FactoryStore` + +Signature: `factory()` : `lucatume\WPBrowser\Module\WPLoader\FactoryStore` Accessor method to get the object storing the factories for things. This method gives access to the same factories provided by the [Core test suite](https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/). #### getContentFolder -Signature: `getContentFolder([string $path])` : `string` + +Signature: `getContentFolder([string $path])` : `string` Returns the absolute path to the WordPress content directory. #### getInstallation -Signature: `getInstallation()` : `lucatume\WPBrowser\WordPress\Installation` +Signature: `getInstallation()` : `lucatume\WPBrowser\WordPress\Installation` #### getPluginsFolder -Signature: `getPluginsFolder([string $path])` : `string` + +Signature: `getPluginsFolder([string $path])` : `string` Returns the absolute path to the plugins directory. @@ -354,12 +350,14 @@ The value will first look at the `WP_PLUGIN_DIR` constant, then the `pluginsFold and will, finally, look in the default path from the WordPress root directory. #### getThemesFolder -Signature: `getThemesFolder([string $path])` : `string` + +Signature: `getThemesFolder([string $path])` : `string` Returns the absolute path to the themes directory. #### getWpRootFolder -Signature: `getWpRootFolder([?string $path])` : `string` + +Signature: `getWpRootFolder([?string $path])` : `string` Returns the absolute path to the WordPress root folder or a path within it.. diff --git a/includes/cli-server/router.php b/includes/cli-server/router.php index 43b38258b..c06acacb6 100644 --- a/includes/cli-server/router.php +++ b/includes/cli-server/router.php @@ -5,40 +5,57 @@ */ $root = $_SERVER['DOCUMENT_ROOT']; -$path = '/'. ltrim( parse_url( urldecode( $_SERVER['REQUEST_URI'] ),PHP_URL_PATH ), '/' ); +$path = '/' . ltrim(parse_url(urldecode($_SERVER['REQUEST_URI']), PHP_URL_PATH), '/'); define('DB_ENGINE', getenv('DB_ENGINE') ?: 'mysql'); // Add a unique request ID to the headers. -$requestId = md5( microtime() ); +$requestId = md5(microtime()); $_SERVER['REQUEST_ID'] = $requestId; -header( 'X-Request-ID: ' . $requestId ); +header('X-Request-ID: ' . $requestId); // Disable the MU upgrade routine. global $wp_filter; $wp_filter['do_mu_upgrade'][10][] = [ 'accepted_args' => 0, - 'function' => '__return_false' + 'function' => '__return_false' ]; - -if ( file_exists( $root.$path ) ) { - - // Enforces trailing slash, keeping links tidy in the admin - if ( is_dir( $root.$path ) && ! str_ends_with( $path, '/' ) ) { - header( "Location: $path/" ); - exit; - } - - // Runs PHP file if it exists - if ( str_contains( $path, '.php' ) ) { - chdir( dirname( $root.$path ) ); - require_once $root.$path; - } else { - return false; - } +$wpbrowserSiteurl = getenv('WPBROWSER_SITEURL'); +$wpbrowserHomeUrl = getenv('WPBROWSER_HOMEURL'); +if ($wpbrowserSiteurl) { + $wp_filter['option_siteurl'][1000][] = [ + 'accepted_args' => 0, + 'function' => function () use ($wpbrowserSiteurl) { + return $wpbrowserSiteurl; + } + ]; +} +if (getenv('WPBROWSER_HOMEURL')) { + $wp_filter['option_home'][1000][] = [ + 'accepted_args' => 0, + 'function' => function () use ($wpbrowserHomeUrl) { + return $wpbrowserHomeUrl; + } + ]; +} +unset($wpbrowserSiteurl, $wpbrowserHomeUrl); + +if (file_exists($root . $path)) { + // Enforces trailing slash, keeping links tidy in the admin + if (is_dir($root . $path) && !str_ends_with($path, '/')) { + header("Location: $path/"); + exit; + } + + // Runs PHP file if it exists + if (str_contains($path, '.php')) { + chdir(dirname($root . $path)); + require_once $root . $path; + } else { + return false; + } } else { - - // Otherwise, run `index.php` - chdir( $root ); - require_once 'index.php'; + // Otherwise, run `index.php` + chdir($root); + require_once 'index.php'; } diff --git a/includes/sqlite-database-integration/load.php b/includes/sqlite-database-integration/load.php index 3af809035..ddc5a9b6c 100644 --- a/includes/sqlite-database-integration/load.php +++ b/includes/sqlite-database-integration/load.php @@ -12,7 +12,9 @@ * @package wp-sqlite-integration */ -define( 'SQLITE_MAIN_FILE', __FILE__ ); +if (!defined('SQLITE_MAIN_FILE')) { + define('SQLITE_MAIN_FILE', __FILE__); +} require_once __DIR__ . '/admin-page.php'; require_once __DIR__ . '/activate.php'; diff --git a/src/Project/SiteProject.php b/src/Project/SiteProject.php index 949add442..412edd088 100644 --- a/src/Project/SiteProject.php +++ b/src/Project/SiteProject.php @@ -12,6 +12,7 @@ use lucatume\WPBrowser\Exceptions\RuntimeException; use lucatume\WPBrowser\Extension\BuiltInServerController; use lucatume\WPBrowser\Extension\ChromeDriverController; +use lucatume\WPBrowser\Template\Wpbrowser; use lucatume\WPBrowser\Utils\ChromedriverInstaller; use lucatume\WPBrowser\Utils\Codeception; use lucatume\WPBrowser\Utils\Filesystem as FS; @@ -47,7 +48,7 @@ public function __construct(InputInterface $input, OutputInterface $output, prot ); } - $suggest = "Make sure you're initializing wp-browser at the root of your site project,". + $suggest = "Make sure you're initializing wp-browser at the root of your site project," . " and that the directory contains the WordPress files and a wp-config.php file."; if ($installationState instanceof EmptyDir) { @@ -95,7 +96,8 @@ public function setup(): void } $contentDir = $this->installation->getContentDir(); - Installation::placeSqliteMuPlugin($this->installation->getMuPluginsDir(), $contentDir); + $dropInPath = Installation::placeSqliteMuPlugin($this->installation->getMuPluginsDir(), $contentDir); + Wpbrowser::setDropInPath($dropInPath); $this->sayInfo('SQLite drop-in placed, installing WordPress ...'); $serverLocalhostPort = Random::openLocalhostPort(); @@ -141,6 +143,22 @@ public function setup(): void EOT; + $docRootEnvVar = "%WORDPRESS_ROOT_DIR%"; + $docRoot = dirname($this->installation->getWpConfigFilePath()); + $siteUrlRelativePath = ''; + $wpRootDir = $this->installation->getWpRootDir(); + if ($docRoot !== rtrim($wpRootDir, '/')) { + $docRootRelativePath = FS::relativePath($this->workDir, $docRoot); + $docRootEnvVar = '%WORDPRESS_DOCROOT%'; + $siteUrlRelativePath = rtrim('/' . ltrim(FS::relativePath($docRoot, $wpRootDir), '/'), '/'); + $this->testEnvironment->extraEnvFileContents .= <<testEnvironment->extensionsEnabled = [ ChromeDriverController::class => [ 'port' => "%CHROMEDRIVER_PORT%", @@ -148,12 +166,14 @@ public function setup(): void BuiltInServerController::class => [ 'workers' => 5, 'port' => "%BUILTIN_SERVER_PORT%", - 'docroot' => "%WORDPRESS_ROOT_DIR%", + 'docroot' => $docRootEnvVar, 'env' => [ 'DATABASE_TYPE' => 'sqlite', 'DB_ENGINE' => 'sqlite', 'DB_DIR' => '%codecept_root_dir%' . DIRECTORY_SEPARATOR . $dataDirRelativePath, - 'DB_FILE' => 'db.sqlite' + 'DB_FILE' => 'db.sqlite', + 'WPBROWSER_SITEURL' => '%WORDPRESS_URL%' . $siteUrlRelativePath, + 'WPBROWSER_HOMEURL' => '%WORDPRESS_URL%' ] ] @@ -163,7 +183,8 @@ public function setup(): void $this->testEnvironment->customCommands[] = DevInfo::class; $this->testEnvironment->customCommands[] = DevRestart::class; $this->testEnvironment->customCommands[] = ChromedriverUpdate::class; - $this->testEnvironment->wpRootDir = '.'; + $this->testEnvironment->wpRootDir = FS::relativePath($this->workDir, $wpRootDir) ?: '.'; + $this->testEnvironment->wpAdminPath = '/' . ltrim(FS::relativePath($docRoot, $wpRootDir . '/wp-admin'), '/'); $this->testEnvironment->dbUrl = 'sqlite://' . implode( DIRECTORY_SEPARATOR, ['%codecept_root_dir%', $dataDirRelativePath, 'db.sqlite'] @@ -182,7 +203,7 @@ public function getTestEnv(): ?TestEnvironment private function getName(): string { - return basename(dirname($this->workDir)); + return basename($this->workDir); } private function scaffoldEndToEndActivationCest(): void diff --git a/src/Project/TestEnvironment.php b/src/Project/TestEnvironment.php index d20b57dd4..cc265498a 100644 --- a/src/Project/TestEnvironment.php +++ b/src/Project/TestEnvironment.php @@ -12,6 +12,7 @@ class TestEnvironment public string $wpTablePrefix = 'wp_'; public string $wpUrl = 'http://wordpress.test'; public string $wpDomain = 'wordpress.test'; + public string $wpAdminPath = '/wp-admin'; public string $wpAdminUser = 'admin'; public string $wpAdminPassword = 'password'; public string $chromeDriverHost = 'localhost'; diff --git a/src/Template/Wpbrowser.php b/src/Template/Wpbrowser.php index bfc726d02..693411849 100644 --- a/src/Template/Wpbrowser.php +++ b/src/Template/Wpbrowser.php @@ -25,6 +25,7 @@ class Wpbrowser extends Bootstrap { private ?TestEnvironment $testEnvironment = null; + private static string $dropInPath = ''; /** * @throws RuntimeException @@ -205,6 +206,7 @@ private function createEnvFile(): void # The URL and domain of the WordPress site used in end-to-end tests. WORDPRESS_URL={$testEnv->wpUrl} WORDPRESS_DOMAIN={$testEnv->wpDomain} +WORDPRESS_ADMIN_PATH={$testEnv->wpAdminPath} # The username and password of the administrator user of the WordPress site used in end-to-end tests. WORDPRESS_ADMIN_USER={$testEnv->wpAdminUser} @@ -247,7 +249,7 @@ private function createEndToEndSuite(ProjectInterface $project): void url: '%WORDPRESS_URL%' adminUsername: '%WORDPRESS_ADMIN_USER%' adminPassword: '%WORDPRESS_ADMIN_PASSWORD%' - adminPath: '/wp-admin' + adminPath: '%WORDPRESS_ADMIN_PATH%' browser: chrome host: '%CHROMEDRIVER_HOST%' port: '%CHROMEDRIVER_PORT%' @@ -275,10 +277,10 @@ private function createEndToEndSuite(ProjectInterface $project): void wpRootFolder: '%WORDPRESS_ROOT_DIR%' lucatume\WPBrowser\Module\WPLoader: loadOnly: true - wpRootFolder: "%WORDPRESS_ROOT_DIR%" + wpRootFolder: '%WORDPRESS_ROOT_DIR%' dbUrl: '%WORDPRESS_DB_URL%' domain: '%WORDPRESS_DOMAIN%' - + EOF; $this->createSuite('EndToEnd', 'EndToEnd', $suiteConfig); $bootstrapContents = <<input, $this->output, $workDir); } + public static function setDropInPath(string $path): void + { + self::$dropInPath = $path; + } + protected function cleanUpOnFail(): void { FS::rrmdir($this->workDir . '/tests'); if (is_file($this->workDir . '/codeception.yml')) { @unlink($this->workDir . '/codeception.yml'); } + + if (self::$dropInPath && file_exists(self::$dropInPath)) { + @unlink(self::$dropInPath); + } } } diff --git a/src/WordPress/CodeExecution/InstallAction.php b/src/WordPress/CodeExecution/InstallAction.php index 2bab63e7d..758a2ca4f 100644 --- a/src/WordPress/CodeExecution/InstallAction.php +++ b/src/WordPress/CodeExecution/InstallAction.php @@ -4,10 +4,15 @@ use Closure; use lucatume\WPBrowser\WordPress\FileRequests\FileRequest; +use lucatume\WPBrowser\WordPress\Traits\WordPressChecks; +use lucatume\WPBrowser\WordPress\WPConfigFile; + use function wp_slash; class InstallAction implements CodeExecutionActionInterface { + use WordPressChecks; + private FileRequest $request; public function __construct( @@ -24,7 +29,7 @@ public function __construct( ->setTargetFile($wpRootDir . '/wp-load.php') ->defineConstant('WP_INSTALLING', true) ->defineConstant('MULTISITE', false) - ->addPreloadClosure(function () use ($url): void { + ->addPreloadClosure(function (): void { // The `MULTISITE` const might be already defined in the `wp-config.php` file. // If that is the case, silence the error. set_error_handler(static function ($errno, $errstr): bool { @@ -39,12 +44,18 @@ public function __construct( // Plug the `wp_mail` function to avoid the sending of emails. require_once dirname(__DIR__, 3) . '/includes/pluggables/function-wp-mail.php'; - - if (!defined('WP_SITEURL')) { - define('WP_SITEURL', $url); - } }) ->addAfterLoadClosure(fn() => $this->installWordPress($title, $adminUser, $adminPassword, $adminEmail)); + + // Define the `WP_SITEURL` constant if not already defined in the wp-config.php file. + $wpConfigFilePath = $this->findWpConfigFilePath($wpRootDir); + if ($wpConfigFilePath) { + $wpConfigFile = new WPConfigFile($wpRootDir, $wpConfigFilePath); + if (!$wpConfigFile->getConstant('WP_SITEURL')) { + $request->defineConstant('WP_SITEURL', $url); + } + } + $this->request = $request; } diff --git a/src/WordPress/FileRequests/FileRequest.php b/src/WordPress/FileRequests/FileRequest.php index 3fbf2445d..7cedc44aa 100644 --- a/src/WordPress/FileRequests/FileRequest.php +++ b/src/WordPress/FileRequests/FileRequest.php @@ -126,8 +126,10 @@ public function execute(): array PreloadFilters::addFilter($hookName, $callback, $priority, $acceptedArgs); } - // Reveal the errors. - define('WP_DISABLE_FATAL_ERROR_HANDLER', true); + // Reveal the errors: disable the fatal error handler. + PreloadFilters::addFilter('wp_fatal_error_handler_enabled', function () { + return false; + }, 1000); // Set up the cookie jar. foreach ($this->cookieJar as $key => $value) { diff --git a/src/WordPress/Installation.php b/src/WordPress/Installation.php index 49ed0fad8..f553458d0 100644 --- a/src/WordPress/Installation.php +++ b/src/WordPress/Installation.php @@ -83,13 +83,14 @@ public static function getCleanScaffoldedInstallations(): array /** * @throws InstallationException */ - public static function placeSqliteMuPlugin(string $muPluginsDir, string $contentDir): void + public static function placeSqliteMuPlugin(string $muPluginsDir, string $contentDir): string { - if (self::hasSqliteDropin($contentDir . '/db.php')) { - return; + $dropinPathname = $contentDir . '/db.php'; + if (self::hasSqliteDropin($dropinPathname)) { + return $dropinPathname; } - if (is_file($contentDir . '/db.php')) { + if (is_file($dropinPathname)) { throw new InstallationException( "The db.php file already exists in the $contentDir directory and it's not a SQLite drop-in.", InstallationException::DB_DROPIN_ALREADY_EXISTS @@ -131,7 +132,7 @@ public static function placeSqliteMuPlugin(string $muPluginsDir, string $content $dbCopyContents ); - if (!file_put_contents($contentDir . '/db.php', $updatedContents, LOCK_EX)) { + if (!file_put_contents($dropinPathname, $updatedContents, LOCK_EX)) { throw new InstallationException( "Could not write the SQLite db.php file at $contentDir.", InstallationException::SQLITE_DROPIN_COPY_FAILED @@ -147,6 +148,8 @@ public static function placeSqliteMuPlugin(string $muPluginsDir, string $content InstallationException::SQLITE_DROPIN_COPY_FAILED ); } + + return $dropinPathname; } /** diff --git a/src/WordPress/Traits/WordPressChecks.php b/src/WordPress/Traits/WordPressChecks.php index 19c8d9208..7bccb55d7 100644 --- a/src/WordPress/Traits/WordPressChecks.php +++ b/src/WordPress/Traits/WordPressChecks.php @@ -33,7 +33,6 @@ private function checkWPRootDir(string $wpRootDir): string return $wpRootDir; } - private function findWpConfigFilePath(string $rootDir): string|false { $wpConfigFile = rtrim($rootDir, '\\/') . '/wp-config.php'; diff --git a/tests/_support/_generated/WploaderTesterActions.php b/tests/_support/_generated/WploaderTesterActions.php index bf0e9a02b..78c4ba56a 100644 --- a/tests/_support/_generated/WploaderTesterActions.php +++ b/tests/_support/_generated/WploaderTesterActions.php @@ -1,4 +1,4 @@ - $this->replaceRandomPorts(...func_get_args()) ); } + + /** + * It should scaffold correctly on site with non default structure using default configuration + * + * @test + */ + public function should_scaffold_correctly_on_site_with_non_default_structure_using_default_configuration(): void + { + if (PHP_VERSION < 8.0) { + $this->markTestSkipped('This test requires PHP 8.0 or higher.'); + } + + $projectDir = FS::tmpDir('setup_'); + $dbName = Random::dbName(); + $dbHost = Env::get('WORDPRESS_DB_HOST'); + $dbUser = Env::get('WORDPRESS_DB_USER'); + $dbPassword = Env::get('WORDPRESS_DB_PASSWORD'); + $db = new MysqlDatabase($dbName, $dbUser, $dbPassword, $dbHost, 'test_'); + (new BedrockProject($db, 'https://the-project.local'))->scaffold($projectDir); + + $this->mockComposerBin($projectDir); + + $command = [ + PHP_BINARY, + codecept_root_dir("vendor/bin/codecept"), + 'init', + 'wpbrowser', + '--path=' . $projectDir + ]; + $process = new Process($command); + + + $process->setInput( + "yes\n" // Yes, use recommended setup. + ); + + $process->mustRun(); + + // Remove some hashed files. + FS::rrmdir($projectDir . '/' . Codeception::supportDir() . '/_generated'); + FS::rrmdir($projectDir . '/' . Codeception::dataDir() . '/db.sqlite'); + FS::rrmdir($projectDir . '/' . Codeception::dataDir() . '/dump.sql'); + + // Random ports will change: visit the data to replace the random ports with a placeholder. + $this->assertMatchesDirectorySnapshot( + $projectDir . '/tests', + fn() => $this->replaceRandomPorts(...func_get_args()) + ); + } } diff --git a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_correctly_on_site_with_non_default_structure__0.snapshot b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_correctly_on_site_with_non_default_structure__0.snapshot index c3678a437..680e49321 100644 --- a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_correctly_on_site_with_non_default_structure__0.snapshot +++ b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_correctly_on_site_with_non_default_structure__0.snapshot @@ -16,7 +16,7 @@ modules: url: '%WORDPRESS_URL%' adminUsername: '%WORDPRESS_ADMIN_USER%' adminPassword: '%WORDPRESS_ADMIN_PASSWORD%' - adminPath: '/wp-admin' + adminPath: '%WORDPRESS_ADMIN_PATH%' browser: chrome host: '%CHROMEDRIVER_HOST%' port: '%CHROMEDRIVER_PORT%' @@ -44,10 +44,10 @@ modules: wpRootFolder: '%WORDPRESS_ROOT_DIR%' lucatume\WPBrowser\Module\WPLoader: loadOnly: true - wpRootFolder: "%WORDPRESS_ROOT_DIR%" + wpRootFolder: '%WORDPRESS_ROOT_DIR%' dbUrl: '%WORDPRESS_DB_URL%' domain: '%WORDPRESS_DOMAIN%' - + <<< /EndToEnd.suite.yml <<< >>> /Integration/_bootstrap.php >>> @@ -199,6 +199,7 @@ WORDPRESS_TABLE_PREFIX=wp_ # The URL and domain of the WordPress site used in end-to-end tests. WORDPRESS_URL=http://wordpress.test WORDPRESS_DOMAIN=wordpress.test +WORDPRESS_ADMIN_PATH=/wp-admin # The username and password of the administrator user of the WordPress site used in end-to-end tests. WORDPRESS_ADMIN_USER=admin diff --git a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_correctly_on_site_with_non_default_structure_using_default_configuration__0.snapshot b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_correctly_on_site_with_non_default_structure_using_default_configuration__0.snapshot new file mode 100644 index 000000000..62ce0a039 --- /dev/null +++ b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_correctly_on_site_with_non_default_structure_using_default_configuration__0.snapshot @@ -0,0 +1,294 @@ +>>> /EndToEnd.suite.yml >>> +# Integration suite configuration +# +# Run integration and "WordPress unit" tests. + +actor: EndToEndTester +bootstrap: _bootstrap.php +modules: + enabled: + - lucatume\WPBrowser\Module\WPWebDriver + - lucatume\WPBrowser\Module\WPDb + - lucatume\WPBrowser\Module\WPFilesystem + - lucatume\WPBrowser\Module\WPLoader + config: + lucatume\WPBrowser\Module\WPWebDriver: + url: '%WORDPRESS_URL%' + adminUsername: '%WORDPRESS_ADMIN_USER%' + adminPassword: '%WORDPRESS_ADMIN_PASSWORD%' + adminPath: '%WORDPRESS_ADMIN_PATH%' + browser: chrome + host: '%CHROMEDRIVER_HOST%' + port: '%CHROMEDRIVER_PORT%' + path: '/' + window_size: 1200x1000 + capabilities: + "goog:chromeOptions": + args: + - "--headless" + - "--disable-gpu" + - "--disable-dev-shm-usage" + - "--proxy-server='direct://'" + - "--proxy-bypass-list=*" + - "--no-sandbox" + lucatume\WPBrowser\Module\WPDb: + dbUrl: '%WORDPRESS_DB_URL%' + dump: 'tests/Support/Data/dump.sql' + populate: true + cleanup: true + reconnect: false + url: '%WORDPRESS_URL%' + urlReplacement: false + tablePrefix: '%WORDPRESS_TABLE_PREFIX%' + lucatume\WPBrowser\Module\WPFilesystem: + wpRootFolder: '%WORDPRESS_ROOT_DIR%' + lucatume\WPBrowser\Module\WPLoader: + loadOnly: true + wpRootFolder: '%WORDPRESS_ROOT_DIR%' + dbUrl: '%WORDPRESS_DB_URL%' + domain: '%WORDPRESS_DOMAIN%' + +<<< /EndToEnd.suite.yml <<< + +>>> /Integration/SampleTest.php >>> +post->create_and_get(); + + $this->assertInstanceOf(\WP_Post::class, $post); + } + + public function test_default_users(): void + { + $this->assertEquals(0, wp_get_current_user()->ID); + + wp_set_current_user(1); + + $this->assertEquals(1, wp_get_current_user()->ID); + $this->assertEquals('admin', wp_get_current_user()->user_login); + } +} +<<< /Integration/SampleTest.php <<< + +>>> /Integration/_bootstrap.php >>> +>> /Integration.suite.yml >>> +# Integration suite configuration +# +# Run integration and "WordPress unit" tests. + +actor: IntegrationTester +bootstrap: _bootstrap.php +modules: + enabled: + - lucatume\WPBrowser\Module\WPLoader + config: + lucatume\WPBrowser\Module\WPLoader: + wpRootFolder: "%WORDPRESS_ROOT_DIR%" + dbUrl: '%WORDPRESS_DB_URL%' + wpDebug: true + tablePrefix: '%TEST_TABLE_PREFIX%' + domain: '%WORDPRESS_DOMAIN%' + adminEmail: 'admin@%WORDPRESS_DOMAIN%' + title: 'Integration Tests' + plugins: [] + theme: '' +<<< /Integration.suite.yml <<< + +>>> /Support/IntegrationTester.php >>> +>> /Support/EndToEndTester.php >>> +>> /Support/Data/.gitkeep >>> + +<<< /Support/Data/.gitkeep <<< + +>>> /EndToEnd/_bootstrap.php >>> +` command + * to run WP-CLI commands on the WordPress site and database used by the EndToEnd suite. + * E.g.: + * `vendor/bin/codecept wp:cli EndToEnd db import tests/Support/Data/dump.sql` to load dump file. + * `vendor/bin/codecept wp:cli EndToEnd plugin activate woocommerce` to activate the WooCommerce plugin. + * `vendor/bin/codecept wp:cli EndToEnd user create alice alice@example.com --role=administrator` to create a new user. + * `vendor/bin/codecept wp:cli EndToEnd db export tests/Support/Data/dump.sql` to update the dump file. + */ +<<< /EndToEnd/_bootstrap.php <<< + +>>> /EndToEnd/ActivationCest.php >>> +amOnPage('/'); + $I->seeElement('body'); + } + + public function test_can_login_as_admin(EndToEndTester $I): void + { + $I->loginAsAdmin(); + $I->amOnAdminPage('/'); + $I->seeElement('body.wp-admin'); + } +} + +<<< /EndToEnd/ActivationCest.php <<< + +>>> /.env >>> +# The path to the WordPress root directory, the one containing the wp-load.php file. +# This can be a relative path from the directory that contains the codeception.yml file, +# or an absolute path. +WORDPRESS_ROOT_DIR=web/wp + +# Tests will require a MySQL database to run. +# The database will be created if it does not exist. +# Do not use a database that contains important data! +WORDPRESS_DB_URL=sqlite://%codecept_root_dir%/tests/Support/Data/db.sqlite + +# The Integration suite will use this table prefix for the WordPress tables. +TEST_TABLE_PREFIX=test_ + +# This table prefix used by the WordPress site in end-to-end tests. +WORDPRESS_TABLE_PREFIX=wp_ + +# The URL and domain of the WordPress site used in end-to-end tests. +WORDPRESS_URL=http://localhost:24423 +WORDPRESS_DOMAIN=localhost:24423 +WORDPRESS_ADMIN_PATH=/wp/wp-admin + +# The username and password of the administrator user of the WordPress site used in end-to-end tests. +WORDPRESS_ADMIN_USER=admin +WORDPRESS_ADMIN_PASSWORD=password + +# The host and port of the ChromeDriver server that will be used in end-to-end tests. +CHROMEDRIVER_HOST=localhost +CHROMEDRIVER_PORT=17558 + +# The port on which the PHP built-in server will serve the WordPress installation. +BUILTIN_SERVER_PORT=24423 + +# The path to the directory that should be served on localhost, the one containing the wp-config.php file. +WORDPRESS_DOCROOT=web + +<<< /.env <<< + +>>> /_output/.gitignore >>> +* +!.gitignore + +<<< /_output/.gitignore <<< \ No newline at end of file diff --git a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_child_theme_correctly__0.snapshot b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_child_theme_correctly__0.snapshot index 609f26756..2a777b596 100644 --- a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_child_theme_correctly__0.snapshot +++ b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_child_theme_correctly__0.snapshot @@ -16,7 +16,7 @@ modules: url: '%WORDPRESS_URL%' adminUsername: '%WORDPRESS_ADMIN_USER%' adminPassword: '%WORDPRESS_ADMIN_PASSWORD%' - adminPath: '/wp-admin' + adminPath: '%WORDPRESS_ADMIN_PATH%' browser: chrome host: '%CHROMEDRIVER_HOST%' port: '%CHROMEDRIVER_PORT%' @@ -44,10 +44,10 @@ modules: wpRootFolder: '%WORDPRESS_ROOT_DIR%' lucatume\WPBrowser\Module\WPLoader: loadOnly: true - wpRootFolder: "%WORDPRESS_ROOT_DIR%" + wpRootFolder: '%WORDPRESS_ROOT_DIR%' dbUrl: '%WORDPRESS_DB_URL%' domain: '%WORDPRESS_DOMAIN%' - + <<< /tests/EndToEnd.suite.yml <<< >>> /tests/Integration/SampleTest.php >>> @@ -257,8 +257,9 @@ TEST_TABLE_PREFIX=test_ WORDPRESS_TABLE_PREFIX=wp_ # The URL and domain of the WordPress site used in end-to-end tests. -WORDPRESS_URL=http://localhost:49167 -WORDPRESS_DOMAIN=localhost:49167 +WORDPRESS_URL=http://localhost:39249 +WORDPRESS_DOMAIN=localhost:39249 +WORDPRESS_ADMIN_PATH=/wp-admin # The username and password of the administrator user of the WordPress site used in end-to-end tests. WORDPRESS_ADMIN_USER=admin @@ -266,10 +267,10 @@ WORDPRESS_ADMIN_PASSWORD=password # The host and port of the ChromeDriver server that will be used in end-to-end tests. CHROMEDRIVER_HOST=localhost -CHROMEDRIVER_PORT=29046 +CHROMEDRIVER_PORT=43995 # The port on which the PHP built-in server will serve the WordPress installation. -BUILTIN_SERVER_PORT=49167 +BUILTIN_SERVER_PORT=39249 <<< /tests/.env <<< diff --git a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_multi_site_correctly__0.snapshot.txt b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_multi_site_correctly__0.snapshot.txt index 39a0c43b7..e12a62dea 100644 --- a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_multi_site_correctly__0.snapshot.txt +++ b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_multi_site_correctly__0.snapshot.txt @@ -26,6 +26,8 @@ extensions: DB_ENGINE: sqlite DB_DIR: '%codecept_root_dir%/tests/Support/Data' DB_FILE: db.sqlite + WPBROWSER_SITEURL: '%WORDPRESS_URL%' + WPBROWSER_HOMEURL: '%WORDPRESS_URL%' commands: - lucatume\WPBrowser\Command\RunOriginal - lucatume\WPBrowser\Command\RunAll diff --git a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_multi_site_correctly__1.snapshot b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_multi_site_correctly__1.snapshot index 0c9d7739c..39177ae30 100644 --- a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_multi_site_correctly__1.snapshot +++ b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_multi_site_correctly__1.snapshot @@ -16,7 +16,7 @@ modules: url: '%WORDPRESS_URL%' adminUsername: '%WORDPRESS_ADMIN_USER%' adminPassword: '%WORDPRESS_ADMIN_PASSWORD%' - adminPath: '/wp-admin' + adminPath: '%WORDPRESS_ADMIN_PATH%' browser: chrome host: '%CHROMEDRIVER_HOST%' port: '%CHROMEDRIVER_PORT%' @@ -44,10 +44,10 @@ modules: wpRootFolder: '%WORDPRESS_ROOT_DIR%' lucatume\WPBrowser\Module\WPLoader: loadOnly: true - wpRootFolder: "%WORDPRESS_ROOT_DIR%" + wpRootFolder: '%WORDPRESS_ROOT_DIR%' dbUrl: '%WORDPRESS_DB_URL%' domain: '%WORDPRESS_DOMAIN%' - + <<< /EndToEnd.suite.yml <<< >>> /Integration/SampleTest.php >>> @@ -267,8 +267,9 @@ TEST_TABLE_PREFIX=test_ WORDPRESS_TABLE_PREFIX=wp_ # The URL and domain of the WordPress site used in end-to-end tests. -WORDPRESS_URL=http://localhost:52214 -WORDPRESS_DOMAIN=localhost:52214 +WORDPRESS_URL=http://localhost:9035 +WORDPRESS_DOMAIN=localhost:9035 +WORDPRESS_ADMIN_PATH=/wp-admin # The username and password of the administrator user of the WordPress site used in end-to-end tests. WORDPRESS_ADMIN_USER=admin @@ -276,10 +277,10 @@ WORDPRESS_ADMIN_PASSWORD=password # The host and port of the ChromeDriver server that will be used in end-to-end tests. CHROMEDRIVER_HOST=localhost -CHROMEDRIVER_PORT=52233 +CHROMEDRIVER_PORT=21043 # The port on which the PHP built-in server will serve the WordPress installation. -BUILTIN_SERVER_PORT=52214 +BUILTIN_SERVER_PORT=9035 <<< /.env <<< diff --git a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_plugin_with_non_plugin_php_file__0.snapshot b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_plugin_with_non_plugin_php_file__0.snapshot index 9a6067d55..94aa0c6c0 100644 --- a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_plugin_with_non_plugin_php_file__0.snapshot +++ b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_plugin_with_non_plugin_php_file__0.snapshot @@ -16,7 +16,7 @@ modules: url: '%WORDPRESS_URL%' adminUsername: '%WORDPRESS_ADMIN_USER%' adminPassword: '%WORDPRESS_ADMIN_PASSWORD%' - adminPath: '/wp-admin' + adminPath: '%WORDPRESS_ADMIN_PATH%' browser: chrome host: '%CHROMEDRIVER_HOST%' port: '%CHROMEDRIVER_PORT%' @@ -44,10 +44,10 @@ modules: wpRootFolder: '%WORDPRESS_ROOT_DIR%' lucatume\WPBrowser\Module\WPLoader: loadOnly: true - wpRootFolder: "%WORDPRESS_ROOT_DIR%" + wpRootFolder: '%WORDPRESS_ROOT_DIR%' dbUrl: '%WORDPRESS_DB_URL%' domain: '%WORDPRESS_DOMAIN%' - + <<< /tests/EndToEnd.suite.yml <<< >>> /tests/Integration/SampleTest.php >>> @@ -265,8 +265,9 @@ TEST_TABLE_PREFIX=test_ WORDPRESS_TABLE_PREFIX=wp_ # The URL and domain of the WordPress site used in end-to-end tests. -WORDPRESS_URL=http://localhost:52011 -WORDPRESS_DOMAIN=localhost:52011 +WORDPRESS_URL=http://localhost:53890 +WORDPRESS_DOMAIN=localhost:53890 +WORDPRESS_ADMIN_PATH=/wp-admin # The username and password of the administrator user of the WordPress site used in end-to-end tests. WORDPRESS_ADMIN_USER=admin @@ -274,10 +275,10 @@ WORDPRESS_ADMIN_PASSWORD=password # The host and port of the ChromeDriver server that will be used in end-to-end tests. CHROMEDRIVER_HOST=localhost -CHROMEDRIVER_PORT=52030 +CHROMEDRIVER_PORT=27014 # The port on which the PHP built-in server will serve the WordPress installation. -BUILTIN_SERVER_PORT=52011 +BUILTIN_SERVER_PORT=53890 <<< /tests/.env <<< diff --git a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_plugin_with_non_plugin_php_file_custom__0.snapshot b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_plugin_with_non_plugin_php_file_custom__0.snapshot index 67cbbad11..8f0699f8f 100644 --- a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_plugin_with_non_plugin_php_file_custom__0.snapshot +++ b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_plugin_with_non_plugin_php_file_custom__0.snapshot @@ -21,7 +21,7 @@ modules: url: '%WORDPRESS_URL%' adminUsername: '%WORDPRESS_ADMIN_USER%' adminPassword: '%WORDPRESS_ADMIN_PASSWORD%' - adminPath: '/wp-admin' + adminPath: '%WORDPRESS_ADMIN_PATH%' browser: chrome host: '%CHROMEDRIVER_HOST%' port: '%CHROMEDRIVER_PORT%' @@ -49,10 +49,10 @@ modules: wpRootFolder: '%WORDPRESS_ROOT_DIR%' lucatume\WPBrowser\Module\WPLoader: loadOnly: true - wpRootFolder: "%WORDPRESS_ROOT_DIR%" + wpRootFolder: '%WORDPRESS_ROOT_DIR%' dbUrl: '%WORDPRESS_DB_URL%' domain: '%WORDPRESS_DOMAIN%' - + <<< /tests/EndToEnd.suite.yml <<< >>> /tests/Integration/_bootstrap.php >>> @@ -204,6 +204,7 @@ WORDPRESS_TABLE_PREFIX=wp_ # The URL and domain of the WordPress site used in end-to-end tests. WORDPRESS_URL=http://wordpress.test WORDPRESS_DOMAIN=wordpress.test +WORDPRESS_ADMIN_PATH=/wp-admin # The username and password of the administrator user of the WordPress site used in end-to-end tests. WORDPRESS_ADMIN_USER=admin diff --git a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_plugin_with_plugin_php_file__0.snapshot b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_plugin_with_plugin_php_file__0.snapshot index 7aa3fe7ba..56be82bd8 100644 --- a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_plugin_with_plugin_php_file__0.snapshot +++ b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_plugin_with_plugin_php_file__0.snapshot @@ -21,7 +21,7 @@ modules: url: '%WORDPRESS_URL%' adminUsername: '%WORDPRESS_ADMIN_USER%' adminPassword: '%WORDPRESS_ADMIN_PASSWORD%' - adminPath: '/wp-admin' + adminPath: '%WORDPRESS_ADMIN_PATH%' browser: chrome host: '%CHROMEDRIVER_HOST%' port: '%CHROMEDRIVER_PORT%' @@ -49,10 +49,10 @@ modules: wpRootFolder: '%WORDPRESS_ROOT_DIR%' lucatume\WPBrowser\Module\WPLoader: loadOnly: true - wpRootFolder: "%WORDPRESS_ROOT_DIR%" + wpRootFolder: '%WORDPRESS_ROOT_DIR%' dbUrl: '%WORDPRESS_DB_URL%' domain: '%WORDPRESS_DOMAIN%' - + <<< /tests/EndToEnd.suite.yml <<< >>> /tests/Integration/SampleTest.php >>> @@ -270,8 +270,9 @@ TEST_TABLE_PREFIX=test_ WORDPRESS_TABLE_PREFIX=wp_ # The URL and domain of the WordPress site used in end-to-end tests. -WORDPRESS_URL=http://localhost:51968 -WORDPRESS_DOMAIN=localhost:51968 +WORDPRESS_URL=http://localhost:19501 +WORDPRESS_DOMAIN=localhost:19501 +WORDPRESS_ADMIN_PATH=/wp-admin # The username and password of the administrator user of the WordPress site used in end-to-end tests. WORDPRESS_ADMIN_USER=admin @@ -279,10 +280,10 @@ WORDPRESS_ADMIN_PASSWORD=password # The host and port of the ChromeDriver server that will be used in end-to-end tests. CHROMEDRIVER_HOST=localhost -CHROMEDRIVER_PORT=51983 +CHROMEDRIVER_PORT=13899 # The port on which the PHP built-in server will serve the WordPress installation. -BUILTIN_SERVER_PORT=51968 +BUILTIN_SERVER_PORT=19501 <<< /tests/.env <<< diff --git a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_plugin_with_plugin_php_file_custom__0.snapshot b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_plugin_with_plugin_php_file_custom__0.snapshot index a155e1b89..3eb25f223 100644 --- a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_plugin_with_plugin_php_file_custom__0.snapshot +++ b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_plugin_with_plugin_php_file_custom__0.snapshot @@ -21,7 +21,7 @@ modules: url: '%WORDPRESS_URL%' adminUsername: '%WORDPRESS_ADMIN_USER%' adminPassword: '%WORDPRESS_ADMIN_PASSWORD%' - adminPath: '/wp-admin' + adminPath: '%WORDPRESS_ADMIN_PATH%' browser: chrome host: '%CHROMEDRIVER_HOST%' port: '%CHROMEDRIVER_PORT%' @@ -49,10 +49,10 @@ modules: wpRootFolder: '%WORDPRESS_ROOT_DIR%' lucatume\WPBrowser\Module\WPLoader: loadOnly: true - wpRootFolder: "%WORDPRESS_ROOT_DIR%" + wpRootFolder: '%WORDPRESS_ROOT_DIR%' dbUrl: '%WORDPRESS_DB_URL%' domain: '%WORDPRESS_DOMAIN%' - + <<< /tests/EndToEnd.suite.yml <<< >>> /tests/Integration/_bootstrap.php >>> @@ -204,6 +204,7 @@ WORDPRESS_TABLE_PREFIX=wp_ # The URL and domain of the WordPress site used in end-to-end tests. WORDPRESS_URL=http://wordpress.test WORDPRESS_DOMAIN=wordpress.test +WORDPRESS_ADMIN_PATH=/wp-admin # The username and password of the administrator user of the WordPress site used in end-to-end tests. WORDPRESS_ADMIN_USER=admin diff --git a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_single_site_correctly__0.snapshot.txt b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_single_site_correctly__0.snapshot.txt index 39a0c43b7..e12a62dea 100644 --- a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_single_site_correctly__0.snapshot.txt +++ b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_single_site_correctly__0.snapshot.txt @@ -26,6 +26,8 @@ extensions: DB_ENGINE: sqlite DB_DIR: '%codecept_root_dir%/tests/Support/Data' DB_FILE: db.sqlite + WPBROWSER_SITEURL: '%WORDPRESS_URL%' + WPBROWSER_HOMEURL: '%WORDPRESS_URL%' commands: - lucatume\WPBrowser\Command\RunOriginal - lucatume\WPBrowser\Command\RunAll diff --git a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_single_site_correctly__1.snapshot b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_single_site_correctly__1.snapshot index a2207738e..a808ee15b 100644 --- a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_single_site_correctly__1.snapshot +++ b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_single_site_correctly__1.snapshot @@ -16,7 +16,7 @@ modules: url: '%WORDPRESS_URL%' adminUsername: '%WORDPRESS_ADMIN_USER%' adminPassword: '%WORDPRESS_ADMIN_PASSWORD%' - adminPath: '/wp-admin' + adminPath: '%WORDPRESS_ADMIN_PATH%' browser: chrome host: '%CHROMEDRIVER_HOST%' port: '%CHROMEDRIVER_PORT%' @@ -44,10 +44,10 @@ modules: wpRootFolder: '%WORDPRESS_ROOT_DIR%' lucatume\WPBrowser\Module\WPLoader: loadOnly: true - wpRootFolder: "%WORDPRESS_ROOT_DIR%" + wpRootFolder: '%WORDPRESS_ROOT_DIR%' dbUrl: '%WORDPRESS_DB_URL%' domain: '%WORDPRESS_DOMAIN%' - + <<< /EndToEnd.suite.yml <<< >>> /Integration/SampleTest.php >>> @@ -267,8 +267,9 @@ TEST_TABLE_PREFIX=test_ WORDPRESS_TABLE_PREFIX=wp_ # The URL and domain of the WordPress site used in end-to-end tests. -WORDPRESS_URL=http://localhost:52169 -WORDPRESS_DOMAIN=localhost:52169 +WORDPRESS_URL=http://localhost:26712 +WORDPRESS_DOMAIN=localhost:26712 +WORDPRESS_ADMIN_PATH=/wp-admin # The username and password of the administrator user of the WordPress site used in end-to-end tests. WORDPRESS_ADMIN_USER=admin @@ -276,10 +277,10 @@ WORDPRESS_ADMIN_PASSWORD=password # The host and port of the ChromeDriver server that will be used in end-to-end tests. CHROMEDRIVER_HOST=localhost -CHROMEDRIVER_PORT=52182 +CHROMEDRIVER_PORT=12425 # The port on which the PHP built-in server will serve the WordPress installation. -BUILTIN_SERVER_PORT=52169 +BUILTIN_SERVER_PORT=26712 <<< /.env <<< diff --git a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_theme_correctly__0.snapshot b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_theme_correctly__0.snapshot index d1dbc2fef..82c54f0aa 100644 --- a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_theme_correctly__0.snapshot +++ b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_theme_correctly__0.snapshot @@ -16,7 +16,7 @@ modules: url: '%WORDPRESS_URL%' adminUsername: '%WORDPRESS_ADMIN_USER%' adminPassword: '%WORDPRESS_ADMIN_PASSWORD%' - adminPath: '/wp-admin' + adminPath: '%WORDPRESS_ADMIN_PATH%' browser: chrome host: '%CHROMEDRIVER_HOST%' port: '%CHROMEDRIVER_PORT%' @@ -44,10 +44,10 @@ modules: wpRootFolder: '%WORDPRESS_ROOT_DIR%' lucatume\WPBrowser\Module\WPLoader: loadOnly: true - wpRootFolder: "%WORDPRESS_ROOT_DIR%" + wpRootFolder: '%WORDPRESS_ROOT_DIR%' dbUrl: '%WORDPRESS_DB_URL%' domain: '%WORDPRESS_DOMAIN%' - + <<< /tests/EndToEnd.suite.yml <<< >>> /tests/Integration/SampleTest.php >>> @@ -257,8 +257,9 @@ TEST_TABLE_PREFIX=test_ WORDPRESS_TABLE_PREFIX=wp_ # The URL and domain of the WordPress site used in end-to-end tests. -WORDPRESS_URL=http://localhost:7039 -WORDPRESS_DOMAIN=localhost:7039 +WORDPRESS_URL=http://localhost:61144 +WORDPRESS_DOMAIN=localhost:61144 +WORDPRESS_ADMIN_PATH=/wp-admin # The username and password of the administrator user of the WordPress site used in end-to-end tests. WORDPRESS_ADMIN_USER=admin @@ -266,10 +267,10 @@ WORDPRESS_ADMIN_PASSWORD=password # The host and port of the ChromeDriver server that will be used in end-to-end tests. CHROMEDRIVER_HOST=localhost -CHROMEDRIVER_PORT=48529 +CHROMEDRIVER_PORT=17476 # The port on which the PHP built-in server will serve the WordPress installation. -BUILTIN_SERVER_PORT=7039 +BUILTIN_SERVER_PORT=61144 <<< /tests/.env <<< diff --git a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_theme_custom_correctly__0.snapshot b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_theme_custom_correctly__0.snapshot index 328b5421a..6e8c18c1f 100644 --- a/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_theme_custom_correctly__0.snapshot +++ b/tests/unit/Codeception/Template/__snapshots__/WpbrowserTest__should_scaffold_for_theme_custom_correctly__0.snapshot @@ -23,7 +23,7 @@ modules: url: '%WORDPRESS_URL%' adminUsername: '%WORDPRESS_ADMIN_USER%' adminPassword: '%WORDPRESS_ADMIN_PASSWORD%' - adminPath: '/wp-admin' + adminPath: '%WORDPRESS_ADMIN_PATH%' browser: chrome host: '%CHROMEDRIVER_HOST%' port: '%CHROMEDRIVER_PORT%' @@ -51,10 +51,10 @@ modules: wpRootFolder: '%WORDPRESS_ROOT_DIR%' lucatume\WPBrowser\Module\WPLoader: loadOnly: true - wpRootFolder: "%WORDPRESS_ROOT_DIR%" + wpRootFolder: '%WORDPRESS_ROOT_DIR%' dbUrl: '%WORDPRESS_DB_URL%' domain: '%WORDPRESS_DOMAIN%' - + <<< /tests/EndToEnd.suite.yml <<< >>> /tests/Integration/_bootstrap.php >>> @@ -206,6 +206,7 @@ WORDPRESS_TABLE_PREFIX=wp_ # The URL and domain of the WordPress site used in end-to-end tests. WORDPRESS_URL=http://wordpress.test WORDPRESS_DOMAIN=wordpress.test +WORDPRESS_ADMIN_PATH=/wp-admin # The username and password of the administrator user of the WordPress site used in end-to-end tests. WORDPRESS_ADMIN_USER=admin