Skip to content

Commit

Permalink
wip: run tests within wp-env
Browse files Browse the repository at this point in the history
  • Loading branch information
Vicente Canales committed Jul 17, 2023
1 parent 1c90eaa commit 2144066
Show file tree
Hide file tree
Showing 4 changed files with 7,003 additions and 10,298 deletions.
6 changes: 5 additions & 1 deletion .wp-env.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"core": "WordPress/WordPress",
"plugins": [ "." ]
"plugins": [ "." ],
"config": {
"WP_UPLOAD_MAX_FILESIZE": "128M",
"WP_MEMORY_LIMIT": "256M"
}
}
68 changes: 22 additions & 46 deletions bin/install-wp-tests.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
#!/usr/bin/env bash

# Function to display usage instructions
display_usage() {
echo "Usage: $0 [options] <db-name> <db-user> <db-pass> [db-host] [wp-version] [skip-database-creation]"
echo "Options:"
echo " --recreate-db Recreate the database"
echo " --help Displays this help message"
}

RECREATE_DB=0

# Parse command-line arguments
while [[ $# -gt 0 ]]; do
case "$1" in
--recreate-db)
recreate_db=1
shift
;;
*)
break
;;
esac
for arg in "$@"
do
case $arg in
--recreate-db)
RECREATE_DB=1
shift
;;
--help)
SHOW_HELP=1
shift
;;
esac
done

if [[ "$SHOW_HELP" -eq 1 ]]
then
display_help
exit 0
fi

# Check if required arguments are provided
if [[ $# -lt 3 ]]; then
display_usage
Expand All @@ -37,14 +46,6 @@ TMPDIR=${TMPDIR-/tmp}
TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//")
WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests-lib}
WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR/wordpress}
WP_CLI_CMD=$WP_CORE_DIR/wp-cli.phar

RECREATE_DB=0

# Check for --recreate-db flag
if [[ $recreate_db ]]; then
RECREATE_DB=1
fi

download() {
if [ `which curl` ]; then
Expand Down Expand Up @@ -121,9 +122,7 @@ install_wp() {
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
download https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar $WP_CORE_DIR/wp-cli.phar
chmod +x $WP_CORE_DIR/wp-cli.phar
download https://raw.githubusercontent.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php
}

install_test_suite() {
Expand Down Expand Up @@ -212,29 +211,6 @@ install_db() {
fi
}


# downloads and imports theme unit test data
# from https://github.com/WPTT/theme-test-data/blob/master/themeunittestdata.wordpress.xml
import_theme_data() {
# download theme unit test data if it doesn't exist
if [ ! -f $WP_CORE_DIR/wp-content/themes/themeunittestdata.wordpress.xml ]; then
download https://raw.githubusercontent.com/WPTT/theme-test-data/master/themeunittestdata.wordpress.xml $WP_CORE_DIR/wp-content/themes/themeunittestdata.wordpress.xml
fi
WP_ADMIN_USER=admin
WP_ADMIN_PASSWORD=password
WP_ADMIN_EMAIL='example@make.wordpress.org'
# create wp-config file
if [ ! -f $WP_CORE_DIR/wp-config.php ]; then
$WP_CLI_CMD config create --dbname=$DB_NAME --dbuser=$DB_USER --dbpass=$DB_PASS --dbhost=$DB_HOST --path=$WP_CORE_DIR --skip-check
fi
# install site
$WP_CLI_CMD core install --url=$WP_URL --title=$WP_TITLE --admin_user=$WP_ADMIN_USER --admin_password=$WP_ADMIN_PASS --admin_email=$WP_ADMIN_EMAIL --path=$WP_CORE_DIR
# use wp cli to import the theme unit test data
$WP_CLI_CMD plugin install wordpress-importer --activate --path=$WP_CORE_DIR
$WP_CLI_CMD import $WP_CORE_DIR/wp-content/themes/themeunittestdata.wordpress.xml --authors=create --path=$WP_CORE_DIR
}

install_wp
install_test_suite
install_db
import_theme_data
Loading

0 comments on commit 2144066

Please sign in to comment.