Adds multisite test environment to CI
Adds Robo command to run multisite tests locally and on CI
This commit is contained in:
@ -1,6 +1,4 @@
|
|||||||
Listen 8080
|
<VirtualHost *:80>
|
||||||
|
|
||||||
<VirtualHost *:8080>
|
|
||||||
UseCanonicalName Off
|
UseCanonicalName Off
|
||||||
ServerName mailpoet.loc
|
ServerName mailpoet.loc
|
||||||
DocumentRoot /home/circleci/mailpoet/wordpress
|
DocumentRoot /home/circleci/mailpoet/wordpress
|
||||||
@ -8,6 +6,9 @@ Listen 8080
|
|||||||
LogLevel notice
|
LogLevel notice
|
||||||
|
|
||||||
<Directory /home/circleci/mailpoet/wordpress>
|
<Directory /home/circleci/mailpoet/wordpress>
|
||||||
|
Options Indexes FollowSymLinks
|
||||||
|
AllowOverride All
|
||||||
|
RewriteEngine On
|
||||||
Require all granted
|
Require all granted
|
||||||
</Directory>
|
</Directory>
|
||||||
</VirtualHost>
|
</VirtualHost>
|
||||||
|
@ -120,7 +120,38 @@ jobs:
|
|||||||
- run:
|
- run:
|
||||||
name: "PHP Unit tests"
|
name: "PHP Unit tests"
|
||||||
command: |
|
command: |
|
||||||
WP_TEST_PATH="/home/circleci/mailpoet/wordpress" ./do t:u --xml
|
./do t:u --xml
|
||||||
|
- store_test_results:
|
||||||
|
path: tests/_output
|
||||||
|
- store_artifacts:
|
||||||
|
path: tests/_output
|
||||||
|
destination: codeception
|
||||||
|
- store_artifacts:
|
||||||
|
path: /tmp/fake-mailer/
|
||||||
|
destination: fake-mailer
|
||||||
|
php7_multisite:
|
||||||
|
working_directory: /home/circleci/mailpoet
|
||||||
|
docker:
|
||||||
|
- image: circleci/php:7.1-apache-browsers
|
||||||
|
- image: circleci/mysql:5.7
|
||||||
|
environment:
|
||||||
|
TZ: /usr/share/zoneinfo/Etc/UTC
|
||||||
|
steps:
|
||||||
|
- checkout
|
||||||
|
- run:
|
||||||
|
name: "Set up virtual host"
|
||||||
|
command: echo 127.0.0.1 mailpoet.loc | sudo tee -a /etc/hosts
|
||||||
|
- restore_cache:
|
||||||
|
key: composer-{{ checksum "composer.json" }}-{{ checksum "composer.lock" }}
|
||||||
|
- restore_cache:
|
||||||
|
key: npm-{{ checksum "package.json" }}
|
||||||
|
- run:
|
||||||
|
name: "Set up test environment"
|
||||||
|
command: source ./.circleci/setup.bash && setup php7_multisite
|
||||||
|
- run:
|
||||||
|
name: "PHP Unit tests"
|
||||||
|
command: |
|
||||||
|
./do t:multisite-unit --xml
|
||||||
- store_test_results:
|
- store_test_results:
|
||||||
path: tests/_output
|
path: tests/_output
|
||||||
- store_artifacts:
|
- store_artifacts:
|
||||||
@ -135,4 +166,5 @@ workflows:
|
|||||||
jobs:
|
jobs:
|
||||||
- qa_js_php5
|
- qa_js_php5
|
||||||
- php7
|
- php7
|
||||||
|
- php7_multisite
|
||||||
- acceptance_tests
|
- acceptance_tests
|
@ -2,8 +2,11 @@
|
|||||||
|
|
||||||
function setup {
|
function setup {
|
||||||
local version=$1
|
local version=$1
|
||||||
|
local wp_cli_wordpress_path="--path=wordpress"
|
||||||
|
local wp_cli_allow_root="--allow-root"
|
||||||
|
|
||||||
# install PHP dependencies for WordPress
|
# install PHP dependencies for WordPress
|
||||||
if [[ $version == "php7" ]]; then
|
if [[ $version == "php7" ]] || [[ $version == "php7_multisite" ]]; then
|
||||||
echo "deb http://packages.dotdeb.org jessie all" | sudo tee -a /etc/apt/sources.list.d/dotdeb.list
|
echo "deb http://packages.dotdeb.org jessie all" | sudo tee -a /etc/apt/sources.list.d/dotdeb.list
|
||||||
echo "deb-src http://packages.dotdeb.org jessie all" | sudo tee -a /etc/apt/sources.list.d/dotdeb.list
|
echo "deb-src http://packages.dotdeb.org jessie all" | sudo tee -a /etc/apt/sources.list.d/dotdeb.list
|
||||||
wget -qO - http://www.dotdeb.org/dotdeb.gpg | sudo apt-key add -
|
wget -qO - http://www.dotdeb.org/dotdeb.gpg | sudo apt-key add -
|
||||||
@ -15,35 +18,66 @@ function setup {
|
|||||||
sudo apt-get install mysql-client php5-mysql zlib1g-dev
|
sudo apt-get install mysql-client php5-mysql zlib1g-dev
|
||||||
sudo docker-php-ext-install mysql mysqli pdo pdo_mysql zip
|
sudo docker-php-ext-install mysql mysqli pdo pdo_mysql zip
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Add a fake sendmail mailer
|
# Add a fake sendmail mailer
|
||||||
sudo cp ./.circleci/fake-sendmail.php /usr/local/bin/
|
sudo cp ./.circleci/fake-sendmail.php /usr/local/bin/
|
||||||
|
|
||||||
# configure Apache
|
# configure Apache
|
||||||
sudo cp ./.circleci/mailpoet_php.ini /usr/local/etc/php/conf.d/
|
sudo cp ./.circleci/mailpoet_php.ini /usr/local/etc/php/conf.d/
|
||||||
sudo cp ./.circleci/apache/mailpoet.loc.conf /etc/apache2/sites-available
|
sudo cp ./.circleci/apache/mailpoet.loc.conf /etc/apache2/sites-available
|
||||||
|
sudo a2dissite 000-default.conf
|
||||||
sudo a2ensite mailpoet.loc
|
sudo a2ensite mailpoet.loc
|
||||||
sudo a2enmod rewrite
|
sudo a2enmod rewrite
|
||||||
sudo service apache2 restart
|
sudo service apache2 restart
|
||||||
|
|
||||||
# Install NodeJS+NPM
|
# Install NodeJS+NPM
|
||||||
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
|
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
|
||||||
sudo apt-get install nodejs build-essential
|
sudo apt-get install nodejs build-essential
|
||||||
|
|
||||||
# install plugin dependencies
|
# install plugin dependencies
|
||||||
curl -sS https://getcomposer.org/installer | php
|
curl -sS https://getcomposer.org/installer | php
|
||||||
./composer.phar install
|
./composer.phar install
|
||||||
./do install
|
./do install
|
||||||
# Set up Wordpress
|
|
||||||
|
# Set up WordPress
|
||||||
mysql -h 127.0.0.1 -u root -e "create database wordpress"
|
mysql -h 127.0.0.1 -u root -e "create database wordpress"
|
||||||
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
|
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
|
||||||
chmod +x wp-cli.phar
|
chmod +x wp-cli.phar
|
||||||
./wp-cli.phar core download --allow-root --path=wordpress
|
sudo mv wp-cli.phar /usr/local/bin/wp
|
||||||
|
wp core download $wp_cli_wordpress_path $wp_cli_allow_root
|
||||||
|
|
||||||
# Generate `wp-config.php` file with debugging enabled
|
# Generate `wp-config.php` file with debugging enabled
|
||||||
echo "define(\"WP_DEBUG\", true);" | ./wp-cli.phar core config --allow-root --dbname=wordpress --dbuser=root --dbhost=127.0.0.1 --path=wordpress --extra-php
|
echo "define(\"WP_DEBUG\", true);" | wp core config --dbname=wordpress --dbuser=root --dbhost=127.0.0.1 --extra-php $wp_cli_wordpress_path $wp_cli_allow_root
|
||||||
|
|
||||||
|
# Change default table prefix
|
||||||
sed -i "s/\$table_prefix = 'wp_';/\$table_prefix = 'mp_';/" ./wordpress/wp-config.php
|
sed -i "s/\$table_prefix = 'wp_';/\$table_prefix = 'mp_';/" ./wordpress/wp-config.php
|
||||||
|
|
||||||
# Install WordPress
|
# Install WordPress
|
||||||
./wp-cli.phar core install --allow-root --admin_name=admin --admin_password=admin --admin_email=admin@mailpoet.loc --url=http://mailpoet.loc:8080 --title=WordPress --path=wordpress
|
if [[ $version == "php7_multisite" ]]; then
|
||||||
|
# Configure multisite environment
|
||||||
|
wp core multisite-install --admin_name=admin --admin_password=admin --admin_email=admin@mailpoet.loc --url=http://mailpoet.loc --title="WordPress MultiSite" $wp_cli_wordpress_path $wp_cli_allow_root
|
||||||
|
cp ./.circleci/wordpress/.htaccess ./wordpress/
|
||||||
|
|
||||||
|
# Add a second blog
|
||||||
|
wp site create --slug=php7_multisite $wp_cli_wordpress_path $wp_cli_allow_root
|
||||||
|
echo "WP_TEST_MULTISITE_SLUG=php7_multisite" >> .env
|
||||||
|
echo "WP_TEST_PATH_MULTISITE=/home/circleci/mailpoet/wordpress" >> .env
|
||||||
|
echo "HTTP_HOST=mailpoet.loc" >> .env
|
||||||
|
|
||||||
|
# Add a third dummy blog
|
||||||
|
wp site create --slug=dummy_multisite $wp_cli_wordpress_path $wp_cli_allow_root
|
||||||
|
else
|
||||||
|
wp core install --admin_name=admin --admin_password=admin --admin_email=admin@mailpoet.loc --url=http://mailpoet.loc --title="WordPress Single" $wp_cli_wordpress_path $wp_cli_allow_root
|
||||||
|
echo "WP_TEST_PATH=/home/circleci/mailpoet/wordpress" >> .env
|
||||||
|
fi
|
||||||
|
|
||||||
# Softlink plugin to plugin path
|
# Softlink plugin to plugin path
|
||||||
ln -s ../../.. wordpress/wp-content/plugins/mailpoet
|
ln -s ../../.. wordpress/wp-content/plugins/mailpoet
|
||||||
./wp-cli.phar plugin activate mailpoet --path=wordpress
|
|
||||||
# Create .env file with correct path to WP installation
|
# Activate plugin
|
||||||
# TODO: Remove this line after PR gets merged and CircleCI env variables change
|
if [[ $version == "php7_multisite" ]]; then
|
||||||
echo "WP_TEST_PATH=\"/home/circleci/mailpoet/wordpress\"" > .env
|
wp plugin activate mailpoet --url=http://mailpoet.loc/php7_multisite/ $wp_cli_wordpress_path $wp_cli_allow_root
|
||||||
|
else
|
||||||
|
wp plugin activate mailpoet $wp_cli_wordpress_path $wp_cli_allow_root
|
||||||
|
fi
|
||||||
}
|
}
|
12
.circleci/wordpress/.htaccess
Normal file
12
.circleci/wordpress/.htaccess
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
RewriteEngine On
|
||||||
|
RewriteBase /
|
||||||
|
RewriteRule ^index\.php$ - [L]
|
||||||
|
|
||||||
|
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
|
||||||
|
|
||||||
|
RewriteCond %{REQUEST_FILENAME} -f [OR]
|
||||||
|
RewriteCond %{REQUEST_FILENAME} -d
|
||||||
|
RewriteRule ^ - [L]
|
||||||
|
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
|
||||||
|
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
|
||||||
|
RewriteRule . index.php [L]
|
@ -1,4 +1,6 @@
|
|||||||
WP_TEST_PATH="/var/www/wordpress"
|
WP_TEST_PATH="/var/www/wordpress"
|
||||||
|
WP_TEST_PATH_MULTISITE="/var/www/wordpress"
|
||||||
|
WP_TEST_MULTISITE_SLUG=""
|
||||||
WP_TEST_ENABLE_NETWORK_TESTS="true"
|
WP_TEST_ENABLE_NETWORK_TESTS="true"
|
||||||
WP_TEST_IMPORT_MAILCHIMP_API=""
|
WP_TEST_IMPORT_MAILCHIMP_API=""
|
||||||
WP_TEST_IMPORT_MAILCHIMP_LISTS="" // (separated with comma)
|
WP_TEST_IMPORT_MAILCHIMP_LISTS="" // (separated with comma)
|
||||||
@ -17,3 +19,4 @@ WP_TEST_MAILER_SMTP_PASSWORD=""
|
|||||||
WP_SVN_USERNAME=""
|
WP_SVN_USERNAME=""
|
||||||
WP_SVN_PASSWORD=""
|
WP_SVN_PASSWORD=""
|
||||||
WP_TRANSIFEX_API_TOKEN=""
|
WP_TRANSIFEX_API_TOKEN=""
|
||||||
|
HTTP_HOST="" // URL of your site (used for multisite env and equals to DOMAIN_CURRENT_SITE from wp-config.php)
|
17
RoboFile.php
17
RoboFile.php
@ -153,17 +153,30 @@ class RoboFile extends \Robo\Tasks {
|
|||||||
return $this->_exec('./tasks/transifex_init.sh');
|
return $this->_exec('./tasks/transifex_init.sh');
|
||||||
}
|
}
|
||||||
|
|
||||||
function testUnit($opts=['file' => null, 'xml' => false]) {
|
function testUnit($opts=['file' => null, 'xml' => false, 'multisite' => false]) {
|
||||||
$this->loadEnv();
|
$this->loadEnv();
|
||||||
|
|
||||||
$command = 'vendor/bin/codecept run unit -c codeception.unit.yml -f '.(($opts['file']) ? $opts['file'] : '');
|
$command = 'vendor/bin/codecept run unit -c codeception.unit.yml';
|
||||||
|
|
||||||
|
if($opts['multisite']) {
|
||||||
|
$command = 'MULTISITE=true ' . $command;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($opts['file']) {
|
||||||
|
$command .= ' -f ' . $opts['file'];
|
||||||
|
}
|
||||||
|
|
||||||
if($opts['xml']) {
|
if($opts['xml']) {
|
||||||
$command .= ' --xml';
|
$command .= ' --xml';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->_exec($command);
|
return $this->_exec($command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testMultisiteUnit($opts=['file' => null, 'xml' => false, 'multisite' => true]) {
|
||||||
|
return $this->testUnit($opts);
|
||||||
|
}
|
||||||
|
|
||||||
function testCoverage($opts=['file' => null, 'xml' => false]) {
|
function testCoverage($opts=['file' => null, 'xml' => false]) {
|
||||||
$this->loadEnv();
|
$this->loadEnv();
|
||||||
$command = join(' ', array(
|
$command = join(' ', array(
|
||||||
|
@ -1,6 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
$wp_load_file = getenv('WP_TEST_PATH') . '/wp-load.php';
|
if((boolean)getenv('MULTISITE') === true) {
|
||||||
|
// REQUEST_URI needs to be set for WP to load the proper subsite where MailPoet is activated
|
||||||
|
$_SERVER['REQUEST_URI'] = '/' . getenv('WP_TEST_MULTISITE_SLUG');
|
||||||
|
$wp_load_file = getenv('WP_TEST_PATH_MULTISITE') . '/wp-load.php';
|
||||||
|
} else {
|
||||||
|
$wp_load_file = getenv('WP_TEST_PATH') . '/wp-load.php';
|
||||||
|
}
|
||||||
require_once($wp_load_file);
|
require_once($wp_load_file);
|
||||||
|
|
||||||
$console = new \Codeception\Lib\Console\Output([]);
|
$console = new \Codeception\Lib\Console\Output([]);
|
||||||
|
Reference in New Issue
Block a user