Skip to content

Commit

Permalink
Merge pull request #50 from jasonbahl/feature/#49-login-mutation-uses…
Browse files Browse the repository at this point in the history
…-old-api

#49 - use register_graphql_mutation
  • Loading branch information
jasonbahl authored Oct 18, 2019
2 parents 2b0e5f9 + a6566ff commit 91b76ec
Show file tree
Hide file tree
Showing 16 changed files with 277 additions and 6,733 deletions.
23 changes: 23 additions & 0 deletions .env.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Shared
TEST_DB_NAME="wptests"
TEST_DB_HOST="127.0.0.1"
TEST_DB_USER="root"
TEST_DB_PASSWORD=""

# Install script
WP_VERSION=latest
SKIP_DB_CREATE=false

# Codeception
WP_ROOT_FOLDER="/tmp/wp-graphql-jwt-authentication/wordpress"
WP_ADMIN_PATH="/wp-admin"
DB_NAME="wptests"
DB_HOST="127.0.0.1"
DB_USER="root"
DB_PASSWORD=""
WP_TABLE_PREFIX="wp_"
WP_URL="http://wp.test"
WP_DOMAIN="wp.test"
ADMIN_EMAIL="admin@wp.test"
ADMIN_USERNAME="admin"
ADMIN_PASSWORD="password"
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ vendor/*
!vendor/autoload.php
c3.php
!/tests
/tests/*.suite.yml
/tests/*.suite.yml
.env
.codeception.yml
composer.lock
80 changes: 47 additions & 33 deletions bin/install-wp-tests.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,42 @@
#!/usr/bin/env bash

if [ $# -lt 3 ]; then
echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version] [skip-database-creation]"
source .env

print_usage_instruction() {
echo "Ensure that .env file exist in project root directory exists."
echo "And run the following 'composer install-wp-tests' in the project root directory"
exit 1
fi
}

DB_NAME=$1
DB_USER=$2
DB_PASS=$3
DB_HOST=${4-localhost}
WP_VERSION=${5-latest}
SKIP_DB_CREATE=${6-false}
if [[ -z "$TEST_DB_NAME" ]]; then
echo "TEST_DB_NAME not found"
print_usage_instruction
else
DB_NAME=$TEST_DB_NAME
fi
if [[ -z "$TEST_DB_USER" ]]; then
echo "TEST_DB_USER not found"
print_usage_instruction
else
DB_USER=$TEST_DB_USER
fi
if [[ -z "$TEST_DB_PASSWORD" ]]; then
DB_PASS=""
else
DB_PASS=$TEST_DB_PASSWORD
fi
if [[ -z "$TEST_DB_HOST" ]]; then
DB_HOST=localhost
else
DB_HOST=$TEST_DB_HOST
fi
if [ -z "$SKIP_DB_CREATE" ]; then
SKIP_DB_CREATE=false
fi

PLUGIN_DIR=$(pwd)
WP_TESTS_DIR=${WP_TESTS_DIR-/tmp/wp-graphql-jwt-authentication}
WP_CORE_DIR=${WP_CORE_DIR-/tmp/wp-graphql-jwt-authentication/}
DB_SERVE_NAME=${DB_SERVE_NAME-wpgraphql_jwt_auth_serve}
WP_TESTS_DIR=${WP_TESTS_DIR-/tmp/wp-graphql-jwt-authentication/wordpress-tests-lib}
WP_CORE_DIR=${WP_CORE_DIR-/tmp/wp-graphql-jwt-authentication/wordpress/}

download() {
if [ `which curl` ]; then
Expand Down Expand Up @@ -93,7 +114,7 @@ install_test_suite() {
sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s|localhost|$DB_HOST|" "$WP_TESTS_DIR"/wp-tests-config.php
fi

}
Expand All @@ -120,43 +141,36 @@ install_db() {
fi
fi


RESULT=`mysql -u $DB_USER --password="$DB_PASS" --skip-column-names -e "SHOW DATABASES LIKE '$DB_NAME'"`
if [ "$RESULT" != $DB_NAME ]; then
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
fi

RESULT_2=`mysql -u $DB_USER --password="$DB_PASS" --skip-column-names -e "SHOW DATABASES LIKE '$DB_SERVE_NAME'"`
if [ "$RESULT_2" != $DB_SERVE_NAME ]; then
mysqladmin create $DB_SERVE_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
fi

# create database
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
}

configure_wordpress() {

cd $WP_CORE_DIR
wp config create --dbname="$DB_SERVE_NAME" --dbuser=root --dbpass="$DB_PASS" --dbhost="$DB_HOST" --skip-check --force=true
wp core install --url=wpgraphql.test --title="WPGraphQL Tests" --admin_user=admin --admin_password=password --admin_email=admin@wpgraphql.test
wp config create --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST" --skip-check --force=true
wp core install --url=wpgraphql.test --title="WPGraphQL jwt-authentication Tests" --admin_user=admin --admin_password=password --admin_email=admin@wpgraphql.test
wp rewrite structure '/%year%/%monthnum%/%postname%/'
}

install_wpgraphql() {
echo "Cloning WPGraphQL"
git clone https://github.com/wp-graphql/wp-graphql.git $WP_CORE_DIR/wp-content/plugins/wp-graphql
if [ ! -d $WP_CORE_DIR/wp-content/plugins/wp-graphql ]; then
echo "Cloning WPGraphQL"
git clone https://github.com/wp-graphql/wp-graphql.git $WP_CORE_DIR/wp-content/plugins/wp-graphql
fi
echo "Activating WPGraphQL"
wp plugin activate wp-graphql
}

activate_plugins() {

# Add this repo as a plugin to the repo
ln -s $PLUGIN_DIR $WP_CORE_DIR/wp-content/plugins/wp-graphql-jwt-authentication
if [ ! -d $WP_CORE_DIR/wp-content/plugins/wp-graphql-jwt-authentication ]; then
ln -s $PLUGIN_DIR $WP_CORE_DIR/wp-content/plugins/wp-graphql-jwt-authentication
fi

cd $WP_CORE_DIR

# activate the plugin
wp plugin activate wp-graphql
wp plugin activate wp-graphql-jwt-authentication

# Flush the permalinks
wp rewrite flush

Expand Down
72 changes: 72 additions & 0 deletions codeception.dist.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
paths:
tests: tests
output: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
actor_suffix: Tester
settings:
colors: true
memory_limit: 1024M
coverage:
enabled: true
whitelist:
include:
- wp-graphql-acf.php
- access-functions.php
- src/*.php
extensions:
enabled:
- Codeception\Extension\RunFailed
commands:
- Codeception\Command\GenerateWPUnit
- Codeception\Command\GenerateWPRestApi
- Codeception\Command\GenerateWPRestController
- Codeception\Command\GenerateWPRestPostTypeController
- Codeception\Command\GenerateWPAjax
- Codeception\Command\GenerateWPCanonical
- Codeception\Command\GenerateWPXMLRPC
params:
- .env.dist
modules:
config:
WPDb:
dsn: 'mysql:host=%DB_HOST%;dbname=%DB_NAME%'
user: '%DB_USER%'
password: '%DB_PASSWORD%'
populator: 'mysql -u $user -p$password -h $host $dbname < $dump'
dump: 'tests/_data/dump.sql'
populate: true
cleanup: true
waitlock: 0
url: '%WP_URL%'
urlReplacement: true
tablePrefix: '%WP_TABLE_PREFIX%'
WPBrowser:
url: '%WP_URL%'
wpRootFolder: '%WP_ROOT_FOLDER%'
adminUsername: '%ADMIN_USERNAME%'
adminPassword: '%ADMIN_PASSWORD%'
adminPath: '/wp-admin'
REST:
depends: WPBrowser
url: '%WP_URL%'
WPFilesystem:
wpRootFolder: '%WP_ROOT_FOLDER%'
plugins: '/wp-content/plugins'
mu-plugins: '/wp-content/mu-plugins'
themes: '/wp-content/themes'
uploads: '/wp-content/uploads'
WPLoader:
wpRootFolder: '%WP_ROOT_FOLDER%'
dbName: '%DB_NAME%'
dbHost: '%DB_HOST%'
dbUser: '%DB_USER%'
dbPassword: '%DB_PASSWORD%'
tablePrefix: '%WP_TABLE_PREFIX%'
domain: '%WP_DOMAIN%'
adminEmail: '%ADMIN_EMAIL%'
title: 'Test'
plugins: ['wp-graphql/wp-graphql.php', 'wp-graphql/wp-graphql-jwt-authentication.php']
activatePlugins: ['wp-graphql/wp-graphql.php', 'wp-graphql/wp-graphql-jwt-authentication.php', ]
configFile: 'tests/_data/config.php'
51 changes: 47 additions & 4 deletions codeception.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ paths:
support: tests/_support
envs: tests/_envs
actor_suffix: Tester
settings:
colors: true
memory_limit: 1024M
coverage:
enabled: true
c3_url: 'http://wp.localhost/wp-content/plugins/wp-graphql-jwt-authentication/c3.php'
whitelist:
include:
- wp-graphql-jwt-authentication.php
- wp-graphql-acf.php
- access-functions.php
- src/*.php
extensions:
Expand All @@ -24,5 +26,46 @@ extensions:
- Codeception\Command\GenerateWPAjax
- Codeception\Command\GenerateWPCanonical
- Codeception\Command\GenerateWPXMLRPC
- Codeception\Command\DbSnapshot
- tad\Codeception\Command\SearchReplace
params:
- .env
modules:
config:
WPDb:
dsn: 'mysql:host=%DB_HOST%;dbname=%DB_NAME%'
user: '%DB_USER%'
password: '%DB_PASSWORD%'
populator: 'mysql -u $user -p$password -h $host $dbname < $dump'
dump: 'tests/_data/dump.sql'
populate: true
cleanup: true
waitlock: 0
url: '%WP_URL%'
urlReplacement: true
tablePrefix: '%WP_TABLE_PREFIX%'
WPBrowser:
url: '%WP_URL%'
wpRootFolder: '%WP_ROOT_FOLDER%'
adminUsername: '%ADMIN_USERNAME%'
adminPassword: '%ADMIN_PASSWORD%'
adminPath: '/wp-admin'
REST:
depends: WPBrowser
url: '%WP_URL%'
WPFilesystem:
wpRootFolder: '%WP_ROOT_FOLDER%'
plugins: '/wp-content/plugins'
mu-plugins: '/wp-content/mu-plugins'
themes: '/wp-content/themes'
uploads: '/wp-content/uploads'
WPLoader:
wpRootFolder: '%WP_ROOT_FOLDER%'
dbName: '%DB_NAME%'
dbHost: '%DB_HOST%'
dbUser: '%DB_USER%'
dbPassword: '%DB_PASSWORD%'
tablePrefix: '%WP_TABLE_PREFIX%'
domain: '%WP_DOMAIN%'
adminEmail: '%ADMIN_EMAIL%'
title: 'Test'
plugins: ['wp-graphql/wp-graphql.php', 'wp-graphql-jwt-authentication/wp-graphql-jwt-authentication.php']
activatePlugins: ['wp-graphql/wp-graphql.php', 'wp-graphql-jwt-authentication/wp-graphql-jwt-authentication.php', ]
7 changes: 2 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "wp-graphql/wp-graphql-jwt-authentication",
"description": "JWT Authentication for WPGraphQL",
"type": "wordpress-plugin",
"version": "0.3.1",
"version": "0.3.3",
"license": "GPL-3.0+",
"authors": [
{
Expand All @@ -14,10 +14,7 @@
"firebase/php-jwt": "^4.0"
},
"require-dev": {
"satooshi/php-coveralls": "~1.0",
"lucatume/wp-browser": "^1.21",
"codeception/c3": "2.*",
"phpunit/phpcov": "^4.0"
"lucatume/wp-browser": ">=2.2.1 <2.2.8"
},
"config": {
"optimize-autoloader": true
Expand Down
Loading

0 comments on commit 91b76ec

Please sign in to comment.