Clenup WordPress install in acceptance tests entrypoint, simplify setup

[MAILPOET-2302]
This commit is contained in:
Jan Jakeš
2019-09-02 10:01:44 +02:00
committed by M. Shull
parent 65b26991d4
commit bfd0c0ab03
2 changed files with 34 additions and 87 deletions

View File

@ -26,14 +26,6 @@ class CleanupExtension extends Extension {
parent::__construct($config, $options); parent::__construct($config, $options);
$this->root_connection = new PDO($this->createDsnConnectionString(), self::DB_USERNAME, self::DB_PASSWORD); $this->root_connection = new PDO($this->createDsnConnectionString(), self::DB_USERNAME, self::DB_PASSWORD);
$this->root_connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $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) { function backupDatabase(SuiteEvent $event) {
@ -77,7 +69,7 @@ class CleanupExtension extends Extension {
} }
private function createDsnConnectionString() { 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() { private function createMysqlDumpCommand() {

111
tests/docker/codeception/docker-entrypoint.sh Normal file → Executable file
View File

@ -1,8 +1,7 @@
#!/bin/bash #!/bin/bash
# Allows WP CLI to run with the right permissions. wp() {
wp-su() { command wp --allow-root "$@"
sudo -E -u www-data wp "$@"
} }
# wait for database container to be ready # wait for database container to be ready
@ -18,89 +17,42 @@ while ! bash -c "echo > /dev/tcp/wordpress/80" &>/dev/null; do
sleep 1 sleep 1
done done
# Make sure permissions are correct. # make sure permissions are correct
cd /wp-core cd /wp-core
chown www-data:www-data wp-content/plugins chown www-data:www-data wp-content/plugins
chown www-data:www-data wp-content/uploads chown www-data:www-data wp-content/uploads
chmod 755 wp-content/plugins chmod 755 wp-content/plugins
chmod -R 777 wp-content/uploads chmod -R 777 wp-content/uploads
# Make sure WordPress is installed. # backup original 'wp-config.php' created by WordPress image
if ! $(wp-su core is-installed); then if [ ! -f wp-config-original.php ]; then
cp wp-config.php wp-config-original.php
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
fi 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=''
CONFIG+="define('WP_DEBUG', true);\n" CONFIG+="define('WP_DEBUG', true);\n"
CONFIG+="define('WP_DEBUG_DISPLAY', true);\n" CONFIG+="define('WP_DEBUG_DISPLAY', true);\n"
@ -122,6 +74,9 @@ if [[ -z "${SKIP_DEPS}" ]]; then
php composer.phar install php composer.phar install
fi fi
# activate MailPoet
wp plugin activate mailpoet/mailpoet.php
cd /wp-core/wp-content/plugins/mailpoet cd /wp-core/wp-content/plugins/mailpoet
/project/vendor/bin/codecept run acceptance $@ /project/vendor/bin/codecept run acceptance $@