From 851e1cf0b2ff32339ceb9ee051dd998326eb665f Mon Sep 17 00:00:00 2001 From: Mostafa Soufi Date: Sun, 15 Sep 2024 14:33:32 +0300 Subject: [PATCH] revert: the comments --- templates/install-wp-tests.sh | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/templates/install-wp-tests.sh b/templates/install-wp-tests.sh index d3a590fb..43265c60 100644 --- a/templates/install-wp-tests.sh +++ b/templates/install-wp-tests.sh @@ -35,6 +35,7 @@ if ! command -v svn &> /dev/null; then exit 1 fi +# Set WP_TESTS_TAG based on WP_VERSION if [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+\-(beta|RC)[0-9]+$ ]]; then WP_BRANCH=${WP_VERSION%\-*} WP_TESTS_TAG="branches/$WP_BRANCH" @@ -42,6 +43,7 @@ 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" @@ -49,6 +51,7 @@ elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then WP_TESTS_TAG="trunk" else + # Download latest version if no specific version is provided download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json LATEST_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//') if [[ -z "$LATEST_VERSION" ]]; then @@ -57,8 +60,10 @@ else fi WP_TESTS_TAG="tags/$LATEST_VERSION" fi + set -ex +# Install WordPress core install_wp() { if [ -d $WP_CORE_DIR ]; then @@ -98,20 +103,25 @@ install_wp() { download https://raw.githubusercontent.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php } +# Install the WordPress test suite 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 rm -rf $WP_TESTS_DIR/{includes,data} svn export --quiet --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes svn export --quiet --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data fi + # Configure wp-tests-config.php 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 WP_CORE_DIR=$(echo $WP_CORE_DIR | sed "s:/\+$::") @@ -124,9 +134,11 @@ install_test_suite() { fi } +# Recreate the database if needed recreate_db() { shopt -s nocasematch - if [[ $1 =~ ^(y|yes)$ ]]; then + if [[ $1 =~ ^(y|yes)$ ]] + then mysqladmin drop $DB_NAME -f --user="$DB_USER" --password="$DB_PASS"$EXTRA create_db echo "Recreated the database ($DB_NAME)." @@ -136,31 +148,37 @@ recreate_db() { shopt -u nocasematch } +# Create the database create_db() { mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA } +# Install the test database install_db() { + if [ ${SKIP_DB_CREATE} = "true" ]; then return 0 fi + # parse DB_HOST for port or socket references local PARTS=(${DB_HOST//\:/ }) local DB_HOSTNAME=${PARTS[0]}; local DB_SOCK_OR_PORT=${PARTS[1]}; local EXTRA="" - if ! [ -z $DB_HOSTNAME ]; then + if ! [ -z $DB_HOSTNAME ] ; then if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp" - elif ! [ -z $DB_SOCK_OR_PORT ]; then + elif ! [ -z $DB_SOCK_OR_PORT ] ; then EXTRA=" --socket=$DB_SOCK_OR_PORT" - elif ! [ -z $DB_HOSTNAME ]; then + elif ! [ -z $DB_HOSTNAME ] ; then EXTRA=" --host=$DB_HOSTNAME --protocol=tcp" fi fi - if [ $(mysql --user="$DB_USER" --password="$DB_PASS"$EXTRA --execute='show databases;' | grep ^$DB_NAME$) ]; then + # create database + if [ $(mysql --user="$DB_USER" --password="$DB_PASS"$EXTRA --execute='show databases;' | grep ^$DB_NAME$) ] + then echo "Reinstalling will delete the existing test database ($DB_NAME)" read -p 'Are you sure you want to proceed? [y/N]: ' DELETE_EXISTING_DB recreate_db $DELETE_EXISTING_DB @@ -169,6 +187,7 @@ install_db() { fi } +# Run the installation functions install_wp install_test_suite install_db