From ca6bde8a64cfc4ba901c64fa482b788f31b7a2ba Mon Sep 17 00:00:00 2001 From: Pavel Dohnal Date: Thu, 18 Jan 2018 12:23:33 +0000 Subject: [PATCH] Add multisite run for acceptance tests [MAILPOET-1193] --- .gitignore | 3 +- RoboFile.php | 4 + codeception.acceptance.yml | 3 +- docker-entrypoint.sh | 72 +++++++++++- tests/_data/acceptanceMultisiteDump.sql | 148 ++++++++++++++++++++++++ 5 files changed, 222 insertions(+), 8 deletions(-) create mode 100644 tests/_data/acceptanceMultisiteDump.sql diff --git a/.gitignore b/.gitignore index 833a4a1cdb..9d195210b2 100644 --- a/.gitignore +++ b/.gitignore @@ -21,4 +21,5 @@ assets/js/*.json .vagrant lang .mp_svn -/nbproject/ \ No newline at end of file +/nbproject/ +tests/_data/acceptanceGenerated.sql \ No newline at end of file diff --git a/RoboFile.php b/RoboFile.php index 0ca0d6698b..66fe60ffb4 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -231,6 +231,10 @@ class RoboFile extends \Robo\Tasks { return $this->_exec('COMPOSE_HTTP_TIMEOUT=200 docker-compose run codeception --steps --debug -vvv'); } + function testAcceptanceMultisite() { + return $this->_exec('COMPOSE_HTTP_TIMEOUT=200 docker-compose run -e MULTISITE=1 codeception --steps --debug -vvv'); + } + function deleteDocker() { return $this->_exec('docker-compose down -v --remove-orphans --rmi all'); } diff --git a/codeception.acceptance.yml b/codeception.acceptance.yml index f83fa641cd..72cec51ffe 100644 --- a/codeception.acceptance.yml +++ b/codeception.acceptance.yml @@ -34,11 +34,12 @@ modules: dbHost: mysql dbUser: wordpress dbPassword: wordpress + domain: wordpress WPDb: dsn: 'mysql:host=mysql;dbname=wordpress' user: wordpress password: wordpress - dump: tests/_data/acceptanceDump.sql + dump: tests/_data/acceptanceGenerated.sql populate: true cleanup: false url: 'http://wordpress' diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 5d1839d78a..fc085fe4b6 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -23,15 +23,75 @@ if ! $(wp-su core is-installed); then echo "Installing WordPress" - wp-su core install --url=wordpress --title=tests --admin_user=admin --admin_email=test@test.com + if [ -z "${MULTISITE}" ] + then + + echo "Running in single site mode" + + wp-su core install --url=wordpress --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=wordpress --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 + +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 - echo "Configuring WordPress" - # The development version of Gravity Flow requires SCRIPT_DEBUG - wp-su core config --dbhost=mysql --dbname=wordpress --dbuser=wordpress --dbpass=wordpress --extra-php="define( 'SCRIPT_DEBUG', true );" --force fi -# Change default table prefix -sed -i "s/\$table_prefix = 'wp_';/\$table_prefix = 'mp_';/" ./wp-config.php +sed -i "s/define( *'WP_DEBUG', false *);/define('WP_DEBUG', true);define('WP_DEBUG_DISPLAY', true);define('WP_DEBUG_LOG', true);/" ./wp-config.php # Load Composer dependencies # Set KEEP_DEPS environment flag to not redownload them on each run, only for the 1st time, useful for development. diff --git a/tests/_data/acceptanceMultisiteDump.sql b/tests/_data/acceptanceMultisiteDump.sql new file mode 100644 index 0000000000..271f272440 --- /dev/null +++ b/tests/_data/acceptanceMultisiteDump.sql @@ -0,0 +1,148 @@ +-- Adminer 4.2.5 MySQL dump + +SET NAMES utf8; +SET time_zone = '+00:00'; +SET foreign_key_checks = 0; +SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO'; + +-- +-- Table structure for table `mp_blog_versions` +-- + +DROP TABLE IF EXISTS `mp_blog_versions`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `mp_blog_versions` ( + `blog_id` bigint(20) NOT NULL DEFAULT '0', + `db_version` varchar(20) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '', + `last_updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + PRIMARY KEY (`blog_id`), + KEY `db_version` (`db_version`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `mp_blog_versions` +-- + +LOCK TABLES `mp_blog_versions` WRITE; +/*!40000 ALTER TABLE `mp_blog_versions` DISABLE KEYS */; +/*!40000 ALTER TABLE `mp_blog_versions` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `mp_blogs` +-- + +DROP TABLE IF EXISTS `mp_blogs`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `mp_blogs` ( + `blog_id` bigint(20) NOT NULL AUTO_INCREMENT, + `site_id` bigint(20) NOT NULL DEFAULT '0', + `domain` varchar(200) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '', + `path` varchar(100) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '', + `registered` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + `last_updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + `public` tinyint(2) NOT NULL DEFAULT '1', + `archived` tinyint(2) NOT NULL DEFAULT '0', + `mature` tinyint(2) NOT NULL DEFAULT '0', + `spam` tinyint(2) NOT NULL DEFAULT '0', + `deleted` tinyint(2) NOT NULL DEFAULT '0', + `lang_id` int(11) NOT NULL DEFAULT '0', + PRIMARY KEY (`blog_id`), + KEY `domain` (`domain`(50),`path`(5)), + KEY `lang_id` (`lang_id`) +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `mp_blogs` +-- + +LOCK TABLES `mp_blogs` WRITE; +/*!40000 ALTER TABLE `mp_blogs` DISABLE KEYS */; +INSERT INTO `mp_blogs` VALUES (1,1,'wordpress','/','2018-01-17 17:08:02','0000-00-00 00:00:00',1,0,0,0,0,0); +/*!40000 ALTER TABLE `mp_blogs` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `mp_registration_log` +-- + +DROP TABLE IF EXISTS `mp_registration_log`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `mp_registration_log` ( + `ID` bigint(20) NOT NULL AUTO_INCREMENT, + `email` varchar(255) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '', + `IP` varchar(30) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '', + `blog_id` bigint(20) NOT NULL DEFAULT '0', + `date_registered` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + PRIMARY KEY (`ID`), + KEY `IP` (`IP`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `mp_registration_log` +-- + +LOCK TABLES `mp_registration_log` WRITE; +/*!40000 ALTER TABLE `mp_registration_log` DISABLE KEYS */; +/*!40000 ALTER TABLE `mp_registration_log` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `mp_site` +-- + +DROP TABLE IF EXISTS `mp_site`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `mp_site` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `domain` varchar(200) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '', + `path` varchar(100) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '', + PRIMARY KEY (`id`), + KEY `domain` (`domain`(140),`path`(51)) +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `mp_site` +-- + +LOCK TABLES `mp_site` WRITE; +/*!40000 ALTER TABLE `mp_site` DISABLE KEYS */; +INSERT INTO `mp_site` VALUES (1,'wordpress','/'); +/*!40000 ALTER TABLE `mp_site` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `mp_sitemeta` +-- + +DROP TABLE IF EXISTS `mp_sitemeta`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `mp_sitemeta` ( + `meta_id` bigint(20) NOT NULL AUTO_INCREMENT, + `site_id` bigint(20) NOT NULL DEFAULT '0', + `meta_key` varchar(255) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL, + `meta_value` longtext COLLATE utf8mb4_unicode_520_ci, + PRIMARY KEY (`meta_id`), + KEY `meta_key` (`meta_key`(191)), + KEY `site_id` (`site_id`) +) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `mp_sitemeta` +-- + +LOCK TABLES `mp_sitemeta` WRITE; +/*!40000 ALTER TABLE `mp_sitemeta` DISABLE KEYS */; +INSERT INTO `mp_sitemeta` VALUES (1,1,'site_name','tests Sites'),(2,1,'admin_email','test@test.com'),(3,1,'admin_user_id','1'),(4,1,'registration','none'),(5,1,'upload_filetypes','jpg jpeg png gif mov avi mpg 3gp 3g2 midi mid pdf doc ppt odt pptx docx pps ppsx xls xlsx key mp3 ogg m4a wav mp4 m4v webm ogv flv'),(6,1,'blog_upload_space','100'),(7,1,'fileupload_maxk','1500'),(8,1,'site_admins','a:1:{i:0;s:5:\"admin\";}'),(9,1,'allowedthemes','a:1:{s:15:\"twentyseventeen\";b:1;}'),(10,1,'illegal_names','a:9:{i:0;s:3:\"www\";i:1;s:3:\"web\";i:2;s:4:\"root\";i:3;s:5:\"admin\";i:4;s:4:\"main\";i:5;s:6:\"invite\";i:6;s:13:\"administrator\";i:7;s:5:\"files\";i:8;s:4:\"blog\";}'),(11,1,'wpmu_upgrade_site','38590'),(12,1,'welcome_email','Howdy USERNAME,\n\nYour new SITE_NAME site has been successfully set up at:\nBLOG_URL\n\nYou can log in to the administrator account with the following information:\n\nUsername: USERNAME\nPassword: PASSWORD\nLog in here: BLOG_URLwp-login.php\n\nWe hope you enjoy your new site. Thanks!\n\n--The Team @ SITE_NAME'),(13,1,'first_post','Welcome to %s. This is your first post. Edit or delete it, then start blogging!'),(14,1,'siteurl','http://wordpress/'),(15,1,'add_new_users','0'),(16,1,'upload_space_check_disabled','1'),(17,1,'subdomain_install','0'),(18,1,'global_terms_enabled','0'),(19,1,'ms_files_rewriting','0'),(20,1,'initial_db_version','38590'),(21,1,'active_sitewide_plugins','a:0:{}'),(22,1,'WPLANG','en_US'); +/*!40000 ALTER TABLE `mp_sitemeta` ENABLE KEYS */; +UNLOCK TABLES;