1
1
#! /usr/bin/env bash
2
2
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"
5
8
exit 1
6
- fi
9
+ }
7
10
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
14
36
15
37
PLUGIN_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/ }
19
40
20
41
download () {
21
42
if [ ` which curl` ]; then
@@ -93,7 +114,7 @@ install_test_suite() {
93
114
sed $ioption " s/youremptytestdbnamehere/$DB_NAME /" " $WP_TESTS_DIR " /wp-tests-config.php
94
115
sed $ioption " s/yourusernamehere/$DB_USER /" " $WP_TESTS_DIR " /wp-tests-config.php
95
116
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
97
118
fi
98
119
99
120
}
@@ -120,43 +141,36 @@ install_db() {
120
141
fi
121
142
fi
122
143
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
134
146
}
135
147
136
148
configure_wordpress () {
137
149
138
150
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]
141
153
wp rewrite structure ' /%year%/%monthnum%/%postname%/'
142
154
}
143
155
144
156
install_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
147
163
}
148
164
149
165
activate_plugins () {
150
166
151
167
# 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
153
171
154
172
cd $WP_CORE_DIR
155
173
156
- # activate the plugin
157
- wp plugin activate wp-graphql
158
- wp plugin activate wp-graphql-jwt-authentication
159
-
160
174
# Flush the permalinks
161
175
wp rewrite flush
162
176
0 commit comments