From 5ce6f9707c626746408e38106c6472ff486ec4b1 Mon Sep 17 00:00:00 2001 From: Ulrich Pogson Date: Thu, 17 Mar 2022 12:24:58 +0100 Subject: [PATCH] Hide sidebar widgets if widget block is enabled (#54) * Hide sidebar widgets option if widget block is enabled * Update wp-tests * Composer allow plugins * Require yoast/phpunit-polyfills --- bin/install-wp-tests.sh | 49 +++++++++++++++++++++++------ classes/class-wp-widget-disable.php | 32 ++++++++++++++++++- composer.json | 10 ++++-- tests/bootstrap.php | 34 +++++++++++++++++--- 4 files changed, 106 insertions(+), 19 deletions(-) mode change 100644 => 100755 bin/install-wp-tests.sh diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh old mode 100644 new mode 100755 index 364f839..ee05775 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -15,7 +15,7 @@ SKIP_DB_CREATE=${6-false} 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_CORE_DIR=${WP_CORE_DIR-$TMPDIR/wordpress} download() { if [ `which curl` ]; then @@ -25,7 +25,11 @@ download() { fi } -if [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+$ ]]; then +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 @@ -47,7 +51,6 @@ else fi WP_TESTS_TAG="tags/$LATEST_VERSION" fi - set -ex install_wp() { @@ -59,10 +62,10 @@ install_wp() { mkdir -p $WP_CORE_DIR if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then - 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 + mkdir -p $TMPDIR/wordpress-trunk + rm -rf $TMPDIR/wordpress-trunk/* + svn export --quiet https://core.svn.wordpress.org/trunk $TMPDIR/wordpress-trunk/wordpress + mv $TMPDIR/wordpress-trunk/wordpress/* $WP_CORE_DIR else if [ $WP_VERSION == 'latest' ]; then local ARCHIVE_NAME='latest' @@ -104,8 +107,9 @@ install_test_suite() { 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 + 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 if [ ! -f wp-tests-config.php ]; then @@ -113,6 +117,7 @@ install_test_suite() { # 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:__DIR__ . '/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 @@ -121,6 +126,23 @@ install_test_suite() { } +recreate_db() { + shopt -s nocasematch + 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)." + else + echo "Leaving the existing database ($DB_NAME) in place." + fi + shopt -u nocasematch +} + +create_db() { + mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA +} + install_db() { if [ ${SKIP_DB_CREATE} = "true" ]; then @@ -144,7 +166,14 @@ install_db() { fi # create database - mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA + 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 + else + create_db + fi } install_wp diff --git a/classes/class-wp-widget-disable.php b/classes/class-wp-widget-disable.php index e87a78b..79cf969 100644 --- a/classes/class-wp-widget-disable.php +++ b/classes/class-wp-widget-disable.php @@ -632,9 +632,15 @@ public function render_sidebar_checkboxes() { return; } - $options = (array) get_option( $this->sidebar_widgets_option, [] ); + $options = (array) get_option( $this->sidebar_widgets_option, [] ); + $widgets_to_hide = $this->get_widgets_to_hide_from_legacy_widget_block(); + $use_widgets_block_editor = $this->use_widgets_block_editor(); foreach ( $widgets as $id => $widget_object ) { + // Hide widgets if widgets block is enabled. + if ( $use_widgets_block_editor && in_array( $widget_object->id_base, $widgets_to_hide, true ) ) { + continue; + } printf( '

', esc_attr( $id ), @@ -791,4 +797,28 @@ public function render_dashboard_checkboxes() {

=5.6", "wearerequired/wp-requirements-check": "~1.1" }, "require-dev": { "dealerdirect/phpcodesniffer-composer-installer": "^0.7", "phpunit/phpunit": "^5 || ^7", - "wearerequired/coding-standards": "^1.6" + "wearerequired/coding-standards": "^1.6", + "yoast/phpunit-polyfills": "^1.0" }, "scripts": { "format": "vendor/bin/phpcbf --report-summary --report-source .", diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 60d35df..c7b0c76 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,19 +1,43 @@