Skip to content

Commit 91b76ec

Browse files
authored
Merge pull request #50 from jasonbahl/feature/#49-login-mutation-uses-old-api
#49 - use register_graphql_mutation
2 parents 2b0e5f9 + a6566ff commit 91b76ec

16 files changed

+277
-6733
lines changed

.env.dist

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Shared
2+
TEST_DB_NAME="wptests"
3+
TEST_DB_HOST="127.0.0.1"
4+
TEST_DB_USER="root"
5+
TEST_DB_PASSWORD=""
6+
7+
# Install script
8+
WP_VERSION=latest
9+
SKIP_DB_CREATE=false
10+
11+
# Codeception
12+
WP_ROOT_FOLDER="/tmp/wp-graphql-jwt-authentication/wordpress"
13+
WP_ADMIN_PATH="/wp-admin"
14+
DB_NAME="wptests"
15+
DB_HOST="127.0.0.1"
16+
DB_USER="root"
17+
DB_PASSWORD=""
18+
WP_TABLE_PREFIX="wp_"
19+
WP_URL="http://wp.test"
20+
WP_DOMAIN="wp.test"
21+
ADMIN_EMAIL="admin@wp.test"
22+
ADMIN_USERNAME="admin"
23+
ADMIN_PASSWORD="password"

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@ vendor/*
1313
!vendor/autoload.php
1414
c3.php
1515
!/tests
16-
/tests/*.suite.yml
16+
/tests/*.suite.yml
17+
.env
18+
.codeception.yml
19+
composer.lock

bin/install-wp-tests.sh

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,42 @@
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

1537
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/}
1940

2041
download() {
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

136148
configure_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 --admin_email=admin@wpgraphql.test
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 --admin_email=admin@wpgraphql.test
141153
wp rewrite structure '/%year%/%monthnum%/%postname%/'
142154
}
143155

144156
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
147163
}
148164

149165
activate_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

codeception.dist.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
paths:
2+
tests: tests
3+
output: tests/_output
4+
data: tests/_data
5+
support: tests/_support
6+
envs: tests/_envs
7+
actor_suffix: Tester
8+
settings:
9+
colors: true
10+
memory_limit: 1024M
11+
coverage:
12+
enabled: true
13+
whitelist:
14+
include:
15+
- wp-graphql-acf.php
16+
- access-functions.php
17+
- src/*.php
18+
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
31+
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'

codeception.yml

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ paths:
55
support: tests/_support
66
envs: tests/_envs
77
actor_suffix: Tester
8+
settings:
9+
colors: true
10+
memory_limit: 1024M
811
coverage:
912
enabled: true
10-
c3_url: 'http://wp.localhost/wp-content/plugins/wp-graphql-jwt-authentication/c3.php'
1113
whitelist:
1214
include:
13-
- wp-graphql-jwt-authentication.php
15+
- wp-graphql-acf.php
1416
- access-functions.php
1517
- src/*.php
1618
extensions:
@@ -24,5 +26,46 @@ extensions:
2426
- Codeception\Command\GenerateWPAjax
2527
- Codeception\Command\GenerateWPCanonical
2628
- Codeception\Command\GenerateWPXMLRPC
27-
- Codeception\Command\DbSnapshot
28-
- tad\Codeception\Command\SearchReplace
29+
params:
30+
- .env
31+
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-jwt-authentication/wp-graphql-jwt-authentication.php']
71+
activatePlugins: ['wp-graphql/wp-graphql.php', 'wp-graphql-jwt-authentication/wp-graphql-jwt-authentication.php', ]

composer.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "wp-graphql/wp-graphql-jwt-authentication",
33
"description": "JWT Authentication for WPGraphQL",
44
"type": "wordpress-plugin",
5-
"version": "0.3.1",
5+
"version": "0.3.3",
66
"license": "GPL-3.0+",
77
"authors": [
88
{
@@ -14,10 +14,7 @@
1414
"firebase/php-jwt": "^4.0"
1515
},
1616
"require-dev": {
17-
"satooshi/php-coveralls": "~1.0",
18-
"lucatume/wp-browser": "^1.21",
19-
"codeception/c3": "2.*",
20-
"phpunit/phpcov": "^4.0"
17+
"lucatume/wp-browser": ">=2.2.1 <2.2.8"
2118
},
2219
"config": {
2320
"optimize-autoloader": true

0 commit comments

Comments
 (0)