|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +WORKING_DIR=$(pwd) |
| 4 | + |
| 5 | +# Remove old tmp folder |
| 6 | +rm -rf "$WORKING_DIR/tmp" |
| 7 | + |
| 8 | +# Ask for some parameters to install the test env. |
| 9 | +echo "Choose a database Name for tests [elementor-tests]:" |
| 10 | +read -r DB_NAME |
| 11 | +echo "What is your database username [admin]?" |
| 12 | +read -r DB_USER |
| 13 | +echo "What is your database password [admin]?" |
| 14 | +read -r DB_PASS |
| 15 | +echo "What is your database host (specify port if needed) [127.0.0.1:PORT]?" |
| 16 | +read -r DB_HOST |
| 17 | +echo "Choose WordPress version for testing [latest]:" |
| 18 | +read -r WP_VERSION |
| 19 | + |
| 20 | +DB_NAME=${DB_NAME:-"elementor-tests"} |
| 21 | +DB_USER=${DB_USER:-"admin"} |
| 22 | +DB_PASS=${DB_PASS:-"admin"} |
| 23 | +DB_HOST=${DB_HOST:-"127.0.0.1"} |
| 24 | +WP_VERSION=${WP_VERSION:-"latest"} |
| 25 | + |
| 26 | +WP_TESTS_UTILS_DIR=${WP_TESTS_UTILS_DIR-$WORKING_DIR/tmp/wordpress-tests-lib} |
| 27 | +WP_CORE_DIR=${WP_CORE_DIR-$WORKING_DIR/tmp/wordpress/} |
| 28 | +ELEMENTOR_PLUGIN_DIR=${ELEMENTOR_PLUGIN_DIR-$WORKING_DIR/tmp} |
| 29 | +HELLOPLUS_PLUGIN_DIR=${HELLOPLUS_PLUGIN_DIR-$WORKING_DIR/tmp} |
| 30 | +HELLOTHEME_THEME_DIR=${HELLOTHEME_THEME_DIR-$WP_CORE_DIR/wp-content/themes/hello-theme} |
| 31 | + |
| 32 | +# Download util |
| 33 | +download() { |
| 34 | + if [ `which curl` ]; then |
| 35 | + curl --location -s "$1" > "$2"; |
| 36 | + elif [ `which wget` ]; then |
| 37 | + wget -nv -O "$2" "$1" |
| 38 | + fi |
| 39 | +} |
| 40 | + |
| 41 | +## Determine the WP_TEST_TAG. |
| 42 | +if [[ $WP_VERSION =~ [0-9]+\.[0-9]+(\.[0-9]+)? ]]; then |
| 43 | + WP_TESTS_TAG="tags/$WP_VERSION" |
| 44 | +else |
| 45 | + # http serves a single offer, whereas https serves multiple. we only want one |
| 46 | + download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json |
| 47 | + grep '[0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json |
| 48 | + LATEST_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//') |
| 49 | + if [[ -z "$LATEST_VERSION" ]]; then |
| 50 | + echo "Latest WordPress version could not be found" |
| 51 | + exit 1 |
| 52 | + fi |
| 53 | + WP_TESTS_TAG="tags/$LATEST_VERSION" |
| 54 | +fi |
| 55 | + |
| 56 | +set -ex |
| 57 | + |
| 58 | +check_for_svn() { |
| 59 | + if [ ! `which svn` ]; then |
| 60 | + echo 'Please install "svn" and re run this script.' |
| 61 | + echo 'Mac users: `brew install svn`' |
| 62 | + exit 1 |
| 63 | + fi |
| 64 | +} |
| 65 | + |
| 66 | +install_wp() { |
| 67 | + if [ -d "$WP_CORE_DIR" ]; then |
| 68 | + return; |
| 69 | + fi |
| 70 | + |
| 71 | + mkdir -p "$WP_CORE_DIR" |
| 72 | + |
| 73 | + if [ $WP_VERSION == 'latest' ]; then |
| 74 | + local ARCHIVE_NAME='latest' |
| 75 | + else |
| 76 | + local ARCHIVE_NAME="wordpress-$WP_VERSION" |
| 77 | + fi |
| 78 | + |
| 79 | + download https://wordpress.org/${ARCHIVE_NAME}.tar.gz /tmp/wordpress.tar.gz |
| 80 | + tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C "$WP_CORE_DIR" |
| 81 | + |
| 82 | + download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php "$WP_CORE_DIR/wp-content/db.php" |
| 83 | +} |
| 84 | + |
| 85 | +install_test_suite() { |
| 86 | + # portable in-place argument for both GNU sed and Mac OSX sed |
| 87 | + if [[ $(uname -s) == 'Darwin' ]]; then |
| 88 | + local ioption='-i .bak' |
| 89 | + else |
| 90 | + local ioption='-i' |
| 91 | + fi |
| 92 | + |
| 93 | + # set up testing suite if it doesn't yet exist |
| 94 | + if [ ! -d "$WP_TESTS_UTILS_DIR" ]; then |
| 95 | + # set up testing suite |
| 96 | + mkdir -p "$WP_TESTS_UTILS_DIR"/includes |
| 97 | + svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ "$WP_TESTS_UTILS_DIR/includes/" |
| 98 | + fi |
| 99 | + |
| 100 | + cd "$WP_TESTS_UTILS_DIR" |
| 101 | + |
| 102 | + if [ ! -f wp-tests-config.php ]; then |
| 103 | + download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_UTILS_DIR/wp-tests-config.php" |
| 104 | + sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR':" "$WP_TESTS_UTILS_DIR"/wp-tests-config.php |
| 105 | + sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_UTILS_DIR"/wp-tests-config.php |
| 106 | + sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_UTILS_DIR"/wp-tests-config.php |
| 107 | + sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_UTILS_DIR"/wp-tests-config.php |
| 108 | + sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_UTILS_DIR"/wp-tests-config.php |
| 109 | + fi |
| 110 | +} |
| 111 | + |
| 112 | +install_db() { |
| 113 | + # parse DB_HOST for port or socket references |
| 114 | + local PARTS=(${DB_HOST//\:/ }) |
| 115 | + local DB_HOSTNAME=${PARTS[0]}; |
| 116 | + local DB_SOCK_OR_PORT=${PARTS[1]}; |
| 117 | + local EXTRA="" |
| 118 | + |
| 119 | + if ! [ -z $DB_HOSTNAME ] ; then |
| 120 | + if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then |
| 121 | + EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp" |
| 122 | + elif ! [ -z $DB_SOCK_OR_PORT ] ; then |
| 123 | + EXTRA=" --socket=$DB_SOCK_OR_PORT" |
| 124 | + elif ! [ -z $DB_HOSTNAME ] ; then |
| 125 | + EXTRA=" --host=$DB_HOSTNAME --protocol=tcp" |
| 126 | + fi |
| 127 | + fi |
| 128 | + |
| 129 | + # create database |
| 130 | + mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA |
| 131 | +} |
| 132 | + |
| 133 | +install_elementor_plugin() { |
| 134 | + download https://downloads.wordpress.org/plugin/elementor.latest-stable.zip /tmp/elementor.zip |
| 135 | + # Using double-quotes to wrap the unzip path so directory names with spaces will not cause problems |
| 136 | + unzip -q /tmp/elementor.zip -d "$ELEMENTOR_PLUGIN_DIR" |
| 137 | +} |
| 138 | + |
| 139 | +install_helloplus_plugin() { |
| 140 | + download https://downloads.wordpress.org/plugin/hello-plus.latest-stable.zip /tmp/hello-plus.zip |
| 141 | + # Using double-quotes to wrap the unzip path so directory names with spaces will not cause problems |
| 142 | + unzip -q /tmp/hello-plus.zip -d "$HELLOPLUS_PLUGIN_DIR" |
| 143 | +} |
| 144 | + |
| 145 | +symlink_theme() { |
| 146 | + rm -rf "$HELLOTHEME_THEME_DIR" |
| 147 | + |
| 148 | + ln -s "$WORKING_DIR" "$HELLOTHEME_THEME_DIR" |
| 149 | +} |
| 150 | + |
| 151 | +check_for_svn |
| 152 | +install_wp |
| 153 | +install_test_suite |
| 154 | +install_elementor_plugin |
| 155 | +install_helloplus_plugin |
| 156 | +symlink_theme |
| 157 | +install_db |
0 commit comments