11#! /usr/bin/env bash
22
3- if [ $# -lt 3 ]; then
4- echo " usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version] [skip-database-creation]"
3+ source .env
4+
5+ print_usage_instruction () {
6+ echo " Ensure that .env file exist in project root directory exists."
7+ echo " And run the following 'composer install-wp-tests' in the project root directory"
58 exit 1
6- fi
9+ }
710
8- DB_NAME=$1
9- DB_USER=$2
10- DB_PASS=$3
11- DB_HOST=${4-localhost}
12- WP_VERSION=${5-latest}
13- SKIP_DB_CREATE=${6-false}
11+ if [[ -z " $TEST_DB_NAME " ]]; then
12+ echo " TEST_DB_NAME not found"
13+ print_usage_instruction
14+ else
15+ DB_NAME=$TEST_DB_NAME
16+ fi
17+ if [[ -z " $TEST_DB_USER " ]]; then
18+ echo " TEST_DB_USER not found"
19+ print_usage_instruction
20+ else
21+ DB_USER=$TEST_DB_USER
22+ fi
23+ if [[ -z " $TEST_DB_PASSWORD " ]]; then
24+ DB_PASS=" "
25+ else
26+ DB_PASS=$TEST_DB_PASSWORD
27+ fi
28+ if [[ -z " $TEST_DB_HOST " ]]; then
29+ DB_HOST=localhost
30+ else
31+ DB_HOST=$TEST_DB_HOST
32+ fi
33+ if [ -z " $SKIP_DB_CREATE " ]; then
34+ SKIP_DB_CREATE=false
35+ fi
1436
1537PLUGIN_DIR=$( pwd)
16- WP_TESTS_DIR=${WP_TESTS_DIR-/ tmp/ wp-graphql-jwt-authentication}
17- WP_CORE_DIR=${WP_CORE_DIR-/ tmp/ wp-graphql-jwt-authentication/ }
18- DB_SERVE_NAME=${DB_SERVE_NAME-wpgraphql_jwt_auth_serve}
38+ WP_TESTS_DIR=${WP_TESTS_DIR-/ tmp/ wp-graphql-jwt-authentication/ wordpress-tests-lib}
39+ WP_CORE_DIR=${WP_CORE_DIR-/ tmp/ wp-graphql-jwt-authentication/ wordpress/ }
1940
2041download () {
2142 if [ ` which curl` ]; then
@@ -93,7 +114,7 @@ install_test_suite() {
93114 sed $ioption " s/youremptytestdbnamehere/$DB_NAME /" " $WP_TESTS_DIR " /wp-tests-config.php
94115 sed $ioption " s/yourusernamehere/$DB_USER /" " $WP_TESTS_DIR " /wp-tests-config.php
95116 sed $ioption " s/yourpasswordhere/$DB_PASS /" " $WP_TESTS_DIR " /wp-tests-config.php
96- sed $ioption " s|localhost|${ DB_HOST} |" " $WP_TESTS_DIR " /wp-tests-config.php
117+ sed $ioption " s|localhost|$DB_HOST |" " $WP_TESTS_DIR " /wp-tests-config.php
97118 fi
98119
99120}
@@ -120,43 +141,36 @@ install_db() {
120141 fi
121142 fi
122143
123-
124- RESULT=` mysql -u $DB_USER --password=" $DB_PASS " --skip-column-names -e " SHOW DATABASES LIKE '$DB_NAME '" `
125- if [ " $RESULT " != $DB_NAME ]; then
126- mysqladmin create $DB_NAME --user=" $DB_USER " --password=" $DB_PASS " $EXTRA
127- fi
128-
129- RESULT_2=` mysql -u $DB_USER --password=" $DB_PASS " --skip-column-names -e " SHOW DATABASES LIKE '$DB_SERVE_NAME '" `
130- if [ " $RESULT_2 " != $DB_SERVE_NAME ]; then
131- mysqladmin create $DB_SERVE_NAME --user=" $DB_USER " --password=" $DB_PASS " $EXTRA
132- fi
133-
144+ # create database
145+ mysqladmin create $DB_NAME --user=" $DB_USER " --password=" $DB_PASS " $EXTRA
134146}
135147
136148configure_wordpress () {
137149
138150 cd $WP_CORE_DIR
139- wp config create --dbname=" $DB_SERVE_NAME " --dbuser=root --dbpass=" $DB_PASS " --dbhost=" $DB_HOST " --skip-check --force=true
140- wp core install --url=wpgraphql.test --title=
" WPGraphQL Tests" --admin_user=admin --admin_password=password
[email protected] 151+ wp config create --dbname=" $DB_NAME " --dbuser=" $DB_USER " --dbpass=" $DB_PASS " --dbhost=" $DB_HOST " --skip-check --force=true
152+ wp core install --url=wpgraphql.test --title=
" WPGraphQL jwt-authentication Tests" --admin_user=admin --admin_password=password
[email protected] 141153 wp rewrite structure ' /%year%/%monthnum%/%postname%/'
142154}
143155
144156install_wpgraphql () {
145- echo " Cloning WPGraphQL"
146- git clone https://github.com/wp-graphql/wp-graphql.git $WP_CORE_DIR /wp-content/plugins/wp-graphql
157+ if [ ! -d $WP_CORE_DIR /wp-content/plugins/wp-graphql ]; then
158+ echo " Cloning WPGraphQL"
159+ git clone https://github.com/wp-graphql/wp-graphql.git $WP_CORE_DIR /wp-content/plugins/wp-graphql
160+ fi
161+ echo " Activating WPGraphQL"
162+ wp plugin activate wp-graphql
147163}
148164
149165activate_plugins () {
150166
151167 # Add this repo as a plugin to the repo
152- ln -s $PLUGIN_DIR $WP_CORE_DIR /wp-content/plugins/wp-graphql-jwt-authentication
168+ if [ ! -d $WP_CORE_DIR /wp-content/plugins/wp-graphql-jwt-authentication ]; then
169+ ln -s $PLUGIN_DIR $WP_CORE_DIR /wp-content/plugins/wp-graphql-jwt-authentication
170+ fi
153171
154172 cd $WP_CORE_DIR
155173
156- # activate the plugin
157- wp plugin activate wp-graphql
158- wp plugin activate wp-graphql-jwt-authentication
159-
160174 # Flush the permalinks
161175 wp rewrite flush
162176
0 commit comments