Skip to content

Commit

Permalink
Merge pull request #153 from wp-graphql/release/v0.5.0
Browse files Browse the repository at this point in the history
Release v0.5.0
  • Loading branch information
jasonbahl authored Apr 15, 2022
2 parents 7905ab9 + 51ca240 commit b98b94e
Show file tree
Hide file tree
Showing 33 changed files with 15,340 additions and 522 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ The plugin offers some filters to hook into.
**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.**

```php
add_filter('graphql_jwt_auth_expire', 60);
function custom_jwt_expiration( $expiration ) {
return 60;
}

add_filter('graphql_jwt_auth_expire', 'custom_jwt_expiration', 10);
```

- Argument: Expiration in seconds
Expand Down
151 changes: 76 additions & 75 deletions bin/install-wp-tests.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
#!/usr/bin/env bash

if [[ ! -f ".env" ]]; then
echo "No .env file was detected. .env.dist has been copied to .env"
echo "Open the .env file and enter values to match your local environment"
cp .env.dist .env
fi

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"
echo "And run the following 'composer build-test' in the project root directory"
exit 1
}

Expand All @@ -20,23 +26,17 @@ if [[ -z "$TEST_DB_USER" ]]; then
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

DB_HOST=${TEST_DB_HOST-localhost}
DB_PASS=${TEST_DB_PASSWORD-""}
WP_VERSION=${WP_VERSION-latest}
TMPDIR=${TMPDIR-/tmp}
TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//")
WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests-lib}
WP_CORE_DIR=${TEST_WP_ROOT_FOLDER-$TMPDIR/wordpress/}
PLUGIN_DIR=$(pwd)
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/}
DB_SERVE_NAME=${DB_SERVE_NAME-wpgatsby_serve}
SKIP_DB_CREATE=${SKIP_DB_CREATE-false}

download() {
if [ `which curl` ]; then
Expand All @@ -46,8 +46,19 @@ download() {
fi
}

if [[ $WP_VERSION =~ [0-9]+\.[0-9]+(\.[0-9]+)? ]]; then
WP_TESTS_TAG="tags/$WP_VERSION"
if [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+\-(beta|RC)[0-9]+$ ]]; then
WP_BRANCH=${WP_VERSION%\-*}
WP_TESTS_TAG="branches/$WP_BRANCH"

elif [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+$ ]]; then
WP_TESTS_TAG="branches/$WP_VERSION"
elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then
if [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then
# version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x
WP_TESTS_TAG="tags/${WP_VERSION%??}"
else
WP_TESTS_TAG="tags/$WP_VERSION"
fi
elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
WP_TESTS_TAG="trunk"
else
Expand All @@ -61,7 +72,6 @@ else
fi
WP_TESTS_TAG="tags/$LATEST_VERSION"
fi

set -ex

install_wp() {
Expand All @@ -73,52 +83,39 @@ install_wp() {
mkdir -p $WP_CORE_DIR

if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
mkdir -p /tmp/wordpress-nightly
download https://wordpress.org/nightly-builds/wordpress-latest.zip /tmp/wordpress-nightly/wordpress-nightly.zip
unzip -q /tmp/wordpress-nightly/wordpress-nightly.zip -d /tmp/wordpress-nightly/
mv /tmp/wordpress-nightly/wordpress/* $WP_CORE_DIR
mkdir -p $TMPDIR/wordpress-nightly
download https://wordpress.org/nightly-builds/wordpress-latest.zip $TMPDIR/wordpress-nightly/wordpress-nightly.zip
unzip -q $TMPDIR/wordpress-nightly/wordpress-nightly.zip -d $TMPDIR/wordpress-nightly/
mv $TMPDIR/wordpress-nightly/wordpress/* $WP_CORE_DIR
else
if [ $WP_VERSION == 'latest' ]; then
local ARCHIVE_NAME='latest'
elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+ ]]; then
# https serves multiple offers, whereas http serves single.
download https://api.wordpress.org/core/version-check/1.7/ $TMPDIR/wp-latest.json
if [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then
# version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x
LATEST_VERSION=${WP_VERSION%??}
else
# otherwise, scan the releases and get the most up to date minor version of the major release
local VERSION_ESCAPED=`echo $WP_VERSION | sed 's/\./\\\\./g'`
LATEST_VERSION=$(grep -o '"version":"'$VERSION_ESCAPED'[^"]*' $TMPDIR/wp-latest.json | sed 's/"version":"//' | head -1)
fi
if [[ -z "$LATEST_VERSION" ]]; then
local ARCHIVE_NAME="wordpress-$WP_VERSION"
else
local ARCHIVE_NAME="wordpress-$LATEST_VERSION"
fi
else
local ARCHIVE_NAME="wordpress-$WP_VERSION"
fi
download https://wordpress.org/${ARCHIVE_NAME}.tar.gz /tmp/wordpress.tar.gz
tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR
download https://wordpress.org/${ARCHIVE_NAME}.tar.gz $TMPDIR/wordpress.tar.gz
tar --strip-components=1 -zxmf $TMPDIR/wordpress.tar.gz -C $WP_CORE_DIR
fi

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

install_test_suite() {
# portable in-place argument for both GNU sed and Mac OSX sed
if [[ $(uname -s) == 'Darwin' ]]; then
local ioption='-i .bak'
else
local ioption='-i'
fi

# set up testing suite if it doesn't yet exist
if [ ! -d $WP_TESTS_DIR ]; then
# set up testing suite
mkdir -p $WP_TESTS_DIR
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data
fi

if [ ! -f wp-tests-config.php ]; then
download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php
# remove all forward slashes in the end
WP_CORE_DIR=$(echo $WP_CORE_DIR | sed "s:/\+$::")
sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php
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
fi

}

install_db() {

if [ ${SKIP_DB_CREATE} = "true" ]; then
Expand Down Expand Up @@ -149,41 +146,45 @@ install_db() {
}

configure_wordpress() {

cd $WP_CORE_DIR
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 core install --url=wp.test --title="WPGraphQL Tests" --admin_user=admin --admin_password=password --admin_email=admin@wp.test
wp rewrite structure '/%year%/%monthnum%/%postname%/'
}

install_wpgraphql() {
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
setup_plugin() {

# Add this repo as a plugin to the repo
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
cd $WP_CORE_DIR/wp-content/plugins
pwd
ls
fi
echo "Activating WPGraphQL"

cd $PLUGIN_DIR

composer install

cd $WP_CORE_DIR

wp plugin install wp-graphql
wp plugin activate wp-graphql
}

activate_plugins() {
wp plugin list

# Add this repo as a plugin to the repo
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
# activate the plugin
wp plugin activate wp-graphql-jwt-authentication

cd $WP_CORE_DIR
# Flush the permalinks
wp rewrite flush

# Flush the permalinks
wp rewrite flush
# Export the db for codeception to use
wp db export $PLUGIN_DIR/tests/_data/dump.sql

# Export the db for codeception to use
wp db export $PLUGIN_DIR/tests/_data/dump.sql
}

install_wp
install_test_suite
install_db
configure_wordpress
install_wpgraphql
activate_plugins
setup_plugin
140 changes: 74 additions & 66 deletions codeception.dist.yml
Original file line number Diff line number Diff line change
@@ -1,72 +1,80 @@
paths:
tests: tests
output: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
tests: '%TESTS_DIR%'
output: '%TESTS_OUTPUT%'
data: '%TESTS_DATA%'
support: '%TESTS_SUPPORT%'
envs: '%TESTS_ENVS%'
params:
- env
- .env
actor_suffix: Tester
settings:
colors: true
memory_limit: 1024M
colors: true
memory_limit: 1024M
coverage:
enabled: true
whitelist:
include:
- wp-graphql-acf.php
- access-functions.php
- src/*.php
enabled: true
remote: false
c3_url: '%WP_URL%/wp-content/plugins/wp-graphql-jwt-authentication/wp-graphql-jwt-authentication.php'
include:
- src/*.php
exclude:
- wp-graphql-jwt-authentication.php
- vendor/*
- packages/*
show_only_summary: false
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
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
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'
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: false
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'
cookies: false
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
activatePlugins:
- wp-graphql/wp-graphql.php
configFile: 'tests/_data/config.php'
Loading

0 comments on commit b98b94e

Please sign in to comment.