Skip to content

Commit b98b94e

Browse files
authored
Merge pull request #153 from wp-graphql/release/v0.5.0
Release v0.5.0
2 parents 7905ab9 + 51ca240 commit b98b94e

33 files changed

+15340
-522
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,11 @@ The plugin offers some filters to hook into.
130130
**Note: For security, we highly recommend, that the Auth Token is short lived. So do not set this higher than 300 seconds unless you know what you are doing.**
131131

132132
```php
133-
add_filter('graphql_jwt_auth_expire', 60);
133+
function custom_jwt_expiration( $expiration ) {
134+
return 60;
135+
}
136+
137+
add_filter('graphql_jwt_auth_expire', 'custom_jwt_expiration', 10);
134138
```
135139

136140
- Argument: Expiration in seconds

bin/install-wp-tests.sh

Lines changed: 76 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
#!/usr/bin/env bash
22

3+
if [[ ! -f ".env" ]]; then
4+
echo "No .env file was detected. .env.dist has been copied to .env"
5+
echo "Open the .env file and enter values to match your local environment"
6+
cp .env.dist .env
7+
fi
8+
39
source .env
410

511
print_usage_instruction() {
612
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"
13+
echo "And run the following 'composer build-test' in the project root directory"
814
exit 1
915
}
1016

@@ -20,23 +26,17 @@ if [[ -z "$TEST_DB_USER" ]]; then
2026
else
2127
DB_USER=$TEST_DB_USER
2228
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
3629

30+
DB_HOST=${TEST_DB_HOST-localhost}
31+
DB_PASS=${TEST_DB_PASSWORD-""}
32+
WP_VERSION=${WP_VERSION-latest}
33+
TMPDIR=${TMPDIR-/tmp}
34+
TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//")
35+
WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests-lib}
36+
WP_CORE_DIR=${TEST_WP_ROOT_FOLDER-$TMPDIR/wordpress/}
3737
PLUGIN_DIR=$(pwd)
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/}
38+
DB_SERVE_NAME=${DB_SERVE_NAME-wpgatsby_serve}
39+
SKIP_DB_CREATE=${SKIP_DB_CREATE-false}
4040

4141
download() {
4242
if [ `which curl` ]; then
@@ -46,8 +46,19 @@ download() {
4646
fi
4747
}
4848

49-
if [[ $WP_VERSION =~ [0-9]+\.[0-9]+(\.[0-9]+)? ]]; then
50-
WP_TESTS_TAG="tags/$WP_VERSION"
49+
if [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+\-(beta|RC)[0-9]+$ ]]; then
50+
WP_BRANCH=${WP_VERSION%\-*}
51+
WP_TESTS_TAG="branches/$WP_BRANCH"
52+
53+
elif [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+$ ]]; then
54+
WP_TESTS_TAG="branches/$WP_VERSION"
55+
elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then
56+
if [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then
57+
# version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x
58+
WP_TESTS_TAG="tags/${WP_VERSION%??}"
59+
else
60+
WP_TESTS_TAG="tags/$WP_VERSION"
61+
fi
5162
elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
5263
WP_TESTS_TAG="trunk"
5364
else
@@ -61,7 +72,6 @@ else
6172
fi
6273
WP_TESTS_TAG="tags/$LATEST_VERSION"
6374
fi
64-
6575
set -ex
6676

6777
install_wp() {
@@ -73,52 +83,39 @@ install_wp() {
7383
mkdir -p $WP_CORE_DIR
7484

7585
if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
76-
mkdir -p /tmp/wordpress-nightly
77-
download https://wordpress.org/nightly-builds/wordpress-latest.zip /tmp/wordpress-nightly/wordpress-nightly.zip
78-
unzip -q /tmp/wordpress-nightly/wordpress-nightly.zip -d /tmp/wordpress-nightly/
79-
mv /tmp/wordpress-nightly/wordpress/* $WP_CORE_DIR
86+
mkdir -p $TMPDIR/wordpress-nightly
87+
download https://wordpress.org/nightly-builds/wordpress-latest.zip $TMPDIR/wordpress-nightly/wordpress-nightly.zip
88+
unzip -q $TMPDIR/wordpress-nightly/wordpress-nightly.zip -d $TMPDIR/wordpress-nightly/
89+
mv $TMPDIR/wordpress-nightly/wordpress/* $WP_CORE_DIR
8090
else
8191
if [ $WP_VERSION == 'latest' ]; then
8292
local ARCHIVE_NAME='latest'
93+
elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+ ]]; then
94+
# https serves multiple offers, whereas http serves single.
95+
download https://api.wordpress.org/core/version-check/1.7/ $TMPDIR/wp-latest.json
96+
if [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then
97+
# version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x
98+
LATEST_VERSION=${WP_VERSION%??}
99+
else
100+
# otherwise, scan the releases and get the most up to date minor version of the major release
101+
local VERSION_ESCAPED=`echo $WP_VERSION | sed 's/\./\\\\./g'`
102+
LATEST_VERSION=$(grep -o '"version":"'$VERSION_ESCAPED'[^"]*' $TMPDIR/wp-latest.json | sed 's/"version":"//' | head -1)
103+
fi
104+
if [[ -z "$LATEST_VERSION" ]]; then
105+
local ARCHIVE_NAME="wordpress-$WP_VERSION"
106+
else
107+
local ARCHIVE_NAME="wordpress-$LATEST_VERSION"
108+
fi
83109
else
84110
local ARCHIVE_NAME="wordpress-$WP_VERSION"
85111
fi
86-
download https://wordpress.org/${ARCHIVE_NAME}.tar.gz /tmp/wordpress.tar.gz
87-
tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR
112+
download https://wordpress.org/${ARCHIVE_NAME}.tar.gz $TMPDIR/wordpress.tar.gz
113+
tar --strip-components=1 -zxmf $TMPDIR/wordpress.tar.gz -C $WP_CORE_DIR
88114
fi
89115

90116
download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php
91117
}
92118

93-
install_test_suite() {
94-
# portable in-place argument for both GNU sed and Mac OSX sed
95-
if [[ $(uname -s) == 'Darwin' ]]; then
96-
local ioption='-i .bak'
97-
else
98-
local ioption='-i'
99-
fi
100-
101-
# set up testing suite if it doesn't yet exist
102-
if [ ! -d $WP_TESTS_DIR ]; then
103-
# set up testing suite
104-
mkdir -p $WP_TESTS_DIR
105-
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
106-
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data
107-
fi
108-
109-
if [ ! -f wp-tests-config.php ]; then
110-
download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php
111-
# remove all forward slashes in the end
112-
WP_CORE_DIR=$(echo $WP_CORE_DIR | sed "s:/\+$::")
113-
sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php
114-
sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php
115-
sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php
116-
sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php
117-
sed $ioption "s|localhost|$DB_HOST|" "$WP_TESTS_DIR"/wp-tests-config.php
118-
fi
119-
120-
}
121-
122119
install_db() {
123120

124121
if [ ${SKIP_DB_CREATE} = "true" ]; then
@@ -149,41 +146,45 @@ install_db() {
149146
}
150147

151148
configure_wordpress() {
152-
153149
cd $WP_CORE_DIR
154150
wp config create --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST" --skip-check --force=true
155-
wp core install --url=wpgraphql.test --title="WPGraphQL jwt-authentication Tests" --admin_user=admin --admin_password=password --admin_email=admin@wpgraphql.test
151+
wp core install --url=wp.test --title="WPGraphQL Tests" --admin_user=admin --admin_password=password --admin_email=admin@wp.test
156152
wp rewrite structure '/%year%/%monthnum%/%postname%/'
157153
}
158154

159-
install_wpgraphql() {
160-
if [ ! -d $WP_CORE_DIR/wp-content/plugins/wp-graphql ]; then
161-
echo "Cloning WPGraphQL"
162-
git clone https://github.com/wp-graphql/wp-graphql.git $WP_CORE_DIR/wp-content/plugins/wp-graphql
155+
setup_plugin() {
156+
157+
# Add this repo as a plugin to the repo
158+
if [ ! -d $WP_CORE_DIR/wp-content/plugins/wp-graphql-jwt-authentication ]; then
159+
ln -s $PLUGIN_DIR $WP_CORE_DIR/wp-content/plugins/wp-graphql-jwt-authentication
160+
cd $WP_CORE_DIR/wp-content/plugins
161+
pwd
162+
ls
163163
fi
164-
echo "Activating WPGraphQL"
164+
165+
cd $PLUGIN_DIR
166+
167+
composer install
168+
169+
cd $WP_CORE_DIR
170+
171+
wp plugin install wp-graphql
165172
wp plugin activate wp-graphql
166-
}
167173

168-
activate_plugins() {
174+
wp plugin list
169175

170-
# Add this repo as a plugin to the repo
171-
if [ ! -d $WP_CORE_DIR/wp-content/plugins/wp-graphql-jwt-authentication ]; then
172-
ln -s $PLUGIN_DIR $WP_CORE_DIR/wp-content/plugins/wp-graphql-jwt-authentication
173-
fi
176+
# activate the plugin
177+
wp plugin activate wp-graphql-jwt-authentication
174178

175-
cd $WP_CORE_DIR
179+
# Flush the permalinks
180+
wp rewrite flush
176181

177-
# Flush the permalinks
178-
wp rewrite flush
182+
# Export the db for codeception to use
183+
wp db export $PLUGIN_DIR/tests/_data/dump.sql
179184

180-
# Export the db for codeception to use
181-
wp db export $PLUGIN_DIR/tests/_data/dump.sql
182185
}
183186

184187
install_wp
185-
install_test_suite
186188
install_db
187189
configure_wordpress
188-
install_wpgraphql
189-
activate_plugins
190+
setup_plugin

codeception.dist.yml

Lines changed: 74 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,80 @@
11
paths:
2-
tests: tests
3-
output: tests/_output
4-
data: tests/_data
5-
support: tests/_support
6-
envs: tests/_envs
2+
tests: '%TESTS_DIR%'
3+
output: '%TESTS_OUTPUT%'
4+
data: '%TESTS_DATA%'
5+
support: '%TESTS_SUPPORT%'
6+
envs: '%TESTS_ENVS%'
7+
params:
8+
- env
9+
- .env
710
actor_suffix: Tester
811
settings:
9-
colors: true
10-
memory_limit: 1024M
12+
colors: true
13+
memory_limit: 1024M
1114
coverage:
12-
enabled: true
13-
whitelist:
14-
include:
15-
- wp-graphql-acf.php
16-
- access-functions.php
17-
- src/*.php
15+
enabled: true
16+
remote: false
17+
c3_url: '%WP_URL%/wp-content/plugins/wp-graphql-jwt-authentication/wp-graphql-jwt-authentication.php'
18+
include:
19+
- src/*.php
20+
exclude:
21+
- wp-graphql-jwt-authentication.php
22+
- vendor/*
23+
- packages/*
24+
show_only_summary: false
1825
extensions:
19-
enabled:
20-
- Codeception\Extension\RunFailed
21-
commands:
22-
- Codeception\Command\GenerateWPUnit
23-
- Codeception\Command\GenerateWPRestApi
24-
- Codeception\Command\GenerateWPRestController
25-
- Codeception\Command\GenerateWPRestPostTypeController
26-
- Codeception\Command\GenerateWPAjax
27-
- Codeception\Command\GenerateWPCanonical
28-
- Codeception\Command\GenerateWPXMLRPC
29-
params:
30-
- .env.dist
26+
enabled:
27+
- Codeception\Extension\RunFailed
28+
commands:
29+
- Codeception\Command\GenerateWPUnit
30+
- Codeception\Command\GenerateWPRestApi
31+
- Codeception\Command\GenerateWPRestController
32+
- Codeception\Command\GenerateWPRestPostTypeController
33+
- Codeception\Command\GenerateWPAjax
34+
- Codeception\Command\GenerateWPCanonical
35+
- Codeception\Command\GenerateWPXMLRPC
3136
modules:
32-
config:
33-
WPDb:
34-
dsn: 'mysql:host=%DB_HOST%;dbname=%DB_NAME%'
35-
user: '%DB_USER%'
36-
password: '%DB_PASSWORD%'
37-
populator: 'mysql -u $user -p$password -h $host $dbname < $dump'
38-
dump: 'tests/_data/dump.sql'
39-
populate: true
40-
cleanup: true
41-
waitlock: 0
42-
url: '%WP_URL%'
43-
urlReplacement: true
44-
tablePrefix: '%WP_TABLE_PREFIX%'
45-
WPBrowser:
46-
url: '%WP_URL%'
47-
wpRootFolder: '%WP_ROOT_FOLDER%'
48-
adminUsername: '%ADMIN_USERNAME%'
49-
adminPassword: '%ADMIN_PASSWORD%'
50-
adminPath: '/wp-admin'
51-
REST:
52-
depends: WPBrowser
53-
url: '%WP_URL%'
54-
WPFilesystem:
55-
wpRootFolder: '%WP_ROOT_FOLDER%'
56-
plugins: '/wp-content/plugins'
57-
mu-plugins: '/wp-content/mu-plugins'
58-
themes: '/wp-content/themes'
59-
uploads: '/wp-content/uploads'
60-
WPLoader:
61-
wpRootFolder: '%WP_ROOT_FOLDER%'
62-
dbName: '%DB_NAME%'
63-
dbHost: '%DB_HOST%'
64-
dbUser: '%DB_USER%'
65-
dbPassword: '%DB_PASSWORD%'
66-
tablePrefix: '%WP_TABLE_PREFIX%'
67-
domain: '%WP_DOMAIN%'
68-
adminEmail: '%ADMIN_EMAIL%'
69-
title: 'Test'
70-
plugins: ['wp-graphql/wp-graphql.php', 'wp-graphql/wp-graphql-jwt-authentication.php']
71-
activatePlugins: ['wp-graphql/wp-graphql.php', 'wp-graphql/wp-graphql-jwt-authentication.php', ]
72-
configFile: 'tests/_data/config.php'
37+
config:
38+
WPDb:
39+
dsn: 'mysql:host=%DB_HOST%;dbname=%DB_NAME%'
40+
user: '%DB_USER%'
41+
password: '%DB_PASSWORD%'
42+
populator: 'mysql -u $user -p$password -h $host $dbname < $dump'
43+
dump: 'tests/_data/dump.sql'
44+
populate: false
45+
cleanup: true
46+
waitlock: 0
47+
url: '%WP_URL%'
48+
urlReplacement: true
49+
tablePrefix: '%WP_TABLE_PREFIX%'
50+
WPBrowser:
51+
url: '%WP_URL%'
52+
wpRootFolder: '%WP_ROOT_FOLDER%'
53+
adminUsername: '%ADMIN_USERNAME%'
54+
adminPassword: '%ADMIN_PASSWORD%'
55+
adminPath: '/wp-admin'
56+
cookies: false
57+
REST:
58+
depends: WPBrowser
59+
url: '%WP_URL%'
60+
WPFilesystem:
61+
wpRootFolder: '%WP_ROOT_FOLDER%'
62+
plugins: '/wp-content/plugins'
63+
mu-plugins: '/wp-content/mu-plugins'
64+
themes: '/wp-content/themes'
65+
uploads: '/wp-content/uploads'
66+
WPLoader:
67+
wpRootFolder: '%WP_ROOT_FOLDER%'
68+
dbName: '%DB_NAME%'
69+
dbHost: '%DB_HOST%'
70+
dbUser: '%DB_USER%'
71+
dbPassword: '%DB_PASSWORD%'
72+
tablePrefix: '%WP_TABLE_PREFIX%'
73+
domain: '%WP_DOMAIN%'
74+
adminEmail: '%ADMIN_EMAIL%'
75+
title: 'Test'
76+
plugins:
77+
- wp-graphql/wp-graphql.php
78+
activatePlugins:
79+
- wp-graphql/wp-graphql.php
80+
configFile: 'tests/_data/config.php'

0 commit comments

Comments
 (0)