diff --git a/tests/_support/CleanupExtension.php b/tests/_support/CleanupExtension.php index e4c76ec4cc..325e7fb7ef 100644 --- a/tests/_support/CleanupExtension.php +++ b/tests/_support/CleanupExtension.php @@ -26,14 +26,6 @@ class CleanupExtension extends Extension { parent::__construct($config, $options); $this->root_connection = new PDO($this->createDsnConnectionString(), self::DB_USERNAME, self::DB_PASSWORD); $this->root_connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - - // purge database immediately (before any Codeception modules are loaded) - $database_name = self::DB_NAME; - $this->root_connection->exec(" - DROP DATABASE IF EXISTS $database_name; - CREATE DATABASE $database_name; - USE $database_name; - "); } function backupDatabase(SuiteEvent $event) { @@ -77,7 +69,7 @@ class CleanupExtension extends Extension { } private function createDsnConnectionString() { - return sprintf('mysql:host=%s', self::DB_HOST); + return sprintf('mysql:host=%s;dbname=%s', self::DB_HOST, self::DB_NAME); } private function createMysqlDumpCommand() { diff --git a/tests/docker/codeception/docker-entrypoint.sh b/tests/docker/codeception/docker-entrypoint.sh old mode 100644 new mode 100755 index 8cc7b9fe08..1dc1b6934f --- a/tests/docker/codeception/docker-entrypoint.sh +++ b/tests/docker/codeception/docker-entrypoint.sh @@ -1,8 +1,7 @@ #!/bin/bash -# Allows WP CLI to run with the right permissions. -wp-su() { - sudo -E -u www-data wp "$@" +wp() { + command wp --allow-root "$@" } # wait for database container to be ready @@ -18,89 +17,42 @@ while ! bash -c "echo > /dev/tcp/wordpress/80" &>/dev/null; do sleep 1 done -# Make sure permissions are correct. +# make sure permissions are correct cd /wp-core chown www-data:www-data wp-content/plugins chown www-data:www-data wp-content/uploads chmod 755 wp-content/plugins chmod -R 777 wp-content/uploads -# Make sure WordPress is installed. -if ! $(wp-su core is-installed); then - - echo "Installing WordPress" - - if [ -z "${MULTISITE}" ] - then - - echo "Running in single site mode" - - wp-su core install --url=test.local --title=tests --admin_user=admin --admin_email=test@test.com - - cp /project/tests/_data/acceptanceDump.sql /project/tests/_data/acceptanceGenerated.sql - - else - - wp-su core multisite-install --url=test.local --title=tests --admin_user=admin --admin_email=test@test.com - - cp /project/tests/_data/acceptanceMultisiteDump.sql /project/tests/_data/acceptanceGenerated.sql - cat /project/tests/_data/acceptanceDump.sql >> /project/tests/_data/acceptanceGenerated.sql - echo "Running in multi site mode" - echo " -RewriteEngine On -RewriteBase / -RewriteRule ^index\.php$ - [L] - -# add a trailing slash to /wp-admin -RewriteRule ^wp-admin$ wp-admin/ [R=301,L] - -RewriteCond %{REQUEST_FILENAME} -f [OR] -RewriteCond %{REQUEST_FILENAME} -d -RewriteRule ^ - [L] -RewriteRule ^(wp-(content|admin|includes).*) $1 [L] -RewriteRule ^(.*\.php)$ $1 [L] -RewriteRule . index.php [L] -" > .htaccess - fi - - echo "Installing WooCommerce" - wp plugin install woocommerce --allow-root - -else - - if [ -z "${MULTISITE}" ] && $(wp-su core is-installed --network) - then - echo "xyxicdufd" - echo -e "\033[0;31m--------------------------------------------------------------------" - echo -e "\033[0;31m--------------------------------------------------------------------" - echo -e "\033[0;31m--------------------------------------------------------------------" - echo -e "\033[0;31m-------------------------WARNING!!!!!!!!----------------------------" - echo -e "\033[0;31m- You are trying to run tests in single site mode -" - echo -e "\033[0;31m- But the container has been already installed in multi site mode -" - echo -e "\033[0;31m- You need to delete your installation first. Use ./do d:d -" - echo -e "\033[0;31m--------------------------------------------------------------------" - echo -e "\033[0;31m--------------------------------------------------------------------" - echo -e "\033[0;31m--------------------------------------------------------------------" - exit - - fi - if [ ! -z "${MULTISITE}" ] && ( ! $(wp-su core is-installed --network) ) - then - echo -e "\033[0;31m--------------------------------------------------------------------" - echo -e "\033[0;31m--------------------------------------------------------------------" - echo -e "\033[0;31m--------------------------------------------------------------------" - echo -e "\033[0;31m-------------------------WARNING!!!!!!!!----------------------------" - echo -e "\033[0;31m- You are trying to run tests in multi site mode -" - echo -e "\033[0;31m- But the container has been already installed in single site mode -" - echo -e "\033[0;31m- You need to delete your installation first. Use ./do d:d -" - echo -e "\033[0;31m--------------------------------------------------------------------" - echo -e "\033[0;31m--------------------------------------------------------------------" - echo -e "\033[0;31m--------------------------------------------------------------------" - exit - fi - +# backup original 'wp-config.php' created by WordPress image +if [ ! -f wp-config-original.php ]; then + cp wp-config.php wp-config-original.php fi +# cleanup 'wp-config.php' and database +rm -f wp-config.php && cp wp-config-original.php wp-config.php +mysqladmin --host=mysql --user=root --password=wordpress drop wordpress --force +mysqladmin --host=mysql --user=root --password=wordpress create wordpress --force + +# install WordPress +WP_CORE_INSTALL_PARAMS="--url=test.local --title=tests --admin_user=admin --admin_email=test@test.com --admin_password=password --skip-email" +if [ -z "${MULTISITE}" ]; then + echo 'Installing WordPress (single site mode)' + wp core install $WP_CORE_INSTALL_PARAMS + cp /project/tests/_data/acceptanceDump.sql /project/tests/_data/acceptanceGenerated.sql +else + echo 'Installing WordPress (multisite mode)' + wp core multisite-install $WP_CORE_INSTALL_PARAMS + cp /project/tests/_data/acceptanceMultisiteDump.sql /project/tests/_data/acceptanceGenerated.sql + cat /project/tests/_data/acceptanceDump.sql >> /project/tests/_data/acceptanceGenerated.sql +fi + +# install WooCommerce (activate & deactivate it to populate DB for backup) +wp plugin install woocommerce +wp plugin activate woocommerce +wp plugin deactivate woocommerce + +# add configuration CONFIG='' CONFIG+="define('WP_DEBUG', true);\n" CONFIG+="define('WP_DEBUG_DISPLAY', true);\n" @@ -122,6 +74,9 @@ if [[ -z "${SKIP_DEPS}" ]]; then php composer.phar install fi +# activate MailPoet +wp plugin activate mailpoet/mailpoet.php + cd /wp-core/wp-content/plugins/mailpoet /project/vendor/bin/codecept run acceptance $@