2019-03-13 12:31:37 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
2021-07-05 18:18:52 -04:00
|
|
|
set +u
|
|
|
|
|
|
2023-02-01 14:57:46 -05:00
|
|
|
composer_wordpress_config() {
|
2020-09-01 16:12:01 -04:00
|
|
|
# Set the wordpress install directory and plugin paths in the composer.json
|
|
|
|
|
composer config --unset extra.wordpress-install-dir;
|
|
|
|
|
composer config extra.wordpress-install-dir $WP_CORE_DIR;
|
2019-03-13 12:31:37 -04:00
|
|
|
|
2020-09-01 16:12:01 -04:00
|
|
|
composer config --unset extra.installer-paths;
|
|
|
|
|
composer config --json extra.installer-paths "{
|
|
|
|
|
\"$PLUGINS_DIR/{\$name}/\": [\"type:wordpress-plugin\"],
|
|
|
|
|
\"$MUPLUGINS_DIR/{\$name}/\": [\"type:wordpress-muplugin\"],
|
|
|
|
|
\"$THEMES_DIR/{\$name}/\": [\"type:wordpress-theme\"]
|
|
|
|
|
}"
|
2019-03-13 12:31:37 -04:00
|
|
|
|
2023-02-01 14:57:46 -05:00
|
|
|
# Set WPackagist repository
|
|
|
|
|
composer config repositories.wpackagist composer https://wpackagist.org
|
|
|
|
|
|
|
|
|
|
# Enable plugins
|
|
|
|
|
composer config --no-plugins allow-plugins.composer/installers true
|
|
|
|
|
composer config --no-plugins allow-plugins.johnpbloch/wordpress-core-installer true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
install_wordpress() {
|
|
|
|
|
if [ -f $WP_CORE_DIR/wp-config.php ]; then
|
|
|
|
|
echo "Wordpress already installed."
|
|
|
|
|
return;
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
composer_wordpress_config
|
|
|
|
|
|
2021-07-05 13:51:52 -04:00
|
|
|
# Install Wordpress + integrated plugins for testing/development.
|
2020-09-01 16:12:01 -04:00
|
|
|
composer install
|
2023-04-18 23:48:08 -04:00
|
|
|
composer require --dev --no-interaction -W \
|
2023-01-24 17:21:16 -05:00
|
|
|
johnpbloch/wordpress:* \
|
2021-07-05 13:51:52 -04:00
|
|
|
wp-graphql/wp-graphql-jwt-authentication \
|
|
|
|
|
wpackagist-plugin/woocommerce \
|
2026-03-20 20:21:42 -04:00
|
|
|
wpackagist-plugin/hcaptcha-for-forms-and-more \
|
2021-07-05 13:51:52 -04:00
|
|
|
wpackagist-plugin/woocommerce-gateway-stripe \
|
2023-02-01 14:57:46 -05:00
|
|
|
wpackagist-plugin/wp-graphql \
|
2026-03-30 22:58:32 -04:00
|
|
|
wpackagist-plugin/elementor \
|
2021-07-05 15:31:17 -04:00
|
|
|
wpackagist-theme/twentytwentyone \
|
2023-06-21 13:21:29 -04:00
|
|
|
wp-cli/wp-cli-bundle:*
|
2021-07-05 13:51:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
remove_wordpress() {
|
2022-02-04 15:00:44 -05:00
|
|
|
# Uninstall woocommerce plugins.
|
|
|
|
|
if [ -f $WP_CORE_DIR/wp-config.php ]; then
|
|
|
|
|
wp plugin uninstall woocommerce --deactivate --path=${WP_CORE_DIR}
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Remove WordPress dependencies
|
2021-07-05 13:51:52 -04:00
|
|
|
composer remove --dev wp-graphql/wp-graphql-jwt-authentication \
|
|
|
|
|
wpackagist-plugin/woocommerce-gateway-stripe \
|
|
|
|
|
wpackagist-plugin/wp-graphql \
|
2026-03-30 22:58:32 -04:00
|
|
|
wpackagist-plugin/elementor \
|
2021-07-05 13:51:52 -04:00
|
|
|
wpackagist-theme/twentytwentyone \
|
|
|
|
|
wpackagist-plugin/woocommerce \
|
2026-03-20 20:21:42 -04:00
|
|
|
wpackagist-plugin/hcaptcha-for-forms-and-more \
|
2021-07-05 13:51:52 -04:00
|
|
|
johnpbloch/wordpress \
|
2021-07-05 15:31:17 -04:00
|
|
|
composer/installers \
|
|
|
|
|
wp-cli/wp-cli-bundle
|
2021-07-05 13:51:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
install_local_test_library() {
|
|
|
|
|
# Install testing library dependencies.
|
|
|
|
|
composer install
|
2025-10-11 16:29:36 -04:00
|
|
|
# Pin behat/gherkin to a version compatible with codeception 4.2.2
|
|
|
|
|
# Versions 4.12+ introduced breaking changes that broke codeception's path-based i18n loading
|
2024-05-07 16:50:42 -04:00
|
|
|
composer require --dev -W \
|
2025-10-11 16:29:36 -04:00
|
|
|
"behat/gherkin:^4.8 <4.12" \
|
2024-05-21 00:48:16 -04:00
|
|
|
"lucatume/wp-browser:>3.1 <3.5" \
|
2024-05-07 16:50:42 -04:00
|
|
|
phpunit/phpunit:^9.6 \
|
|
|
|
|
codeception/lib-asserts:* \
|
|
|
|
|
codeception/module-asserts:* \
|
2023-06-13 23:17:02 +03:00
|
|
|
codeception/module-rest:* \
|
2024-05-07 16:50:42 -04:00
|
|
|
codeception/util-universalframework:* \
|
2024-05-21 00:48:16 -04:00
|
|
|
wp-graphql/wp-graphql-testcase:^3.2 \
|
2023-08-22 20:18:47 -04:00
|
|
|
stripe/stripe-php \
|
|
|
|
|
fakerphp/faker
|
2022-08-26 14:53:36 -04:00
|
|
|
|
2021-07-05 13:51:52 -04:00
|
|
|
}
|
|
|
|
|
|
2023-01-24 17:21:16 -05:00
|
|
|
remove_local_composer_instance() {
|
|
|
|
|
if [ -f $PROJECT_ROOT_DIR/vendor/bin/composer ]; then
|
|
|
|
|
rm -f $PROJECT_ROOT_DIR/vendor/bin/composer
|
|
|
|
|
else
|
|
|
|
|
echo "No local composer instance found."
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
remove_project_symlink() {
|
|
|
|
|
if [ -f $WP_CORE_DIR/wp-content/plugins/wp-graphql-woocommerce ]; then
|
|
|
|
|
rm -rf $WP_CORE_DIR/wp-content/plugins/wp-graphql-woocommerce
|
|
|
|
|
echo "Plugin symlink removed."
|
|
|
|
|
else
|
|
|
|
|
echo "Symlink no found."
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-05 13:51:52 -04:00
|
|
|
remove_local_test_library() {
|
|
|
|
|
# Remove testing library dependencies.
|
|
|
|
|
composer remove --dev wp-graphql/wp-graphql-testcase \
|
|
|
|
|
codeception/module-asserts \
|
2023-02-01 14:57:46 -05:00
|
|
|
codeception/lib-asserts \
|
2024-05-07 16:50:42 -04:00
|
|
|
phpunit/phpunit \
|
2021-07-05 13:51:52 -04:00
|
|
|
codeception/module-rest \
|
|
|
|
|
codeception/util-universalframework \
|
|
|
|
|
lucatume/wp-browser \
|
2023-08-22 20:18:47 -04:00
|
|
|
stripe/stripe-php \
|
2025-10-11 16:29:36 -04:00
|
|
|
fakerphp/faker \
|
|
|
|
|
behat/gherkin
|
2019-03-13 12:31:37 -04:00
|
|
|
}
|
|
|
|
|
|
2023-02-01 14:57:46 -05:00
|
|
|
cleanup_composer_file() {
|
|
|
|
|
echo "Removing extra config..."
|
2023-08-02 23:54:46 +03:00
|
|
|
composer config --unset extra.wordpress-install-dir
|
|
|
|
|
composer config --unset extra.installer-paths
|
2023-02-01 14:57:46 -05:00
|
|
|
echo "Removing repositories..."
|
|
|
|
|
composer config --unset repositories
|
|
|
|
|
|
|
|
|
|
composer config --unset config.allow-plugins
|
|
|
|
|
echo "composer.json cleaned!"
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-24 17:21:16 -05:00
|
|
|
cleanup_local_files() {
|
|
|
|
|
if [ -n "$(ls -A $WP_CORE_DIR)" ]; then
|
|
|
|
|
echo "Removing final test files..."
|
|
|
|
|
rm -rf $WP_CORE_DIR/*
|
|
|
|
|
echo "Files removed!!"
|
|
|
|
|
else
|
|
|
|
|
echo "No files to remove!"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "Rebuilding lock file..."
|
2023-08-03 17:02:54 -04:00
|
|
|
rm -rf $PROJECT_ROOT_DIR/vendor
|
2023-08-02 23:54:46 +03:00
|
|
|
|
2024-11-06 11:34:09 -05:00
|
|
|
composer install
|
2023-01-24 17:21:16 -05:00
|
|
|
}
|
|
|
|
|
|
2019-03-13 12:31:37 -04:00
|
|
|
install_db() {
|
|
|
|
|
if [ ${SKIP_DB_CREATE} = "true" ]; then
|
2021-01-08 17:00:48 -05:00
|
|
|
echo "Skipping database creation..."
|
2019-03-13 12:31:37 -04:00
|
|
|
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 [ $(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
|
|
|
|
|
EXTRA=" --socket=$DB_SOCK_OR_PORT"
|
|
|
|
|
elif ! [ -z $DB_HOSTNAME ] ; then
|
|
|
|
|
EXTRA=" --host=$DB_HOSTNAME --protocol=tcp"
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# create database
|
|
|
|
|
RESULT=`mysql -u $DB_USER --password="$DB_PASS" --skip-column-names -e "SHOW DATABASES LIKE '$DB_NAME'"$EXTRA`
|
2019-03-17 23:50:15 -04:00
|
|
|
if [ "$RESULT" != $DB_NAME ]; then
|
|
|
|
|
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
|
|
|
|
|
fi
|
2019-03-13 12:31:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-09-01 16:12:01 -04:00
|
|
|
|
2019-03-13 12:31:37 -04:00
|
|
|
configure_wordpress() {
|
2021-01-08 17:00:48 -05:00
|
|
|
if [ ${SKIP_WP_SETUP} = "true" ]; then
|
|
|
|
|
echo "Skipping WordPress setup..."
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
|
2019-03-13 12:31:37 -04:00
|
|
|
cd $WP_CORE_DIR
|
2021-01-08 17:00:48 -05:00
|
|
|
|
|
|
|
|
echo "Setting up WordPress..."
|
2019-03-17 23:50:15 -04:00
|
|
|
wp config create --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST" --skip-check --force=true
|
2020-09-01 16:12:01 -04:00
|
|
|
wp core install --url=wp.test --title="WooGraphQL Tests" --admin_user=admin --admin_password=password --admin_email=admin@woographql.local
|
2019-03-13 12:31:37 -04:00
|
|
|
wp rewrite structure '/%year%/%monthnum%/%postname%/'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setup_plugin() {
|
2021-01-08 17:00:48 -05:00
|
|
|
if [ ${SKIP_WP_SETUP} = "true" ]; then
|
|
|
|
|
echo "Skipping WooGraphQL installation..."
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
|
2020-09-01 16:12:01 -04:00
|
|
|
# Move to project root directory
|
|
|
|
|
cd $PROJECT_ROOT_DIR
|
|
|
|
|
|
2019-03-13 12:31:37 -04:00
|
|
|
# Add this repo as a plugin to the repo
|
|
|
|
|
if [ ! -d $WP_CORE_DIR/wp-content/plugins/wp-graphql-woocommerce ]; then
|
2021-01-08 17:00:48 -05:00
|
|
|
echo "Installing WooGraphQL..."
|
2020-09-01 16:12:01 -04:00
|
|
|
ln -s $PROJECT_ROOT_DIR $WP_CORE_DIR/wp-content/plugins/wp-graphql-woocommerce
|
2019-03-13 12:31:37 -04:00
|
|
|
fi
|
|
|
|
|
|
2020-09-01 16:12:01 -04:00
|
|
|
# Move to WordPress directory
|
2019-03-13 12:31:37 -04:00
|
|
|
cd $WP_CORE_DIR
|
|
|
|
|
|
2020-09-01 16:12:01 -04:00
|
|
|
# Activate the plugin, it's dependencies should be activated already.
|
2023-12-22 18:06:12 -05:00
|
|
|
wp plugin activate woocommerce wp-graphql
|
2019-03-13 12:31:37 -04:00
|
|
|
wp plugin activate wp-graphql-woocommerce
|
|
|
|
|
|
|
|
|
|
# Flush the permalinks
|
|
|
|
|
wp rewrite flush
|
|
|
|
|
|
|
|
|
|
# Export the db for codeception to use
|
2020-09-01 16:12:01 -04:00
|
|
|
if [ ! -d "$PROJECT_ROOT_DIR/local/db" ]; then
|
|
|
|
|
mkdir ${PROJECT_ROOT_DIR}/local/db
|
|
|
|
|
fi
|
|
|
|
|
if [ -f "$PROJECT_ROOT_DIR/local/db/app_db.sql" ]; then
|
2021-01-08 17:00:48 -05:00
|
|
|
echo "Deleting old DB dump..."
|
|
|
|
|
rm -rf ${PROJECT_ROOT_DIR}/local/db/app_db.sql
|
2020-09-01 16:12:01 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
wp db export ${PROJECT_ROOT_DIR}/local/db/app_db.sql
|
2019-03-13 12:31:37 -04:00
|
|
|
}
|