From 92e2ce2902645cc592f4d6cbe20b9ce476df9d4c Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Sun, 21 Apr 2024 13:58:48 +0530 Subject: [PATCH 01/39] Move PL plugin files to plugins/performance-lab --- {includes => plugins/performance-lab/includes}/admin/load.php | 0 {includes => plugins/performance-lab/includes}/admin/plugins.php | 0 .../performance-lab/includes}/admin/server-timing.php | 0 .../server-timing/class-perflab-server-timing-metric.php | 0 .../includes}/server-timing/class-perflab-server-timing.php | 0 .../performance-lab/includes}/server-timing/defaults.php | 0 .../performance-lab/includes}/server-timing/hooks.php | 0 .../performance-lab/includes}/server-timing/load.php | 0 .../performance-lab/includes}/server-timing/object-cache.copy.php | 0 .../includes}/site-health/audit-autoloaded-options/helper.php | 0 .../includes}/site-health/audit-autoloaded-options/hooks.php | 0 .../includes}/site-health/audit-enqueued-assets/helper.php | 0 .../includes}/site-health/audit-enqueued-assets/hooks.php | 0 .../performance-lab/includes}/site-health/load.php | 0 .../performance-lab/includes}/site-health/webp-support/helper.php | 0 .../performance-lab/includes}/site-health/webp-support/hooks.php | 0 load.php => plugins/performance-lab/load.php | 0 readme.txt => plugins/performance-lab/readme.txt | 0 18 files changed, 0 insertions(+), 0 deletions(-) rename {includes => plugins/performance-lab/includes}/admin/load.php (100%) rename {includes => plugins/performance-lab/includes}/admin/plugins.php (100%) rename {includes => plugins/performance-lab/includes}/admin/server-timing.php (100%) rename {includes => plugins/performance-lab/includes}/server-timing/class-perflab-server-timing-metric.php (100%) rename {includes => plugins/performance-lab/includes}/server-timing/class-perflab-server-timing.php (100%) rename {includes => plugins/performance-lab/includes}/server-timing/defaults.php (100%) rename {includes => plugins/performance-lab/includes}/server-timing/hooks.php (100%) rename {includes => plugins/performance-lab/includes}/server-timing/load.php (100%) rename {includes => plugins/performance-lab/includes}/server-timing/object-cache.copy.php (100%) rename {includes => plugins/performance-lab/includes}/site-health/audit-autoloaded-options/helper.php (100%) rename {includes => plugins/performance-lab/includes}/site-health/audit-autoloaded-options/hooks.php (100%) rename {includes => plugins/performance-lab/includes}/site-health/audit-enqueued-assets/helper.php (100%) rename {includes => plugins/performance-lab/includes}/site-health/audit-enqueued-assets/hooks.php (100%) rename {includes => plugins/performance-lab/includes}/site-health/load.php (100%) rename {includes => plugins/performance-lab/includes}/site-health/webp-support/helper.php (100%) rename {includes => plugins/performance-lab/includes}/site-health/webp-support/hooks.php (100%) rename load.php => plugins/performance-lab/load.php (100%) rename readme.txt => plugins/performance-lab/readme.txt (100%) diff --git a/includes/admin/load.php b/plugins/performance-lab/includes/admin/load.php similarity index 100% rename from includes/admin/load.php rename to plugins/performance-lab/includes/admin/load.php diff --git a/includes/admin/plugins.php b/plugins/performance-lab/includes/admin/plugins.php similarity index 100% rename from includes/admin/plugins.php rename to plugins/performance-lab/includes/admin/plugins.php diff --git a/includes/admin/server-timing.php b/plugins/performance-lab/includes/admin/server-timing.php similarity index 100% rename from includes/admin/server-timing.php rename to plugins/performance-lab/includes/admin/server-timing.php diff --git a/includes/server-timing/class-perflab-server-timing-metric.php b/plugins/performance-lab/includes/server-timing/class-perflab-server-timing-metric.php similarity index 100% rename from includes/server-timing/class-perflab-server-timing-metric.php rename to plugins/performance-lab/includes/server-timing/class-perflab-server-timing-metric.php diff --git a/includes/server-timing/class-perflab-server-timing.php b/plugins/performance-lab/includes/server-timing/class-perflab-server-timing.php similarity index 100% rename from includes/server-timing/class-perflab-server-timing.php rename to plugins/performance-lab/includes/server-timing/class-perflab-server-timing.php diff --git a/includes/server-timing/defaults.php b/plugins/performance-lab/includes/server-timing/defaults.php similarity index 100% rename from includes/server-timing/defaults.php rename to plugins/performance-lab/includes/server-timing/defaults.php diff --git a/includes/server-timing/hooks.php b/plugins/performance-lab/includes/server-timing/hooks.php similarity index 100% rename from includes/server-timing/hooks.php rename to plugins/performance-lab/includes/server-timing/hooks.php diff --git a/includes/server-timing/load.php b/plugins/performance-lab/includes/server-timing/load.php similarity index 100% rename from includes/server-timing/load.php rename to plugins/performance-lab/includes/server-timing/load.php diff --git a/includes/server-timing/object-cache.copy.php b/plugins/performance-lab/includes/server-timing/object-cache.copy.php similarity index 100% rename from includes/server-timing/object-cache.copy.php rename to plugins/performance-lab/includes/server-timing/object-cache.copy.php diff --git a/includes/site-health/audit-autoloaded-options/helper.php b/plugins/performance-lab/includes/site-health/audit-autoloaded-options/helper.php similarity index 100% rename from includes/site-health/audit-autoloaded-options/helper.php rename to plugins/performance-lab/includes/site-health/audit-autoloaded-options/helper.php diff --git a/includes/site-health/audit-autoloaded-options/hooks.php b/plugins/performance-lab/includes/site-health/audit-autoloaded-options/hooks.php similarity index 100% rename from includes/site-health/audit-autoloaded-options/hooks.php rename to plugins/performance-lab/includes/site-health/audit-autoloaded-options/hooks.php diff --git a/includes/site-health/audit-enqueued-assets/helper.php b/plugins/performance-lab/includes/site-health/audit-enqueued-assets/helper.php similarity index 100% rename from includes/site-health/audit-enqueued-assets/helper.php rename to plugins/performance-lab/includes/site-health/audit-enqueued-assets/helper.php diff --git a/includes/site-health/audit-enqueued-assets/hooks.php b/plugins/performance-lab/includes/site-health/audit-enqueued-assets/hooks.php similarity index 100% rename from includes/site-health/audit-enqueued-assets/hooks.php rename to plugins/performance-lab/includes/site-health/audit-enqueued-assets/hooks.php diff --git a/includes/site-health/load.php b/plugins/performance-lab/includes/site-health/load.php similarity index 100% rename from includes/site-health/load.php rename to plugins/performance-lab/includes/site-health/load.php diff --git a/includes/site-health/webp-support/helper.php b/plugins/performance-lab/includes/site-health/webp-support/helper.php similarity index 100% rename from includes/site-health/webp-support/helper.php rename to plugins/performance-lab/includes/site-health/webp-support/helper.php diff --git a/includes/site-health/webp-support/hooks.php b/plugins/performance-lab/includes/site-health/webp-support/hooks.php similarity index 100% rename from includes/site-health/webp-support/hooks.php rename to plugins/performance-lab/includes/site-health/webp-support/hooks.php diff --git a/load.php b/plugins/performance-lab/load.php similarity index 100% rename from load.php rename to plugins/performance-lab/load.php diff --git a/readme.txt b/plugins/performance-lab/readme.txt similarity index 100% rename from readme.txt rename to plugins/performance-lab/readme.txt From 9e06ddd12937667325a08ff1d36600692b9b2553 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Sun, 21 Apr 2024 14:00:40 +0530 Subject: [PATCH 02/39] Add performance-lab to plugins.json --- plugins.json | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins.json b/plugins.json index de34862d23..b4abb9af58 100644 --- a/plugins.json +++ b/plugins.json @@ -4,6 +4,7 @@ "dominant-color-images", "embed-optimizer", "optimization-detective", + "performance-lab", "speculation-rules", "webp-uploads" ] From 38f2e9d80540e1698ce4cc70b9cd06db53e78d0a Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Sun, 21 Apr 2024 14:07:48 +0530 Subject: [PATCH 03/39] Move dotorg assets to PL plugin in plugins directory --- .../.wordpress-org}/banner-1544x500.png | Bin .../.wordpress-org}/banner-772x250.png | Bin .../.wordpress-org}/blueprints/blueprint.json | 0 .../.wordpress-org}/icon-128x128.png | Bin .../.wordpress-org}/icon-256x256.png | Bin .../performance-lab/.wordpress-org}/icon.svg | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename {.wordpress-org => plugins/performance-lab/.wordpress-org}/banner-1544x500.png (100%) rename {.wordpress-org => plugins/performance-lab/.wordpress-org}/banner-772x250.png (100%) rename {.wordpress-org => plugins/performance-lab/.wordpress-org}/blueprints/blueprint.json (100%) rename {.wordpress-org => plugins/performance-lab/.wordpress-org}/icon-128x128.png (100%) rename {.wordpress-org => plugins/performance-lab/.wordpress-org}/icon-256x256.png (100%) rename {.wordpress-org => plugins/performance-lab/.wordpress-org}/icon.svg (100%) diff --git a/.wordpress-org/banner-1544x500.png b/plugins/performance-lab/.wordpress-org/banner-1544x500.png similarity index 100% rename from .wordpress-org/banner-1544x500.png rename to plugins/performance-lab/.wordpress-org/banner-1544x500.png diff --git a/.wordpress-org/banner-772x250.png b/plugins/performance-lab/.wordpress-org/banner-772x250.png similarity index 100% rename from .wordpress-org/banner-772x250.png rename to plugins/performance-lab/.wordpress-org/banner-772x250.png diff --git a/.wordpress-org/blueprints/blueprint.json b/plugins/performance-lab/.wordpress-org/blueprints/blueprint.json similarity index 100% rename from .wordpress-org/blueprints/blueprint.json rename to plugins/performance-lab/.wordpress-org/blueprints/blueprint.json diff --git a/.wordpress-org/icon-128x128.png b/plugins/performance-lab/.wordpress-org/icon-128x128.png similarity index 100% rename from .wordpress-org/icon-128x128.png rename to plugins/performance-lab/.wordpress-org/icon-128x128.png diff --git a/.wordpress-org/icon-256x256.png b/plugins/performance-lab/.wordpress-org/icon-256x256.png similarity index 100% rename from .wordpress-org/icon-256x256.png rename to plugins/performance-lab/.wordpress-org/icon-256x256.png diff --git a/.wordpress-org/icon.svg b/plugins/performance-lab/.wordpress-org/icon.svg similarity index 100% rename from .wordpress-org/icon.svg rename to plugins/performance-lab/.wordpress-org/icon.svg From cd0f1bee649d459e9f771a91ae6291de396cb465 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Sun, 21 Apr 2024 14:08:07 +0530 Subject: [PATCH 04/39] Update build command for PL plugin --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 265a90ae40..0c90d6fa2e 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "versions": "./bin/plugin/cli.js versions", "build": "wp-scripts build", "build-plugins": "npm-run-all 'build:plugin:!(performance-lab)'", - "build:plugin:performance-lab": "rm -rf build/performance-lab && mkdir -p build/performance-lab && git archive HEAD | tar -x -C build/performance-lab", + "build:plugin:performance-lab": "webpack --mode production --env plugin=performance-lab", "build:plugin:auto-sizes": "webpack --mode production --env plugin=auto-sizes", "build:plugin:dominant-color-images": "webpack --mode production --env plugin=dominant-color-images", "build:plugin:embed-optimizer": "webpack --mode production --env plugin=embed-optimizer", From a0336b08d0664d3f6fe0e388ecbe4f668b0b43c7 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Sun, 21 Apr 2024 14:09:05 +0530 Subject: [PATCH 05/39] Move PHPCS config for PL plugins/performance-lab --- phpcs.xml.dist => plugins/performance-lab/phpcs.xml.dist | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename phpcs.xml.dist => plugins/performance-lab/phpcs.xml.dist (100%) diff --git a/phpcs.xml.dist b/plugins/performance-lab/phpcs.xml.dist similarity index 100% rename from phpcs.xml.dist rename to plugins/performance-lab/phpcs.xml.dist From 797f2ff191d31a0b39d55aac320216c9e8a62031 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Sun, 21 Apr 2024 14:14:51 +0530 Subject: [PATCH 06/39] Update wp-env config to include PL plugin from plugins directory --- .wp-env.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.wp-env.json b/.wp-env.json index be6a31146e..759e0a3b01 100644 --- a/.wp-env.json +++ b/.wp-env.json @@ -1,11 +1,11 @@ { "core": null, "plugins": [ - ".", "./plugins/auto-sizes", "./plugins/dominant-color-images", "./plugins/embed-optimizer", "./plugins/optimization-detective", + "./plugins/performance-lab", "./plugins/speculation-rules", "./plugins/webp-uploads" ], From a421c68a4fd074968fa1cbeac1abb98c4cea7ff5 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Sun, 21 Apr 2024 14:17:02 +0530 Subject: [PATCH 07/39] Update PHPCS config --- bin/phpcs/phpcs.ruleset.xml | 4 ++++ plugins/performance-lab/phpcs.xml.dist | 3 --- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/bin/phpcs/phpcs.ruleset.xml b/bin/phpcs/phpcs.ruleset.xml index 02d5053b26..48c8261912 100644 --- a/bin/phpcs/phpcs.ruleset.xml +++ b/bin/phpcs/phpcs.ruleset.xml @@ -131,4 +131,8 @@ ./build/* + + + ./node_modules/* + ./vendor/* diff --git a/plugins/performance-lab/phpcs.xml.dist b/plugins/performance-lab/phpcs.xml.dist index 06664f6bc9..389054a696 100644 --- a/plugins/performance-lab/phpcs.xml.dist +++ b/plugins/performance-lab/phpcs.xml.dist @@ -10,7 +10,4 @@ . - ./node_modules/* - ./plugins/* - ./vendor/* From c719034c7397d4da47961fc179992401c0ea909b Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Sun, 21 Apr 2024 14:50:42 +0530 Subject: [PATCH 08/39] Add placeholder plugin file for performance monorepo --- performance.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 performance.php diff --git a/performance.php b/performance.php new file mode 100644 index 0000000000..8f8e7830f6 --- /dev/null +++ b/performance.php @@ -0,0 +1,36 @@ +

'; + printf( + wp_kses( + /* translators: Link to the Performance Lab plugin on WordPress.org */ + __( 'The Performance Monorepo is not a plugin, and should not be installed as one. Download the Performance Lab plugin to install performance features instead.', 'performance' ), + array( + 'a' => array( 'href' => array() ), + ) + ), + esc_url( 'https://wordpress.org/plugins/performance-lab/' ) + ); + echo "

\n"; +} + +add_action( 'admin_notices', 'perflab_monorepo_is_not_a_plugin' ); From 2533f827d37d901742c04d074f1781e6754f2810 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Sun, 21 Apr 2024 14:51:55 +0530 Subject: [PATCH 09/39] Mount root in wp-env --- .wp-env.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.wp-env.json b/.wp-env.json index 759e0a3b01..3970442724 100644 --- a/.wp-env.json +++ b/.wp-env.json @@ -1,6 +1,7 @@ { "core": null, "plugins": [ + ".", "./plugins/auto-sizes", "./plugins/dominant-color-images", "./plugins/embed-optimizer", From 09569fcf693ac5895d4a2730fc6b7776ce0d1500 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Sun, 21 Apr 2024 14:52:29 +0530 Subject: [PATCH 10/39] Update test scritps --- composer.json | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/composer.json b/composer.json index 4fb2198f61..fdaa5d6888 100644 --- a/composer.json +++ b/composer.json @@ -65,12 +65,12 @@ "format:speculation-rules": "@format -- ./plugins/speculation-rules --standard=./plugins/speculation-rules/phpcs.xml.dist", "format:webp-uploads": "@format -- ./plugins/webp-uploads --standard=./plugins/webp-uploads/phpcs.xml.dist", "lint": "phpcs", - "lint:all": [ - "@lint", + "lint:plugins": [ "@lint:auto-sizes", "@lint:dominant-color-images", "@lint:embed-optimizer", "@lint:optimization-detective", + "@lint:performance-lab", "@lint:speculation-rules", "@lint:webp-uploads" ], @@ -78,46 +78,43 @@ "lint:dominant-color-images": "@lint -- ./plugins/dominant-color-images --standard=./plugins/dominant-color-images/phpcs.xml.dist", "lint:embed-optimizer": "@lint -- ./plugins/embed-optimizer --standard=./plugins/embed-optimizer/phpcs.xml.dist", "lint:optimization-detective": "@lint -- ./plugins/optimization-detective --standard=./plugins/optimization-detective/phpcs.xml.dist", + "lint:performance-lab": "@lint -- ./plugins/performance-lab --standard=./plugins/performance-lab/phpcs.xml.dist", "lint:speculation-rules": "@lint -- ./plugins/speculation-rules --standard=./plugins/speculation-rules/phpcs.xml.dist", "lint:webp-uploads": "@lint -- ./plugins/webp-uploads --standard=./plugins/webp-uploads/phpcs.xml.dist", "phpstan": "phpstan analyse --memory-limit=2048M", - "test": "phpunit --verbose --testsuite performance-lab", - "test-multisite": "phpunit -c tests/multisite.xml --verbose --testsuite performance-lab", - "test-multisite:all": [ - "@test-multisite", - "@test-multisite:plugins" - ], - "test-multisite:auto-sizes": "phpunit -c tests/multisite.xml --verbose --testsuite auto-sizes", - "test-multisite:dominant-color-images": "phpunit -c tests/multisite.xml --verbose --testsuite dominant-color-images", - "test-multisite:embed-optimizer": "phpunit -c tests/multisite.xml --verbose --testsuite embed-optimizer", - "test-multisite:optimization-detective": "phpunit -c tests/multisite.xml --verbose --testsuite optimization-detective", + "test": "phpunit", + "test-multisite": "@test -c tests/multisite.xml", "test-multisite:plugins": [ "@test-multisite:auto-sizes", "@test-multisite:dominant-color-images", "@test-multisite:embed-optimizer", "@test-multisite:optimization-detective", + "@test-multisite:performance-lab", "@test-multisite:speculation-rules", "@test-multisite:webp-uploads" ], - "test-multisite:speculation-rules": "phpunit -c tests/multisite.xml --verbose --testsuite speculation-rules", - "test-multisite:webp-uploads": "phpunit -c tests/multisite.xml --verbose --testsuite webp-uploads", - "test:all": [ - "@test", - "@test:plugins" - ], - "test:auto-sizes": "phpunit --verbose --testsuite auto-sizes", - "test:dominant-color-images": "phpunit --verbose --testsuite dominant-color-images", - "test:embed-optimizer": "phpunit --verbose --testsuite embed-optimizer", - "test:optimization-detective": "phpunit --verbose --testsuite optimization-detective", + "test-multisite:auto-sizes": "@test-multisite --verbose --testsuite auto-sizes", + "test-multisite:dominant-color-images": "@test-multisite --verbose --testsuite dominant-color-images", + "test-multisite:embed-optimizer": "@test-multisite --verbose --testsuite embed-optimizer", + "test-multisite:optimization-detective": "@test-multisite --verbose --testsuite optimization-detective", + "test-multisite:performance-lab": "@test-multisite --verbose --testsuite performance-lab", + "test-multisite:speculation-rules": "@test-multisite --verbose --testsuite speculation-rules", + "test-multisite:webp-uploads": "@test-multisite --verbose --testsuite webp-uploads", "test:plugins": [ "@test:auto-sizes", "@test:dominant-color-images", "@test:embed-optimizer", "@test:optimization-detective", + "@test:performance-lab", "@test:speculation-rules", "@test:webp-uploads" ], - "test:speculation-rules": "phpunit --verbose --testsuite speculation-rules", - "test:webp-uploads": "phpunit --verbose --testsuite webp-uploads" + "test:auto-sizes": "@test --verbose --testsuite auto-sizes", + "test:dominant-color-images": "@test --verbose --testsuite dominant-color-images", + "test:embed-optimizer": "@test --verbose --testsuite embed-optimizer", + "test:optimization-detective": "@test --verbose --testsuite optimization-detective", + "test:performance-lab": "@test --verbose --testsuite performance-lab", + "test:speculation-rules": "@test --verbose --testsuite speculation-rules", + "test:webp-uploads": "@test --verbose --testsuite webp-uploads" } } From 7feeecd3bc07e8540a3b40894ce98da342730a8d Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Sun, 21 Apr 2024 15:13:20 +0530 Subject: [PATCH 11/39] Update tests bootstrap file --- tests/bootstrap.php | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 292ff50ded..baebdca59f 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -40,7 +40,6 @@ if ( '--testsuite' === $arg && isset( $_SERVER['argv'][ $index + 1 ] ) && - 'performance-lab' !== $_SERVER['argv'][ $index + 1 ] && file_exists( TESTS_PLUGIN_DIR . '/plugins/' . $_SERVER['argv'][ $index + 1 ] ) ) { $plugin_name = $_SERVER['argv'][ $index + 1 ]; @@ -65,22 +64,19 @@ static function () use ( $plugin_test_path, $plugin_name ): void { }, 1 ); -} else { - // Force plugin to be active. - $GLOBALS['wp_tests_options'] = array( - 'active_plugins' => array( basename( TESTS_PLUGIN_DIR ) . '/load.php' ), - ); - // Add filter to ensure the plugin's admin integration is loaded for tests. - tests_add_filter( - 'plugins_loaded', - static function (): void { - require_once TESTS_PLUGIN_DIR . '/includes/admin/load.php'; - require_once TESTS_PLUGIN_DIR . '/includes/admin/server-timing.php'; - require_once TESTS_PLUGIN_DIR . '/includes/admin/plugins.php'; - }, - 1 - ); + if ( 'performance-lab' === $plugin_name ) { + // Add filter to ensure the plugin's admin integration is loaded for tests. + tests_add_filter( + 'plugins_loaded', + static function () use ( $plugin_name ) { + require_once TESTS_PLUGIN_DIR . '/plugins/' . $plugin_name . '/includes/admin/load.php'; + require_once TESTS_PLUGIN_DIR . '/plugins/' . $plugin_name . '/includes/admin/server-timing.php'; + require_once TESTS_PLUGIN_DIR . '/plugins/' . $plugin_name . '/includes/admin/plugins.php'; + }, + 1 + ); + } } // Start up the WP testing environment. From ef9f70a819db662193ea3a87189bc11b93a14576 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Sun, 21 Apr 2024 15:21:44 +0530 Subject: [PATCH 12/39] Add PHPCS config for root --- phpcs.xml.dist | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 phpcs.xml.dist diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 0000000000..67e680dba9 --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,12 @@ + + + WordPress Coding Standards for the Performance Features. + + + + + . + + + ./plugins/* + From c4e4de954b338a624fd601a0cd5856a374b6ceef Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Sun, 21 Apr 2024 15:21:55 +0530 Subject: [PATCH 13/39] Add lint:all script --- composer.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/composer.json b/composer.json index fdaa5d6888..46535f1178 100644 --- a/composer.json +++ b/composer.json @@ -65,6 +65,10 @@ "format:speculation-rules": "@format -- ./plugins/speculation-rules --standard=./plugins/speculation-rules/phpcs.xml.dist", "format:webp-uploads": "@format -- ./plugins/webp-uploads --standard=./plugins/webp-uploads/phpcs.xml.dist", "lint": "phpcs", + "lint:all": [ + "@lint", + "@lint:plugins" + ], "lint:plugins": [ "@lint:auto-sizes", "@lint:dominant-color-images", From 5d7ec03e40421fbd90f027998cc58cb3d016658a Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Sun, 21 Apr 2024 15:28:46 +0530 Subject: [PATCH 14/39] Update deploy plugin workflow name --- .../{deploy-standalone-plugins.yml => deploy-plugins.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{deploy-standalone-plugins.yml => deploy-plugins.yml} (100%) diff --git a/.github/workflows/deploy-standalone-plugins.yml b/.github/workflows/deploy-plugins.yml similarity index 100% rename from .github/workflows/deploy-standalone-plugins.yml rename to .github/workflows/deploy-plugins.yml From 750efa1032dc421df3f1943fc0a338c3bfb65023 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Sun, 21 Apr 2024 15:28:59 +0530 Subject: [PATCH 15/39] Remove redundant workflows --- .github/workflows/deploy-dotorg.yml | 28 ----------- .github/workflows/php-test.yml | 74 ----------------------------- 2 files changed, 102 deletions(-) delete mode 100644 .github/workflows/deploy-dotorg.yml delete mode 100644 .github/workflows/php-test.yml diff --git a/.github/workflows/deploy-dotorg.yml b/.github/workflows/deploy-dotorg.yml deleted file mode 100644 index b6533a7afb..0000000000 --- a/.github/workflows/deploy-dotorg.yml +++ /dev/null @@ -1,28 +0,0 @@ ---- -name: Deploy to WordPress.org - -on: - release: - types: - - published - -jobs: - release: - name: Release Performance Lab Plugin - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: WordPress plugin deploy - uses: 10up/action-wordpress-plugin-deploy@stable - env: - SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }} - SVN_USERNAME: ${{ secrets.SVN_USERNAME }} - SLUG: performance-lab - - - name: Upload release assets - uses: softprops/action-gh-release@v1 - if: startsWith(github.ref, 'refs/tags/') - with: - files: ${{github.workspace}}/${{ github.event.repository.name }}.zip diff --git a/.github/workflows/php-test.yml b/.github/workflows/php-test.yml deleted file mode 100644 index c0f290b3af..0000000000 --- a/.github/workflows/php-test.yml +++ /dev/null @@ -1,74 +0,0 @@ -name: Unit Testing - -on: - push: - branches: - - trunk - - 'release/**' - # Only run if PHP-related files changed. - paths: - - '.github/workflows/php-test.yml' - - '**.php' - - '.wp-env.json' - - '**/package.json' - - 'package-lock.json' - - 'phpunit.xml.dist' - - 'tests/multisite.xml' - - 'composer.json' - - 'composer.lock' - pull_request: - # Only run if PHP-related files changed. - paths: - - '.github/workflows/php-test.yml' - - '**.php' - - '.wp-env.json' - - '**/package.json' - - 'package-lock.json' - - 'phpunit.xml.dist' - - 'tests/multisite.xml' - - 'composer.json' - - 'composer.lock' - types: - - opened - - reopened - - synchronize - workflow_dispatch: - -jobs: - php-test: - name: "PHP ${{ matrix.php }} / WP ${{ matrix.wp }}" - runs-on: ubuntu-latest - timeout-minutes: 20 - strategy: - fail-fast: false - matrix: - php: ['8.2', '8.1', '8.0', '7.4', '7.3', '7.2'] - wp: [ 'latest' ] - include: - - php: '7.4' - wp: '6.4' - - php: '8.3' - wp: 'trunk' - env: - WP_ENV_PHP_VERSION: ${{ matrix.php }} - WP_ENV_CORE: ${{ matrix.wp == 'trunk' && 'WordPress/WordPress' || format( 'https://wordpress.org/wordpress-{0}.zip', matrix.wp ) }} - steps: - - uses: styfle/cancel-workflow-action@0.12.1 - - uses: actions/checkout@v4 - - name: Setup Node.js (.nvmrc) - uses: actions/setup-node@v4 - with: - node-version-file: '.nvmrc' - cache: npm - - name: npm install - run: npm ci - - name: Remove standalone plugins from wp-env config - run: jq '.plugins = [.plugins[0]]' .wp-env.json > .wp-env.override.json - - name: Install WordPress - run: npm run wp-env start - - name: Composer Install - run: npm run wp-env run tests-cli -- --env-cwd="wp-content/plugins/$(basename $(pwd))" composer install --no-interaction --no-progress - - name: Running single site unit tests - run: npm run test-php - - name: Running multisite unit tests - run: npm run test-php-multisite From c4ac624e9520a5593287df70057b87b7e14d2a43 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Sun, 21 Apr 2024 15:39:08 +0530 Subject: [PATCH 16/39] Update build-plugins command --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0c90d6fa2e..ae20dd44ea 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "readme": "./bin/plugin/cli.js readme", "versions": "./bin/plugin/cli.js versions", "build": "wp-scripts build", - "build-plugins": "npm-run-all 'build:plugin:!(performance-lab)'", + "build-plugins": "npm-run-all 'build:plugin:*'", "build:plugin:performance-lab": "webpack --mode production --env plugin=performance-lab", "build:plugin:auto-sizes": "webpack --mode production --env plugin=auto-sizes", "build:plugin:dominant-color-images": "webpack --mode production --env plugin=dominant-color-images", From 9125db771fae04cdf621eaf01f487bae7eed9acb Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Thu, 25 Apr 2024 22:19:00 +0530 Subject: [PATCH 17/39] Move avif site health checks to plugins/performance-lab --- .../performance-lab/includes}/site-health/avif-support/helper.php | 0 .../performance-lab/includes}/site-health/avif-support/hooks.php | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename {includes => plugins/performance-lab/includes}/site-health/avif-support/helper.php (100%) rename {includes => plugins/performance-lab/includes}/site-health/avif-support/hooks.php (100%) diff --git a/includes/site-health/avif-support/helper.php b/plugins/performance-lab/includes/site-health/avif-support/helper.php similarity index 100% rename from includes/site-health/avif-support/helper.php rename to plugins/performance-lab/includes/site-health/avif-support/helper.php diff --git a/includes/site-health/avif-support/hooks.php b/plugins/performance-lab/includes/site-health/avif-support/hooks.php similarity index 100% rename from includes/site-health/avif-support/hooks.php rename to plugins/performance-lab/includes/site-health/avif-support/hooks.php From fd67b3893f3df849f241f99c062168310d21afc9 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Thu, 25 Apr 2024 22:20:29 +0530 Subject: [PATCH 18/39] Update PHPStan config --- phpstan.neon.dist | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 9d05005a68..e12458574d 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -4,13 +4,12 @@ parameters: level: 8 treatPhpDocTypesAsCertain: false paths: - - load.php - - includes/ + - performance.php - plugins/ - tests/ bootstrapFiles: - - load.php - bin/phpstan/constants.php + - plugins/performance-lab/load.php - plugins/webp-uploads/load.php scanDirectories: - vendor/wp-phpunit/wp-phpunit/ From bfb1b4b736b1ec99878494c78524e519065ac0ea Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Thu, 25 Apr 2024 22:33:54 +0530 Subject: [PATCH 19/39] Update text domain for plugin root files --- performance.php | 4 ++-- phpcs.xml.dist | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/performance.php b/performance.php index 8f8e7830f6..e6d58c6458 100644 --- a/performance.php +++ b/performance.php @@ -5,7 +5,7 @@ * Description: The Performance Monorepo is not a plugin rather a collection of performance features as plugins. Download Performance Lab plugin to install performance features instead.', 'performance' ), + __( 'The Performance Monorepo is not a plugin, and should not be installed as one. Download the Performance Lab plugin to install performance features instead.', 'performance-lab' ), array( 'a' => array( 'href' => array() ), ) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 67e680dba9..ddfbaee502 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -3,7 +3,7 @@ WordPress Coding Standards for the Performance Features. - + . From ec6fa46925dad328f8cfe86ecb3611aea515347f Mon Sep 17 00:00:00 2001 From: Lovekesh Kumar Date: Thu, 16 May 2024 15:30:22 +0530 Subject: [PATCH 20/39] Update plugin description Co-authored-by: Weston Ruter --- performance.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/performance.php b/performance.php index e6d58c6458..a991ac580a 100644 --- a/performance.php +++ b/performance.php @@ -23,7 +23,7 @@ function perflab_monorepo_is_not_a_plugin() { printf( wp_kses( /* translators: Link to the Performance Lab plugin on WordPress.org */ - __( 'The Performance Monorepo is not a plugin, and should not be installed as one. Download the Performance Lab plugin to install performance features instead.', 'performance-lab' ), + __( 'The Performance Monorepo is not a plugin, and should not be installed as one. Download the Performance Lab plugin to install performance features instead. If you are developing one of the plugins, you can find them in the plugins directory and they should automatically have been added as plugins in wp-env. You may need to restart wp-env for the changes to take effect. If you are not using wp-env, you can add symlinks in your plugins directory to each of the plugins.', 'performance-lab' ), array( 'a' => array( 'href' => array() ), ) From feab2abdd67eacf20a1fee4b59680379d14fc36d Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Thu, 16 May 2024 15:35:14 +0530 Subject: [PATCH 21/39] Move perflab tests to tests/plugins/performance-lab --- tests/{includes => plugins/performance-lab}/admin/load-tests.php | 0 .../performance-lab}/admin/server-timing-tests.php | 0 .../performance-lab}/server-timing/load-tests.php | 0 .../server-timing/perflab-server-timing-metric-tests.php | 0 .../server-timing/perflab-server-timing-tests.php | 0 .../audit-autoloaded-options/audit-autoloaded-options-test.php | 0 .../audit-enqueued-assets/audit-enqueued-assets-helper-test.php | 0 .../audit-enqueued-assets/audit-enqueued-assets-test.php | 0 8 files changed, 0 insertions(+), 0 deletions(-) rename tests/{includes => plugins/performance-lab}/admin/load-tests.php (100%) rename tests/{includes => plugins/performance-lab}/admin/server-timing-tests.php (100%) rename tests/{includes => plugins/performance-lab}/server-timing/load-tests.php (100%) rename tests/{includes => plugins/performance-lab}/server-timing/perflab-server-timing-metric-tests.php (100%) rename tests/{includes => plugins/performance-lab}/server-timing/perflab-server-timing-tests.php (100%) rename tests/{includes => plugins/performance-lab}/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php (100%) rename tests/{includes => plugins/performance-lab}/site-health/audit-enqueued-assets/audit-enqueued-assets-helper-test.php (100%) rename tests/{includes => plugins/performance-lab}/site-health/audit-enqueued-assets/audit-enqueued-assets-test.php (100%) diff --git a/tests/includes/admin/load-tests.php b/tests/plugins/performance-lab/admin/load-tests.php similarity index 100% rename from tests/includes/admin/load-tests.php rename to tests/plugins/performance-lab/admin/load-tests.php diff --git a/tests/includes/admin/server-timing-tests.php b/tests/plugins/performance-lab/admin/server-timing-tests.php similarity index 100% rename from tests/includes/admin/server-timing-tests.php rename to tests/plugins/performance-lab/admin/server-timing-tests.php diff --git a/tests/includes/server-timing/load-tests.php b/tests/plugins/performance-lab/server-timing/load-tests.php similarity index 100% rename from tests/includes/server-timing/load-tests.php rename to tests/plugins/performance-lab/server-timing/load-tests.php diff --git a/tests/includes/server-timing/perflab-server-timing-metric-tests.php b/tests/plugins/performance-lab/server-timing/perflab-server-timing-metric-tests.php similarity index 100% rename from tests/includes/server-timing/perflab-server-timing-metric-tests.php rename to tests/plugins/performance-lab/server-timing/perflab-server-timing-metric-tests.php diff --git a/tests/includes/server-timing/perflab-server-timing-tests.php b/tests/plugins/performance-lab/server-timing/perflab-server-timing-tests.php similarity index 100% rename from tests/includes/server-timing/perflab-server-timing-tests.php rename to tests/plugins/performance-lab/server-timing/perflab-server-timing-tests.php diff --git a/tests/includes/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php b/tests/plugins/performance-lab/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php similarity index 100% rename from tests/includes/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php rename to tests/plugins/performance-lab/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php diff --git a/tests/includes/site-health/audit-enqueued-assets/audit-enqueued-assets-helper-test.php b/tests/plugins/performance-lab/site-health/audit-enqueued-assets/audit-enqueued-assets-helper-test.php similarity index 100% rename from tests/includes/site-health/audit-enqueued-assets/audit-enqueued-assets-helper-test.php rename to tests/plugins/performance-lab/site-health/audit-enqueued-assets/audit-enqueued-assets-helper-test.php diff --git a/tests/includes/site-health/audit-enqueued-assets/audit-enqueued-assets-test.php b/tests/plugins/performance-lab/site-health/audit-enqueued-assets/audit-enqueued-assets-test.php similarity index 100% rename from tests/includes/site-health/audit-enqueued-assets/audit-enqueued-assets-test.php rename to tests/plugins/performance-lab/site-health/audit-enqueued-assets/audit-enqueued-assets-test.php From d3230900ccc9b537a1aea3dad651edb4ce664518 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Thu, 16 May 2024 15:41:12 +0530 Subject: [PATCH 22/39] Update testsuite config for performance-lab plugin --- phpunit.xml.dist | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 7f37f4faaa..42f6df3e2a 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -8,9 +8,7 @@ > - ./tests - ./tests/utils - ./tests/plugins + ./tests/plugins/performance-lab ./tests/plugins/auto-sizes From c8e476ee907dbeeacdd05d305da5451715928be9 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Thu, 16 May 2024 15:41:24 +0530 Subject: [PATCH 23/39] Fix type hints --- performance.php | 2 +- tests/bootstrap.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/performance.php b/performance.php index a991ac580a..ee434097c8 100644 --- a/performance.php +++ b/performance.php @@ -18,7 +18,7 @@ * Notify the admin that the Performance Monorepo is not a plugin, * if they tried to install it as one. */ -function perflab_monorepo_is_not_a_plugin() { +function perflab_monorepo_is_not_a_plugin(): void { echo '

'; printf( wp_kses( diff --git a/tests/bootstrap.php b/tests/bootstrap.php index baebdca59f..3f2ffd1cca 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -69,7 +69,7 @@ static function () use ( $plugin_test_path, $plugin_name ): void { // Add filter to ensure the plugin's admin integration is loaded for tests. tests_add_filter( 'plugins_loaded', - static function () use ( $plugin_name ) { + static function () use ( $plugin_name ): void { require_once TESTS_PLUGIN_DIR . '/plugins/' . $plugin_name . '/includes/admin/load.php'; require_once TESTS_PLUGIN_DIR . '/plugins/' . $plugin_name . '/includes/admin/server-timing.php'; require_once TESTS_PLUGIN_DIR . '/plugins/' . $plugin_name . '/includes/admin/plugins.php'; From affed220b1521f5fca044a4c77e4b877727d4a66 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Thu, 16 May 2024 15:58:54 +0530 Subject: [PATCH 24/39] Move perflab tests to includes dir; Move all site health tests under perflab tests --- tests/plugins/performance-lab/{ => includes}/admin/load-tests.php | 0 .../performance-lab/{ => includes}/admin/server-timing-tests.php | 0 .../performance-lab/{ => includes}/server-timing/load-tests.php | 0 .../server-timing/perflab-server-timing-metric-tests.php | 0 .../{ => includes}/server-timing/perflab-server-timing-tests.php | 0 .../audit-autoloaded-options/audit-autoloaded-options-test.php | 0 .../audit-enqueued-assets/audit-enqueued-assets-helper-test.php | 0 .../audit-enqueued-assets/audit-enqueued-assets-test.php | 0 .../audit-enqueued-assets/class-audit-assets-transients-set.php | 0 .../audit-enqueued-assets/class-site-health-mock-responses.php | 0 10 files changed, 0 insertions(+), 0 deletions(-) rename tests/plugins/performance-lab/{ => includes}/admin/load-tests.php (100%) rename tests/plugins/performance-lab/{ => includes}/admin/server-timing-tests.php (100%) rename tests/plugins/performance-lab/{ => includes}/server-timing/load-tests.php (100%) rename tests/plugins/performance-lab/{ => includes}/server-timing/perflab-server-timing-metric-tests.php (100%) rename tests/plugins/performance-lab/{ => includes}/server-timing/perflab-server-timing-tests.php (100%) rename tests/plugins/performance-lab/{ => includes}/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php (100%) rename tests/plugins/performance-lab/{ => includes}/site-health/audit-enqueued-assets/audit-enqueued-assets-helper-test.php (100%) rename tests/plugins/performance-lab/{ => includes}/site-health/audit-enqueued-assets/audit-enqueued-assets-test.php (100%) rename tests/{testdata/modules => plugins/performance-lab/includes}/site-health/audit-enqueued-assets/class-audit-assets-transients-set.php (100%) rename tests/{testdata/modules => plugins/performance-lab/includes}/site-health/audit-enqueued-assets/class-site-health-mock-responses.php (100%) diff --git a/tests/plugins/performance-lab/admin/load-tests.php b/tests/plugins/performance-lab/includes/admin/load-tests.php similarity index 100% rename from tests/plugins/performance-lab/admin/load-tests.php rename to tests/plugins/performance-lab/includes/admin/load-tests.php diff --git a/tests/plugins/performance-lab/admin/server-timing-tests.php b/tests/plugins/performance-lab/includes/admin/server-timing-tests.php similarity index 100% rename from tests/plugins/performance-lab/admin/server-timing-tests.php rename to tests/plugins/performance-lab/includes/admin/server-timing-tests.php diff --git a/tests/plugins/performance-lab/server-timing/load-tests.php b/tests/plugins/performance-lab/includes/server-timing/load-tests.php similarity index 100% rename from tests/plugins/performance-lab/server-timing/load-tests.php rename to tests/plugins/performance-lab/includes/server-timing/load-tests.php diff --git a/tests/plugins/performance-lab/server-timing/perflab-server-timing-metric-tests.php b/tests/plugins/performance-lab/includes/server-timing/perflab-server-timing-metric-tests.php similarity index 100% rename from tests/plugins/performance-lab/server-timing/perflab-server-timing-metric-tests.php rename to tests/plugins/performance-lab/includes/server-timing/perflab-server-timing-metric-tests.php diff --git a/tests/plugins/performance-lab/server-timing/perflab-server-timing-tests.php b/tests/plugins/performance-lab/includes/server-timing/perflab-server-timing-tests.php similarity index 100% rename from tests/plugins/performance-lab/server-timing/perflab-server-timing-tests.php rename to tests/plugins/performance-lab/includes/server-timing/perflab-server-timing-tests.php diff --git a/tests/plugins/performance-lab/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php b/tests/plugins/performance-lab/includes/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php similarity index 100% rename from tests/plugins/performance-lab/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php rename to tests/plugins/performance-lab/includes/site-health/audit-autoloaded-options/audit-autoloaded-options-test.php diff --git a/tests/plugins/performance-lab/site-health/audit-enqueued-assets/audit-enqueued-assets-helper-test.php b/tests/plugins/performance-lab/includes/site-health/audit-enqueued-assets/audit-enqueued-assets-helper-test.php similarity index 100% rename from tests/plugins/performance-lab/site-health/audit-enqueued-assets/audit-enqueued-assets-helper-test.php rename to tests/plugins/performance-lab/includes/site-health/audit-enqueued-assets/audit-enqueued-assets-helper-test.php diff --git a/tests/plugins/performance-lab/site-health/audit-enqueued-assets/audit-enqueued-assets-test.php b/tests/plugins/performance-lab/includes/site-health/audit-enqueued-assets/audit-enqueued-assets-test.php similarity index 100% rename from tests/plugins/performance-lab/site-health/audit-enqueued-assets/audit-enqueued-assets-test.php rename to tests/plugins/performance-lab/includes/site-health/audit-enqueued-assets/audit-enqueued-assets-test.php diff --git a/tests/testdata/modules/site-health/audit-enqueued-assets/class-audit-assets-transients-set.php b/tests/plugins/performance-lab/includes/site-health/audit-enqueued-assets/class-audit-assets-transients-set.php similarity index 100% rename from tests/testdata/modules/site-health/audit-enqueued-assets/class-audit-assets-transients-set.php rename to tests/plugins/performance-lab/includes/site-health/audit-enqueued-assets/class-audit-assets-transients-set.php diff --git a/tests/testdata/modules/site-health/audit-enqueued-assets/class-site-health-mock-responses.php b/tests/plugins/performance-lab/includes/site-health/audit-enqueued-assets/class-site-health-mock-responses.php similarity index 100% rename from tests/testdata/modules/site-health/audit-enqueued-assets/class-site-health-mock-responses.php rename to tests/plugins/performance-lab/includes/site-health/audit-enqueued-assets/class-site-health-mock-responses.php From fff04dec3421c816bf6a7ce01423bca13ed279fd Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Thu, 16 May 2024 16:01:43 +0530 Subject: [PATCH 25/39] Move test data images from modules to test/data --- .../modules => data}/images/balloons.webp | Bin .../modules => data}/images/car.jpeg | Bin .../modules => data}/images/dice.png | Bin .../modules => data}/images/earth.gif | Bin .../modules => data}/images/image.jpeg | Bin .../modules => data}/images/image.jpg | Bin .../modules => data}/images/leaves.jpg | Bin .../modules => data}/images/paint.jpeg | Bin tests/plugins/auto-sizes/auto-sizes-test.php | 2 +- tests/plugins/webp-uploads/helper-tests.php | 34 ++++----- .../plugins/webp-uploads/image-edit-tests.php | 32 ++++---- tests/plugins/webp-uploads/load-tests.php | 70 +++++++++--------- tests/plugins/webp-uploads/rest-api-tests.php | 4 +- .../utils/TestCase/DominantColorTestCase.php | 2 +- 14 files changed, 72 insertions(+), 72 deletions(-) rename tests/{testdata/modules => data}/images/balloons.webp (100%) rename tests/{testdata/modules => data}/images/car.jpeg (100%) rename tests/{testdata/modules => data}/images/dice.png (100%) rename tests/{testdata/modules => data}/images/earth.gif (100%) rename tests/{testdata/modules => data}/images/image.jpeg (100%) rename tests/{testdata/modules => data}/images/image.jpg (100%) rename tests/{testdata/modules => data}/images/leaves.jpg (100%) rename tests/{testdata/modules => data}/images/paint.jpeg (100%) diff --git a/tests/testdata/modules/images/balloons.webp b/tests/data/images/balloons.webp similarity index 100% rename from tests/testdata/modules/images/balloons.webp rename to tests/data/images/balloons.webp diff --git a/tests/testdata/modules/images/car.jpeg b/tests/data/images/car.jpeg similarity index 100% rename from tests/testdata/modules/images/car.jpeg rename to tests/data/images/car.jpeg diff --git a/tests/testdata/modules/images/dice.png b/tests/data/images/dice.png similarity index 100% rename from tests/testdata/modules/images/dice.png rename to tests/data/images/dice.png diff --git a/tests/testdata/modules/images/earth.gif b/tests/data/images/earth.gif similarity index 100% rename from tests/testdata/modules/images/earth.gif rename to tests/data/images/earth.gif diff --git a/tests/testdata/modules/images/image.jpeg b/tests/data/images/image.jpeg similarity index 100% rename from tests/testdata/modules/images/image.jpeg rename to tests/data/images/image.jpeg diff --git a/tests/testdata/modules/images/image.jpg b/tests/data/images/image.jpg similarity index 100% rename from tests/testdata/modules/images/image.jpg rename to tests/data/images/image.jpg diff --git a/tests/testdata/modules/images/leaves.jpg b/tests/data/images/leaves.jpg similarity index 100% rename from tests/testdata/modules/images/leaves.jpg rename to tests/data/images/leaves.jpg diff --git a/tests/testdata/modules/images/paint.jpeg b/tests/data/images/paint.jpeg similarity index 100% rename from tests/testdata/modules/images/paint.jpeg rename to tests/data/images/paint.jpeg diff --git a/tests/plugins/auto-sizes/auto-sizes-test.php b/tests/plugins/auto-sizes/auto-sizes-test.php index f4c7e3b4fa..a80c9a7f94 100644 --- a/tests/plugins/auto-sizes/auto-sizes-test.php +++ b/tests/plugins/auto-sizes/auto-sizes-test.php @@ -19,7 +19,7 @@ class AutoSizesTests extends WP_UnitTestCase { * Setup shared fixtures. */ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ): void { - self::$image_id = $factory->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' ); + self::$image_id = $factory->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg' ); } /** diff --git a/tests/plugins/webp-uploads/helper-tests.php b/tests/plugins/webp-uploads/helper-tests.php index cea0af9ed8..b1b5a1b837 100644 --- a/tests/plugins/webp-uploads/helper-tests.php +++ b/tests/plugins/webp-uploads/helper-tests.php @@ -35,7 +35,7 @@ public function data_provider_invalid_arguments_for_webp_uploads_generate_additi add_filter( 'wp_image_editors', '__return_empty_array' ); yield 'when no editor is present' => array( - self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' ), + self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/car.jpeg' ), 'medium', array(), 'image/avif', @@ -43,21 +43,21 @@ public function data_provider_invalid_arguments_for_webp_uploads_generate_additi remove_filter( 'wp_image_editors', '__return_empty_array' ); yield 'when using a mime that is not supported' => array( - self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' ), + self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/car.jpeg' ), 'medium', array(), 'image/avif', ); yield 'when no dimension is provided' => array( - self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' ), + self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/car.jpeg' ), 'medium', array(), 'image/webp', ); yield 'when both dimensions are negative numbers' => array( - self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' ), + self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/car.jpeg' ), 'medium', array( 'width' => -10, @@ -67,7 +67,7 @@ public function data_provider_invalid_arguments_for_webp_uploads_generate_additi ); yield 'when both dimensions are zero' => array( - self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' ), + self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/car.jpeg' ), 'medium', array( 'width' => 0, @@ -90,7 +90,7 @@ public function it_should_create_an_image_with_the_default_suffix_in_the_same_lo // Create JPEG and WebP so that both versions are generated. $this->opt_in_to_jpeg_and_webp(); - $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' ); + $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/car.jpeg' ); $size_data = array( 'width' => 300, 'height' => 300, @@ -119,7 +119,7 @@ public function it_should_create_a_file_in_the_specified_location_with_the_speci $this->markTestSkipped( 'Mime type image/webp is not supported.' ); } - $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' ); + $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/car.jpeg' ); $size_data = array( 'width' => 300, 'height' => 300, @@ -144,7 +144,7 @@ public function it_should_create_a_file_in_the_specified_location_with_the_speci */ public function it_should_prevent_processing_an_image_with_corrupted_metadata( callable $callback, string $size ): void { $attachment_id = self::factory()->attachment->create_upload_object( - TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/balloons.webp' + TESTS_PLUGIN_DIR . '/tests/data/images/balloons.webp' ); $metadata = wp_get_attachment_metadata( $attachment_id ); wp_update_attachment_metadata( $attachment_id, $callback( $metadata ) ); @@ -192,7 +192,7 @@ public function it_should_prevent_to_create_an_image_size_when_attached_file_doe } $attachment_id = self::factory()->attachment->create_upload_object( - TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' + TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg' ); $file = get_attached_file( $attachment_id ); $original_file = wp_get_original_image_path( $attachment_id ); @@ -216,7 +216,7 @@ public function it_should_prevent_to_create_an_image_size_when_attached_file_doe */ public function it_should_prevent_to_create_a_subsize_if_the_image_editor_does_not_exists(): void { $attachment_id = self::factory()->attachment->create_upload_object( - TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' + TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg' ); // Make sure no editor is available. @@ -233,7 +233,7 @@ public function it_should_prevent_to_create_a_subsize_if_the_image_editor_does_n */ public function it_should_prevent_to_upload_a_mime_that_is_not_supported_by_wordpress(): void { $attachment_id = self::factory()->attachment->create_upload_object( - TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' + TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg' ); $result = webp_uploads_generate_image_size( $attachment_id, 'medium', 'image/vnd.zbrush.pcx' ); $this->assertWPError( $result ); @@ -248,7 +248,7 @@ public function it_should_prevent_to_upload_a_mime_that_is_not_supported_by_word public function it_should_prevent_to_process_an_image_when_the_editor_does_not_support_the_format(): void { // Make sure no editor is available. $attachment_id = self::factory()->attachment->create_upload_object( - TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' + TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg' ); add_filter( @@ -271,7 +271,7 @@ static function () { public function it_should_create_an_image_with_filter_webp_uploads_pre_generate_additional_image_source(): void { remove_all_filters( 'webp_uploads_pre_generate_additional_image_source' ); - $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' ); + $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/car.jpeg' ); add_filter( 'webp_uploads_pre_generate_additional_image_source', @@ -305,7 +305,7 @@ static function () { public function it_should_use_filesize_when_filter_webp_uploads_pre_generate_additional_image_source_returns_filesize(): void { remove_all_filters( 'webp_uploads_pre_generate_additional_image_source' ); - $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' ); + $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/car.jpeg' ); add_filter( 'webp_uploads_pre_generate_additional_image_source', @@ -340,7 +340,7 @@ static function () { public function it_should_return_an_error_when_filter_webp_uploads_pre_generate_additional_image_source_returns_wp_error(): void { remove_all_filters( 'webp_uploads_pre_generate_additional_image_source' ); - $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' ); + $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/car.jpeg' ); add_filter( 'webp_uploads_pre_generate_additional_image_source', @@ -588,8 +588,8 @@ public function it_should_add_original_image_extension_to_the_webp_file_name_to_ public function data_provider_same_image_name(): array { return array( array( - TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/image.jpeg', - TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/image.jpg', + TESTS_PLUGIN_DIR . '/tests/data/images/image.jpeg', + TESTS_PLUGIN_DIR . '/tests/data/images/image.jpg', ), ); } diff --git a/tests/plugins/webp-uploads/image-edit-tests.php b/tests/plugins/webp-uploads/image-edit-tests.php index 763806bda9..818a129424 100644 --- a/tests/plugins/webp-uploads/image-edit-tests.php +++ b/tests/plugins/webp-uploads/image-edit-tests.php @@ -22,7 +22,7 @@ public function set_up(): void { * @test */ public function it_should_backup_the_sources_structure_alongside_the_full_size(): void { - $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' ); + $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg' ); $metadata = wp_get_attachment_metadata( $attachment_id ); $this->assertEmpty( get_post_meta( $attachment_id, '_wp_attachment_backup_sizes', true ) ); @@ -72,7 +72,7 @@ public function it_should_restore_the_sources_array_from_the_backup_when_an_imag $this->markTestSkipped( 'Mime type image/webp is not supported.' ); } - $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' ); + $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg' ); $metadata = wp_get_attachment_metadata( $attachment_id ); $editor = new WP_Image_Edit( $attachment_id ); @@ -126,7 +126,7 @@ public function it_should_prevent_to_back_up_the_sources_when_the_sources_attrib // Disable the generation of the sources attributes. add_filter( 'webp_uploads_upload_image_mime_transforms', '__return_empty_array' ); - $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' ); + $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg' ); $metadata = wp_get_attachment_metadata( $attachment_id ); $this->assertArrayNotHasKey( 'sources', $metadata ); @@ -159,7 +159,7 @@ public function it_should_prevent_to_backup_the_full_size_image_if_only_the_thum // Create JPEG and WebP. $this->opt_in_to_jpeg_and_webp(); - $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' ); + $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg' ); $metadata = wp_get_attachment_metadata( $attachment_id ); $this->assertArrayHasKey( 'sources', $metadata ); @@ -211,7 +211,7 @@ public function it_should_backup_the_image_when_all_images_except_the_thumbnail_ $this->markTestSkipped( 'Editing image thumbnails separately is disabled' ); } - $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' ); + $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg' ); $metadata = wp_get_attachment_metadata( $attachment_id ); $editor = new WP_Image_Edit( $attachment_id ); @@ -266,7 +266,7 @@ static function () { ); $attachment_id = self::factory()->attachment->create_upload_object( - TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' + TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg' ); $this->assertNotSame( wp_get_original_image_path( $attachment_id ), get_attached_file( $attachment_id ) ); @@ -314,7 +314,7 @@ public function it_should_validate_source_attribute_update_when_webp_edited(): v $this->markTestSkipped( 'Editing image thumbnails separately is disabled' ); } - $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' ); + $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg' ); $editor = new WP_Image_Edit( $attachment_id ); $editor->crop( 1000, 200, 0, 0 )->save(); @@ -343,7 +343,7 @@ public function it_should_validate_source_attribute_update_when_webp_edited(): v * @test */ public function it_should_not_return_a_target_if_no_backup_image_exists(): void { - $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' ); + $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg' ); $this->assertNull( webp_uploads_get_next_full_size_key_from_backup( $attachment_id ) ); } @@ -356,7 +356,7 @@ public function it_should_return_the_full_orig_target_key_when_only_one_edit_ima // Remove the filter to prevent the usage of the next target. remove_filter( 'wp_update_attachment_metadata', 'webp_uploads_update_attachment_metadata' ); - $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' ); + $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg' ); $editor = new WP_Image_Edit( $attachment_id ); $editor->rotate_right()->save(); @@ -370,7 +370,7 @@ public function it_should_return_the_full_orig_target_key_when_only_one_edit_ima * @test */ public function it_should_return_null_when_looking_for_a_target_that_is_already_used(): void { - $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' ); + $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg' ); $editor = new WP_Image_Edit( $attachment_id ); $editor->rotate_right()->save(); @@ -387,7 +387,7 @@ public function it_should_use_the_next_available_hash_for_the_full_size_image_on // Create JPEG and WebP. $this->opt_in_to_jpeg_and_webp(); - $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' ); + $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg' ); $editor = new WP_Image_Edit( $attachment_id ); $editor->rotate_right()->save(); @@ -413,7 +413,7 @@ public function it_should_save_populate_the_backup_sources_with_the_next_target( // Remove the filter to prevent the usage of the next target. remove_filter( 'wp_update_attachment_metadata', 'webp_uploads_update_attachment_metadata' ); - $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' ); + $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg' ); $editor = new WP_Image_Edit( $attachment_id ); $editor->rotate_right()->save(); $this->assertTrue( $editor->success() ); @@ -438,7 +438,7 @@ public function it_should_store_the_metadata_on_the_next_available_hash(): void // Create JPEG and WebP. $this->opt_in_to_jpeg_and_webp(); - $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' ); + $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg' ); $editor = new WP_Image_Edit( $attachment_id ); $editor->rotate_right()->save(); @@ -475,7 +475,7 @@ public function it_should_prevent_to_store_an_empty_set_of_sources(): void { // Remove the filter to prevent the usage of the next target. remove_filter( 'wp_update_attachment_metadata', 'webp_uploads_update_attachment_metadata' ); - $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' ); + $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg' ); $editor = new WP_Image_Edit( $attachment_id ); $editor->rotate_right()->save(); @@ -495,7 +495,7 @@ public function it_should_store_the_next_image_hash_on_the_backup_sources(): voi $this->markTestSkipped( 'Mime type image/webp is not supported.' ); } - $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' ); + $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg' ); $editor = new WP_Image_Edit( $attachment_id ); // Edit the image. $editor->rotate_right()->save(); @@ -522,7 +522,7 @@ public function it_should_create_backup_of_full_size_images_with_the_same_hash_k // Create JPEG and WebP. $this->opt_in_to_jpeg_and_webp(); - $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' ); + $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg' ); $editor = new WP_Image_Edit( $attachment_id ); $editor->rotate_right()->save(); diff --git a/tests/plugins/webp-uploads/load-tests.php b/tests/plugins/webp-uploads/load-tests.php index 9640f6b973..cdca4bf8d6 100644 --- a/tests/plugins/webp-uploads/load-tests.php +++ b/tests/plugins/webp-uploads/load-tests.php @@ -43,7 +43,7 @@ static function ( string $filename ) { * @test */ public function it_should_not_create_the_original_mime_type_for_jpeg_images(): void { - $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' ); + $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg' ); // There should be a WebP source, but no JPEG source for the full image. $this->assertImageHasSource( $attachment_id, 'image/webp' ); @@ -75,7 +75,7 @@ public function it_should_not_create_the_original_mime_type_for_jpeg_images(): v * @test */ public function it_should_create_the_original_mime_type_as_well_with_all_the_available_sources_for_the_specified_mime(): void { - $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/balloons.webp' ); + $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/balloons.webp' ); // There should be a WebP source, but no JPEG source for the full image. $this->assertImageNotHasSource( $attachment_id, 'image/jpeg' ); @@ -106,7 +106,7 @@ public function it_should_create_the_original_mime_type_as_well_with_all_the_ava public function it_should_create_jpeg_and_webp_for_jpeg_images_if_opted_in(): void { $this->opt_in_to_jpeg_and_webp(); - $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' ); + $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg' ); // There should be JPEG and WebP sources for the full image. $this->assertImageHasSource( $attachment_id, 'image/jpeg' ); @@ -137,7 +137,7 @@ public function it_should_create_jpeg_and_webp_for_jpeg_images_if_opted_in(): vo public function it_should_create_jpeg_and_webp_for_jpeg_images_if_generate_webp_and_jpeg_set(): void { update_option( 'perflab_generate_webp_and_jpeg', true ); - $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' ); + $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg' ); // There should be JPEG and WebP sources for the full image. $this->assertImageHasSource( $attachment_id, 'image/jpeg' ); @@ -169,7 +169,7 @@ public function it_should_not_create_the_sources_property_if_no_transform_is_pro add_filter( 'webp_uploads_upload_image_mime_transforms', '__return_empty_array' ); $attachment_id = self::factory()->attachment->create_upload_object( - TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' + TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg' ); $metadata = wp_get_attachment_metadata( $attachment_id ); @@ -195,7 +195,7 @@ static function () { ); $attachment_id = self::factory()->attachment->create_upload_object( - TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' + TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg' ); $this->assertImageHasSource( $attachment_id, 'image/jpeg' ); @@ -222,7 +222,7 @@ static function () { ); $attachment_id = self::factory()->attachment->create_upload_object( - TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/balloons.webp' + TESTS_PLUGIN_DIR . '/tests/data/images/balloons.webp' ); $metadata = wp_get_attachment_metadata( $attachment_id ); @@ -241,7 +241,7 @@ static function () { */ public function it_should_create_a_webp_version_with_all_the_required_properties(): void { $attachment_id = self::factory()->attachment->create_upload_object( - TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' + TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg' ); $metadata = wp_get_attachment_metadata( $attachment_id ); @@ -271,7 +271,7 @@ public function it_should_create_the_full_size_images_when_no_size_is_available( add_filter( 'intermediate_image_sizes', '__return_empty_array' ); add_filter( 'fallback_intermediate_image_sizes', '__return_empty_array' ); - $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' ); + $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg' ); $metadata = wp_get_attachment_metadata( $attachment_id ); $this->assertEmpty( $metadata['sizes'] ); @@ -298,7 +298,7 @@ static function () { ); $attachment_id = self::factory()->attachment->create_upload_object( - TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' + TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg' ); $metadata = wp_get_attachment_metadata( $attachment_id ); $this->assertStringEndsWith( '-scaled.jpg', get_attached_file( $attachment_id ) ); @@ -314,7 +314,7 @@ static function () { */ public function it_should_remove_the_generated_webp_images_when_the_attachment_is_deleted(): void { $attachment_id = self::factory()->attachment->create_upload_object( - TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' + TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg' ); $file = get_attached_file( $attachment_id, true ); @@ -349,7 +349,7 @@ public function it_should_remove_the_generated_webp_images_when_the_attachment_i */ public function it_should_remove_the_attached_webp_version_if_the_attachment_is_force_deleted(): void { $attachment_id = self::factory()->attachment->create_upload_object( - TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' + TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg' ); $file = get_attached_file( $attachment_id, true ); @@ -378,7 +378,7 @@ public function it_should_remove_full_size_images_when_no_size_image_exists(): v add_filter( 'intermediate_image_sizes', '__return_empty_array' ); add_filter( 'fallback_intermediate_image_sizes', '__return_empty_array' ); - $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' ); + $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg' ); $file = get_attached_file( $attachment_id, true ); $dirname = pathinfo( $file, PATHINFO_DIRNAME ); @@ -401,7 +401,7 @@ public function it_should_remove_full_size_images_when_no_size_image_exists(): v */ public function it_should_remove_the_backup_sizes_and_sources_if_the_attachment_is_deleted_after_edit(): void { $attachment_id = self::factory()->attachment->create_upload_object( - TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' + TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg' ); $file = get_attached_file( $attachment_id, true ); @@ -471,7 +471,7 @@ public function it_should_prevent_replacing_a_webp_image(): void { $this->opt_in_to_jpeg_and_webp(); $attachment_id = self::factory()->attachment->create_upload_object( - TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/balloons.webp' + TESTS_PLUGIN_DIR . '/tests/data/images/balloons.webp' ); $tag = wp_get_attachment_image( $attachment_id, 'medium', false, array( 'class' => "wp-image-{$attachment_id}" ) ); @@ -495,7 +495,7 @@ public function it_should_prevent_replacing_a_webp_image(): void { */ public function it_should_prevent_replacing_a_jpg_image_if_the_image_does_not_have_the_target_class_name(): void { $attachment_id = self::factory()->attachment->create_upload_object( - TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' + TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg' ); // Run critical hooks to satisfy webp_uploads_in_frontend_body() conditions. @@ -560,8 +560,8 @@ static function ( $mime_types ) { } public function provider_replace_images_with_different_extensions(): Generator { - yield 'An image with a .jpg extension' => array( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' ); - yield 'An image with a .jpeg extension' => array( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' ); + yield 'An image with a .jpg extension' => array( TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg' ); + yield 'An image with a .jpeg extension' => array( TESTS_PLUGIN_DIR . '/tests/data/images/car.jpeg' ); } /** @@ -574,7 +574,7 @@ public function it_should_replace_all_the_images_including_the_full_size_image() $this->opt_in_to_jpeg_and_webp(); $attachment_id = self::factory()->attachment->create_upload_object( - TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' + TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg' ); $tag = wp_get_attachment_image( $attachment_id, 'full', false, array( 'class' => "wp-image-{$attachment_id}" ) ); @@ -599,7 +599,7 @@ public function it_should_replace_all_the_images_including_the_full_size_image() public function it_should_prevent_replacing_an_image_with_no_available_sources(): void { add_filter( 'webp_uploads_upload_image_mime_transforms', '__return_empty_array' ); - $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' ); + $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/car.jpeg' ); $tag = wp_get_attachment_image( $attachment_id, 'full', false, array( 'class' => "wp-image-{$attachment_id}" ) ); $this->assertSame( $tag, webp_uploads_img_tag_update_mime_type( $tag, 'the_content', $attachment_id ) ); @@ -623,8 +623,8 @@ public function it_should_prevent_update_not_supported_images_with_no_available_ } public function data_provider_not_supported_webp_images(): Generator { - yield 'PNG image' => array( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/dice.png' ); - yield 'GIFT image' => array( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/earth.gif' ); + yield 'PNG image' => array( TESTS_PLUGIN_DIR . '/tests/data/images/dice.png' ); + yield 'GIFT image' => array( TESTS_PLUGIN_DIR . '/tests/data/images/earth.gif' ); } /** @@ -641,7 +641,7 @@ static function () { } ); - $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/paint.jpeg' ); + $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/paint.jpeg' ); $metadata = wp_get_attachment_metadata( $attachment_id ); foreach ( $metadata['sizes'] as $size ) { @@ -669,7 +669,7 @@ public function it_should_preserve_jpeg_subsizes_using_transform_filter(): void // Create JPEG and WebP. $this->opt_in_to_jpeg_and_webp(); - $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' ); + $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/car.jpeg' ); $this->assertImageHasSource( $attachment_id, 'image/webp' ); $this->assertImageHasSource( $attachment_id, 'image/jpeg' ); @@ -698,7 +698,7 @@ static function () { $this->assertTrue( wp_image_editor_supports( array( 'mime_type' => 'image/webp' ) ) ); - $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' ); + $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg' ); $metadata = wp_get_attachment_metadata( $attachment_id ); $this->assertArrayHasKey( 'sources', $metadata ); @@ -717,7 +717,7 @@ static function () { * @test */ public function it_should_replace_the_featured_image_to_webp_when_requesting_the_featured_image(): void { - $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/paint.jpeg' ); + $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/paint.jpeg' ); $post_id = self::factory()->post->create(); set_post_thumbnail( $post_id, $attachment_id ); @@ -742,7 +742,7 @@ static function () { } ); - $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' ); + $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/car.jpeg' ); $tag = wp_get_attachment_image( $attachment_id, 'medium', false, array( 'class' => "wp-image-{$attachment_id}" ) ); $this->assertNotSame( $tag, webp_uploads_img_tag_update_mime_type( $tag, 'the_content', $attachment_id ) ); @@ -760,7 +760,7 @@ public function it_should_create_webp_when_webp_is_smaller_than_jpegs(): void { add_filter( 'webp_uploads_discard_larger_generated_images', '__return_true' ); // Look for an image that contains all of the additional mime type images. - $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' ); + $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/car.jpeg' ); $tag = wp_get_attachment_image( $attachment_id, 'full', false, array( 'class' => "wp-image-{$attachment_id}" ) ); $expected_tag = $tag; $metadata = wp_get_attachment_metadata( $attachment_id ); @@ -800,7 +800,7 @@ public function it_should_create_webp_for_full_size_which_is_smaller_in_webp_for add_filter( 'wp_editor_set_quality', array( $this, 'force_webp_image_quality_86' ), PHP_INT_MAX, 2 ); // Look for an image that contains only full size mime type images. - $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' ); + $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg' ); $tag = wp_get_attachment_image( $attachment_id, 'full', false, array( 'class' => "wp-image-{$attachment_id}" ) ); $metadata = wp_get_attachment_metadata( $attachment_id ); $file = get_attached_file( $attachment_id, true ); @@ -827,7 +827,7 @@ public function it_should_create_webp_for_some_sizes_which_are_smaller_in_webp_f add_filter( 'wp_editor_set_quality', array( $this, 'force_webp_image_quality_86' ), PHP_INT_MAX, 2 ); // Look for an image that contains all of the additional mime type images. - $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/balloons.webp' ); + $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/balloons.webp' ); $tag = wp_get_attachment_image( $attachment_id, 'full', false, array( 'class' => "wp-image-{$attachment_id}" ) ); $expected_tag = $tag; $metadata = wp_get_attachment_metadata( $attachment_id ); @@ -859,7 +859,7 @@ public function it_should_add_fallback_script_if_content_has_updated_images(): v remove_all_actions( 'wp_footer' ); $attachment_id = self::factory()->attachment->create_upload_object( - TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' + TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg' ); // Run critical hooks to satisfy webp_uploads_in_frontend_body() conditions. @@ -912,7 +912,7 @@ static function ( $sizes ) { add_image_size( 'allowed_size_400x300', 400, 300, true ); add_image_size( 'not_allowed_size_200x150', 200, 150, true ); - $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' ); + $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/car.jpeg' ); remove_image_size( 'allowed_size_400x300' ); remove_image_size( 'not_allowed_size_200x150' ); @@ -933,7 +933,7 @@ public function it_should_create_mime_types_for_allowed_sizes_only_via_global_va // TODO: This property should later be set via a new parameter on add_image_size(). $GLOBALS['_wp_additional_image_sizes']['allowed_size_400x300']['provide_additional_mime_types'] = true; - $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' ); + $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/car.jpeg' ); remove_image_size( 'allowed_size_400x300' ); remove_image_size( 'not_allowed_size_200x150' ); @@ -951,7 +951,7 @@ public function it_should_set_quality_with_image_conversion(): void { // Temporary file path. $file = $this->temp_filename(); - $editor = wp_get_image_editor( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/dice.png', array( 'mime_type' => 'image/png' ) ); + $editor = wp_get_image_editor( TESTS_PLUGIN_DIR . '/tests/data/images/dice.png', array( 'mime_type' => 'image/png' ) ); // Quality setting for the source image. For PNG the fallback default of 82 is used. $this->assertSame( 82, $editor->get_quality(), 'Default quality setting for PNG is 82.' ); @@ -960,7 +960,7 @@ public function it_should_set_quality_with_image_conversion(): void { $editor->save( $file, 'image/webp' ); $this->assertSame( 82, $editor->get_quality(), 'Output image format is WebP. Quality setting for it should be 82 universally.' ); - $editor = wp_get_image_editor( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg' ); + $editor = wp_get_image_editor( TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg' ); // Quality setting for the source image. For JPG the fallback default of 82 is used. $this->assertSame( 82, $editor->get_quality(), 'Default quality setting for JPG is 82.' ); diff --git a/tests/plugins/webp-uploads/rest-api-tests.php b/tests/plugins/webp-uploads/rest-api-tests.php index d509619368..5c49035247 100644 --- a/tests/plugins/webp-uploads/rest-api-tests.php +++ b/tests/plugins/webp-uploads/rest-api-tests.php @@ -29,7 +29,7 @@ static function ( $transforms ) { } ); - $file_location = TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg'; + $file_location = TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg'; $attachment_id = self::factory()->attachment->create_upload_object( $file_location ); $metadata = wp_get_attachment_metadata( $attachment_id ); @@ -76,7 +76,7 @@ static function ( $transforms ) { * @test */ public function it_should_check_media_details_in_rest_response(): void { - $file_location = TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg'; + $file_location = TESTS_PLUGIN_DIR . '/tests/data/images/leaves.jpg'; $attachment_id = self::factory()->attachment->create_upload_object( $file_location ); $request = new WP_REST_Request(); diff --git a/tests/utils/TestCase/DominantColorTestCase.php b/tests/utils/TestCase/DominantColorTestCase.php index 592e867fba..36cbedb6f2 100644 --- a/tests/utils/TestCase/DominantColorTestCase.php +++ b/tests/utils/TestCase/DominantColorTestCase.php @@ -96,7 +96,7 @@ public function provider_get_dominant_color(): array { 'expected_transparency' => true, ), 'balloons_webp' => array( - 'image_path' => TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/balloons.webp', + 'image_path' => TESTS_PLUGIN_DIR . '/tests/data/images/balloons.webp', 'expected_color' => array( 'c1bbb9', 'c0bbb9', 'c0bab8', 'c3bdbd', 'bfbab8' ), 'expected_transparency' => false, ), From f9465360b62206342a9b3053e9d4a32ba52cb37f Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Thu, 16 May 2024 16:47:18 +0530 Subject: [PATCH 26/39] Move perflab main plugin file tests to its tests dir --- tests/{ => plugins/performance-lab}/load-tests.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename tests/{ => plugins/performance-lab}/load-tests.php (99%) diff --git a/tests/load-tests.php b/tests/plugins/performance-lab/load-tests.php similarity index 99% rename from tests/load-tests.php rename to tests/plugins/performance-lab/load-tests.php index 5c62d49660..4c497c79d2 100644 --- a/tests/load-tests.php +++ b/tests/plugins/performance-lab/load-tests.php @@ -171,7 +171,7 @@ private function set_up_mock_filesystem(): void { add_filter( 'filesystem_method_file', static function () { - return __DIR__ . '/utils/Filesystem/WP_Filesystem_MockFilesystem.php'; + return __DIR__ . '/../../utils/Filesystem/WP_Filesystem_MockFilesystem.php'; } ); add_filter( From 618446feb4caccefc9e30e1235df83021b9accaf Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Thu, 16 May 2024 16:59:01 +0530 Subject: [PATCH 27/39] Add perflab load.php in paths to get loaded early --- phpstan.neon.dist | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index e12458574d..4b131a4e72 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -4,9 +4,10 @@ parameters: level: 8 treatPhpDocTypesAsCertain: false paths: + - plugins + - tests - performance.php - - plugins/ - - tests/ + - plugins/performance-lab/load.php bootstrapFiles: - bin/phpstan/constants.php - plugins/performance-lab/load.php From af1b6023c9d10341d90357150a409fdfc3e73481 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Thu, 16 May 2024 17:20:54 +0530 Subject: [PATCH 28/39] Set default testsuite --- phpunit.xml.dist | 5 ++-- tests/bootstrap.php | 57 ++++++++++++++++++++++++--------------------- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 42f6df3e2a..3100189bf3 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,10 +1,11 @@ diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 3f2ffd1cca..65ae9358aa 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -46,38 +46,43 @@ } } -if ( $plugin_name ) { - $plugin_test_path = TESTS_PLUGIN_DIR . '/plugins/' . $plugin_name; +// Set default plugin to load if not specified. +if ( ! $plugin_name ) { + $plugin_name = 'performance-lab'; +} + +$plugin_test_path = TESTS_PLUGIN_DIR . '/plugins/' . $plugin_name; + +tests_add_filter( + 'plugins_loaded', + static function () use ( $plugin_test_path, $plugin_name ): void { + // Check if plugin has a "plugin/plugin.php" file. + if ( file_exists( $plugin_test_path . '/' . $plugin_name . '.php' ) ) { + require_once $plugin_test_path . '/' . $plugin_name . '.php'; + } elseif ( file_exists( $plugin_test_path . '/load.php' ) ) { + // Check if plugin has a "plugin/load.php" file. + require_once $plugin_test_path . '/load.php'; + } else { + echo "Unable to locate standalone plugin bootstrap file in $plugin_test_path."; + exit( 1 ); + } + }, + 1 +); + +if ( 'performance-lab' === $plugin_name ) { + // Add filter to ensure the plugin's admin integration is loaded for tests. tests_add_filter( 'plugins_loaded', - static function () use ( $plugin_test_path, $plugin_name ): void { - // Check if plugin has a "plugin/plugin.php" file. - if ( file_exists( $plugin_test_path . '/' . $plugin_name . '.php' ) ) { - require_once $plugin_test_path . '/' . $plugin_name . '.php'; - } elseif ( file_exists( $plugin_test_path . '/load.php' ) ) { - // Check if plugin has a "plugin/load.php" file. - require_once $plugin_test_path . '/load.php'; - } else { - echo "Unable to locate standalone plugin bootstrap file in $plugin_test_path."; - exit( 1 ); - } + static function () use ( $plugin_name ): void { + require_once TESTS_PLUGIN_DIR . '/plugins/' . $plugin_name . '/includes/admin/load.php'; + require_once TESTS_PLUGIN_DIR . '/plugins/' . $plugin_name . '/includes/admin/server-timing.php'; + require_once TESTS_PLUGIN_DIR . '/plugins/' . $plugin_name . '/includes/admin/plugins.php'; }, 1 ); - - if ( 'performance-lab' === $plugin_name ) { - // Add filter to ensure the plugin's admin integration is loaded for tests. - tests_add_filter( - 'plugins_loaded', - static function () use ( $plugin_name ): void { - require_once TESTS_PLUGIN_DIR . '/plugins/' . $plugin_name . '/includes/admin/load.php'; - require_once TESTS_PLUGIN_DIR . '/plugins/' . $plugin_name . '/includes/admin/server-timing.php'; - require_once TESTS_PLUGIN_DIR . '/plugins/' . $plugin_name . '/includes/admin/plugins.php'; - }, - 1 - ); - } } + // Start up the WP testing environment. require $_test_root . '/includes/bootstrap.php'; From 2937407d7c3ada476161980c8ddd8eb2c1b73e5f Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Wed, 22 May 2024 12:54:06 +0530 Subject: [PATCH 29/39] Remove edge case of PL plugin to be refered as the root plugin --- bin/plugin/commands/readme.js | 20 +++++++++----------- bin/plugin/commands/since.js | 11 ++--------- bin/plugin/commands/versions.js | 7 +------ 3 files changed, 12 insertions(+), 26 deletions(-) diff --git a/bin/plugin/commands/readme.js b/bin/plugin/commands/readme.js index b8ca0f354b..177e486d07 100644 --- a/bin/plugin/commands/readme.js +++ b/bin/plugin/commands/readme.js @@ -123,28 +123,25 @@ function getStableTag( readmeFilePath ) { async function updateReadme( settings ) { const pluginRoot = path.resolve( __dirname, '../../../' ); - const allPluginSlugs = [ - 'performance-lab', // TODO: Remove as of . - ...plugins, - ]; - if ( settings.plugin && ! allPluginSlugs.includes( settings.plugin ) ) { + if ( settings.plugin && ! plugins.includes( settings.plugin ) ) { throw new Error( `Unrecognized plugin: ${ settings.plugin }` ); } const pluginSlugs = []; + if ( settings.plugin ) { pluginSlugs.push( settings.plugin ); } else { - pluginSlugs.push( ...allPluginSlugs ); + pluginSlugs.push( ...plugins ); } for ( const pluginSlug of pluginSlugs ) { try { - const pluginDirectory = - 'performance-lab' === pluginSlug // TODO: Remove this condition as of . - ? pluginRoot - : path.resolve( pluginRoot, 'plugins', pluginSlug ); - + const pluginDirectory = path.resolve( + pluginRoot, + 'plugins', + pluginSlug + ); const readmeFilePath = path.resolve( pluginDirectory, 'readme.txt' @@ -157,6 +154,7 @@ async function updateReadme( settings ) { token: settings.token, } ); const status = updateReadmeChangelog( readmeFilePath, changelog ); + log( formats.success( `💃 ${ pluginSlug } successfully updated for version ${ stableTag }: ${ status }` diff --git a/bin/plugin/commands/since.js b/bin/plugin/commands/since.js index b00a87cef1..4a84605393 100644 --- a/bin/plugin/commands/since.js +++ b/bin/plugin/commands/since.js @@ -32,22 +32,15 @@ exports.options = [ exports.handler = async ( opt ) => { const isAllPlugins = ! opt.plugin; - if ( - ! isAllPlugins && - opt.plugin !== 'performance-lab' && // TODO: Remove this as of . - ! plugins.includes( opt.plugin ) - ) { + if ( ! isAllPlugins && ! plugins.includes( opt.plugin ) ) { throw new Error( `The plugin "${ opt.plugin }" is not a valid plugin managed as part of this project.` ); } + const pluginDirectories = []; const pluginRoot = path.resolve( __dirname, '../../../' ); - const pluginDirectories = []; - if ( isAllPlugins || opt.plugin === 'performance-lab' ) { - pluginDirectories.push( pluginRoot ); // TODO: Remove this as of . - } if ( isAllPlugins ) { for ( const pluginSlug of plugins ) { pluginDirectories.push( diff --git a/bin/plugin/commands/versions.js b/bin/plugin/commands/versions.js index 001bb31752..08208d57d7 100644 --- a/bin/plugin/commands/versions.js +++ b/bin/plugin/commands/versions.js @@ -119,13 +119,8 @@ async function checkPluginDirectory( pluginDirectory ) { * @param {WPVersionsCommandOptions} opt Command options. */ exports.handler = async ( opt ) => { - const pluginRoot = path.resolve( __dirname, '../../../' ); - const pluginDirectories = []; - - if ( ! opt.plugin || 'performance-lab' === opt.plugin ) { - pluginDirectories.push( pluginRoot ); // TODO: Remove this after . - } + const pluginRoot = path.resolve( __dirname, '../../../' ); for ( const pluginSlug of plugins ) { if ( ! opt.plugin || pluginSlug === opt.plugin ) { From db957d47717f978c5c0673e6a518b5762d56ef19 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Wed, 22 May 2024 13:21:02 +0530 Subject: [PATCH 30/39] Mount plugin root files in tests --- .wp-env.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.wp-env.json b/.wp-env.json index 3970442724..2cedd753e1 100644 --- a/.wp-env.json +++ b/.wp-env.json @@ -1,7 +1,6 @@ { "core": null, "plugins": [ - ".", "./plugins/auto-sizes", "./plugins/dominant-color-images", "./plugins/embed-optimizer", @@ -14,6 +13,9 @@ "tests": { "config": { "FS_METHOD": "direct" + }, + "mappings": { + "/wp-content/plugins/performance": "." } } } From 23de67ac27966a97dc752e95ccd0c18eef5423db Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Wed, 22 May 2024 13:22:06 +0530 Subject: [PATCH 31/39] Fix cwd in wp-env tests --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index ae20dd44ea..aaf889f578 100644 --- a/package.json +++ b/package.json @@ -43,10 +43,10 @@ "format-php": "composer format", "phpstan": "composer phpstan", "lint-php": "composer lint:all", - "test-php": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/$(basename $(pwd)) composer test", - "test-php-multisite": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/$(basename $(pwd)) composer test-multisite", - "test-php-plugins": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/$(basename $(pwd)) composer test:plugins", - "test-php-multisite-plugins": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/$(basename $(pwd)) composer test-multisite:plugins", + "test-php": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test", + "test-php-multisite": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite", + "test-php-plugins": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test:plugins", + "test-php-multisite-plugins": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite:plugins", "wp-env": "wp-env", "prepare": "husky install" }, From a0f00cc33ac8c92153db86bcc8efe3fe8dc7ed18 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Wed, 22 May 2024 13:31:24 +0530 Subject: [PATCH 32/39] Update ruleset name --- phpcs.xml.dist | 2 +- plugins/performance-lab/phpcs.xml.dist | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index ddfbaee502..b22677cf5a 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -1,5 +1,5 @@ - + WordPress Coding Standards for the Performance Features. diff --git a/plugins/performance-lab/phpcs.xml.dist b/plugins/performance-lab/phpcs.xml.dist index 389054a696..28b28f160b 100644 --- a/plugins/performance-lab/phpcs.xml.dist +++ b/plugins/performance-lab/phpcs.xml.dist @@ -1,5 +1,5 @@ - + WordPress Coding Standards for the Performance Lab Plugin From 0596b062c52c7f4c584e69c7af3ea63981b274d4 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Wed, 22 May 2024 14:28:10 +0530 Subject: [PATCH 33/39] Update lint:all script --- composer.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/composer.json b/composer.json index 46535f1178..032b1c96bc 100644 --- a/composer.json +++ b/composer.json @@ -67,9 +67,6 @@ "lint": "phpcs", "lint:all": [ "@lint", - "@lint:plugins" - ], - "lint:plugins": [ "@lint:auto-sizes", "@lint:dominant-color-images", "@lint:embed-optimizer", From 8cbac0c1f2ae3ed6d8c943192b85b1a1457d7b39 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 22 May 2024 10:46:12 -0700 Subject: [PATCH 34/39] Update monorepo notices --- performance.php | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/performance.php b/performance.php index ee434097c8..c11e86f95f 100644 --- a/performance.php +++ b/performance.php @@ -1,8 +1,8 @@ Performance Lab to install performance features instead. Otherwise, if wanting to contribute, please refer to the handbook page. * Author: WordPress Performance Team * Author URI: https://make.wordpress.org/performance/ * Text Domain: performance-lab @@ -15,22 +15,15 @@ } /** - * Notify the admin that the Performance Monorepo is not a plugin, - * if they tried to install it as one. + * Notify the admin that the Performance monorepo is not a plugin, if they tried to install it as one. */ function perflab_monorepo_is_not_a_plugin(): void { - echo '

'; - printf( - wp_kses( - /* translators: Link to the Performance Lab plugin on WordPress.org */ - __( 'The Performance Monorepo is not a plugin, and should not be installed as one. Download the Performance Lab plugin to install performance features instead. If you are developing one of the plugins, you can find them in the plugins directory and they should automatically have been added as plugins in wp-env. You may need to restart wp-env for the changes to take effect. If you are not using wp-env, you can add symlinks in your plugins directory to each of the plugins.', 'performance-lab' ), - array( - 'a' => array( 'href' => array() ), - ) - ), - esc_url( 'https://wordpress.org/plugins/performance-lab/' ) - ); - echo "

\n"; + // Note: The following notice is not translated because it is never published to WordPress.org and so it will never get translations. + ?> +
+

The Performance monorepo is not a plugin rather a collection of performance features as plugins. Download Performance Lab to install performance features instead. Otherwise, if wanting to contribute, please refer to the handbook page.

+
+ Date: Wed, 22 May 2024 23:20:15 +0530 Subject: [PATCH 35/39] Remove redundant export-ignores --- .gitattributes | 42 ------------------------------------------ 1 file changed, 42 deletions(-) diff --git a/.gitattributes b/.gitattributes index a9f6429d08..f1e57088fa 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,43 +1 @@ *.stub linguist-language=PHP - -/.git export-ignore -/.github export-ignore -/.wordpress-org export-ignore -/.husky export-ignore -/node_modules export-ignore -/vendor export-ignore - -/bin export-ignore -/docs export-ignore -/tests export-ignore -/plugin-tests export-ignore -/plugins export-ignore -/plugins.json export-ignore - -/*.DS_store export-ignore -/.DS_store? export-ignore - -/.editorconfig export-ignore -/.eslintrc.js export-ignore -/.nvmrc export-ignore -/.wp-env.json export-ignore -/composer.json export-ignore -/composer.lock export-ignore -/package.json export-ignore -/package-lock.json export-ignore -phpcs.xml.dist export-ignore -/phpstan.neon.dist export-ignore -/phpunit.xml.dist export-ignore -/webpack.config.js export-ignore - -/CONTRIBUTING.md export-ignore -/SECURITY.md export-ignore -/README.md export-ignore - -/.gitattributes export-ignore -/.gitignore export-ignore - -/modules/**/readme.txt export-ignore -/modules/**/.wordpress-org export-ignore - -/plugins/**/.wordpress-org export-ignore From e3dc1a680f6c4a06b32d02b0e8f1884ab1d4b833 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 22 May 2024 10:53:03 -0700 Subject: [PATCH 36/39] Remove obsolete condition in since command --- bin/plugin/commands/since.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/bin/plugin/commands/since.js b/bin/plugin/commands/since.js index 4a84605393..40ffe8f1ca 100644 --- a/bin/plugin/commands/since.js +++ b/bin/plugin/commands/since.js @@ -70,10 +70,6 @@ exports.handler = async ( opt ) => { } const version = readmeContentMatches[ 1 ]; - if ( pluginDirectory === pluginRoot ) { - ignore.push( '**/plugins' ); // TODO: Remove this as of . - } - patterns.push( `${ pluginDirectory }/**/*.php` ); patterns.push( `${ pluginDirectory }/**/*.js` ); From d9cd4d4d6e47de59e301228399c8fe8e400cf873 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Wed, 22 May 2024 23:28:08 +0530 Subject: [PATCH 37/39] Add github-linguist docs for reference --- .gitattributes | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitattributes b/.gitattributes index f1e57088fa..84e5cd3bed 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,4 @@ +# See . + +# Improve highlighting for PHPStan stub files. *.stub linguist-language=PHP From f0d034d500d00019cd4bcf6f3412a04283e54e61 Mon Sep 17 00:00:00 2001 From: Lovekesh Kumar Date: Thu, 23 May 2024 00:31:06 +0530 Subject: [PATCH 38/39] Update PHP tests commands Co-authored-by: Weston Ruter --- package.json | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index aaf889f578..78b0fdc02d 100644 --- a/package.json +++ b/package.json @@ -43,10 +43,8 @@ "format-php": "composer format", "phpstan": "composer phpstan", "lint-php": "composer lint:all", - "test-php": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test", - "test-php-multisite": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite", - "test-php-plugins": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test:plugins", - "test-php-multisite-plugins": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite:plugins", + "test-php": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test:plugins", + "test-php-multisite": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite:plugins", "wp-env": "wp-env", "prepare": "husky install" }, From 8bc9e7d24376d396e586f562aec83a5b9e23888d Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 22 May 2024 12:03:18 -0700 Subject: [PATCH 39/39] Update test command in php-test-plugins workflow --- .github/workflows/php-test-plugins.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/php-test-plugins.yml b/.github/workflows/php-test-plugins.yml index 4139c048bf..58edcece9d 100644 --- a/.github/workflows/php-test-plugins.yml +++ b/.github/workflows/php-test-plugins.yml @@ -67,7 +67,7 @@ jobs: run: npm run wp-env start - name: Composer Install run: npm run wp-env run tests-cli -- --env-cwd="wp-content/plugins/$(basename $(pwd))" composer install --no-interaction --no-progress - - name: Running single site unit tests for plugins - run: npm run test-php-plugins - - name: Running multisite unit tests for plugins - run: npm run test-php-multisite-plugins + - name: Running single site unit tests + run: npm run test-php + - name: Running multisite unit tests + run: npm run test-php-multisite