diff --git a/.circleci/apache/mailpoet.loc.conf b/.circleci/apache/mailpoet.loc.conf index 68b4ac95f3..7130cf473d 100644 --- a/.circleci/apache/mailpoet.loc.conf +++ b/.circleci/apache/mailpoet.loc.conf @@ -1,6 +1,4 @@ -Listen 8080 - - + UseCanonicalName Off ServerName mailpoet.loc DocumentRoot /home/circleci/mailpoet/wordpress @@ -8,6 +6,9 @@ Listen 8080 LogLevel notice + Options Indexes FollowSymLinks + AllowOverride All + RewriteEngine On Require all granted diff --git a/.circleci/config.yml b/.circleci/config.yml index 691e3ca16e..3fbdd28cb7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -120,7 +120,38 @@ jobs: - run: name: "PHP Unit tests" 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: path: tests/_output - store_artifacts: @@ -135,4 +166,5 @@ workflows: jobs: - qa_js_php5 - php7 - - acceptance_tests + - php7_multisite + - acceptance_tests \ No newline at end of file diff --git a/.circleci/setup.bash b/.circleci/setup.bash index 00ae6ca9ef..53630063f7 100644 --- a/.circleci/setup.bash +++ b/.circleci/setup.bash @@ -2,8 +2,11 @@ function setup { local version=$1 + local wp_cli_wordpress_path="--path=wordpress" + local wp_cli_allow_root="--allow-root" + # 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-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 - @@ -15,35 +18,66 @@ function setup { sudo apt-get install mysql-client php5-mysql zlib1g-dev sudo docker-php-ext-install mysql mysqli pdo pdo_mysql zip fi + # Add a fake sendmail mailer sudo cp ./.circleci/fake-sendmail.php /usr/local/bin/ + # configure Apache sudo cp ./.circleci/mailpoet_php.ini /usr/local/etc/php/conf.d/ sudo cp ./.circleci/apache/mailpoet.loc.conf /etc/apache2/sites-available + sudo a2dissite 000-default.conf sudo a2ensite mailpoet.loc sudo a2enmod rewrite sudo service apache2 restart + # Install NodeJS+NPM curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash - sudo apt-get install nodejs build-essential + # install plugin dependencies curl -sS https://getcomposer.org/installer | php ./composer.phar install ./do install - # Set up Wordpress + + # Set up 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 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 - 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 + # 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 ln -s ../../.. wordpress/wp-content/plugins/mailpoet - ./wp-cli.phar plugin activate mailpoet --path=wordpress - # Create .env file with correct path to WP installation - # TODO: Remove this line after PR gets merged and CircleCI env variables change - echo "WP_TEST_PATH=\"/home/circleci/mailpoet/wordpress\"" > .env -} + + # Activate plugin + if [[ $version == "php7_multisite" ]]; then + 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 +} \ No newline at end of file diff --git a/.circleci/wordpress/.htaccess b/.circleci/wordpress/.htaccess new file mode 100644 index 0000000000..01e10f8805 --- /dev/null +++ b/.circleci/wordpress/.htaccess @@ -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] diff --git a/.env.sample b/.env.sample index 8aadc87daf..09cc17ca5e 100644 --- a/.env.sample +++ b/.env.sample @@ -1,4 +1,6 @@ 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_IMPORT_MAILCHIMP_API="" WP_TEST_IMPORT_MAILCHIMP_LISTS="" // (separated with comma) @@ -16,4 +18,5 @@ WP_TEST_MAILER_SMTP_LOGIN="" WP_TEST_MAILER_SMTP_PASSWORD="" WP_SVN_USERNAME="" WP_SVN_PASSWORD="" -WP_TRANSIFEX_API_TOKEN="" \ No newline at end of file +WP_TRANSIFEX_API_TOKEN="" +HTTP_HOST="" // URL of your site (used for multisite env and equals to DOMAIN_CURRENT_SITE from wp-config.php) \ No newline at end of file diff --git a/RoboFile.php b/RoboFile.php index 8377ee0b0e..5876d21bb9 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -153,17 +153,30 @@ class RoboFile extends \Robo\Tasks { 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(); - $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']) { $command .= ' --xml'; } + return $this->_exec($command); } + function testMultisiteUnit($opts=['file' => null, 'xml' => false, 'multisite' => true]) { + return $this->testUnit($opts); + } + function testCoverage($opts=['file' => null, 'xml' => false]) { $this->loadEnv(); $command = join(' ', array( diff --git a/tests/_bootstrap.php b/tests/_bootstrap.php index 781d5f8019..79ed66a858 100644 --- a/tests/_bootstrap.php +++ b/tests/_bootstrap.php @@ -1,6 +1,12 @@