diff --git a/.editorconfig b/.editorconfig
index 34ef2fd6f4..be1ece849e 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -34,6 +34,7 @@ insert_final_newline = false
quote_type = single
indent_style = space
indent_size = 2
+quote_type = single
[.github/CODEOWNERS]
indent_style = space
diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
index 81d959237d..241f7ef36e 100644
--- a/.github/CODEOWNERS
+++ b/.github/CODEOWNERS
@@ -1,8 +1,10 @@
# Documentation/Infrastructure
-/admin @mukeshpanchal27 @felixarntz
-/tests/admin @mukeshpanchal27 @felixarntz
+/.github @mukeshpanchal27 @felixarntz
/bin @mukeshpanchal27 @felixarntz
-/.github @mukeshpanchal27 @felixarntz @thelovekesh
+
+# Admin: Performance Lab
+/includes/admin @mukeshpanchal27 @felixarntz
+/tests/includes/admin @mukeshpanchal27 @felixarntz
# Site Health: WebP Support Health Check
/includes/site-health/webp-support @adamsilverstein
@@ -14,28 +16,21 @@
# Site Health: Enqueued Assets Health Check
/includes/site-health/audit-enqueued-assets @manuelRod
/tests/includes/site-health/audit-enqueued-assets @manuelRod
-/tests/testdata/modules/site-health/audit-enqueued-assets @manuelRod
# Plugin: Auto-sizes for Lazy-Loaded Images
/plugins/auto-sizes @joemcgill
-/tests/plugins/auto-sizes @joemcgill
-
-# Plugin: Speculative Loading
-/plugins/speculation-rules @felixarntz
-/tests/plugins/speculation-rules @felixarntz
-
-# Plugin: Modern Image Formats
-/plugins/webp-uploads @adamsilverstein @felixarntz
-/tests/plugins/webp-uploads @adamsilverstein @felixarntz
# Plugin: Image Placeholders
/plugins/dominant-color-images @pbearne @spacedmonkey
-/tests/plugins/dominant-color-images @pbearne @spacedmonkey
# Plugin: Embed Optimizer
/plugins/embed-optimizer @adamsilverstein @westonruter
-/tests/plugins/embed-optimizer @adamsilverstein @westonruter
# Plugin: Optimization Detective
/plugins/optimization-detective @westonruter @felixarntz
-/tests/plugins/optimization-detective @westonruter @felixarntz
+
+# Plugin: Speculative Loading
+/plugins/speculation-rules @felixarntz
+
+# Plugin: Modern Image Formats
+/plugins/webp-uploads @adamsilverstein @felixarntz
diff --git a/.github/workflows/php-test-plugins.yml b/.github/workflows/php-test-plugins.yml
index 5e87f00d81..3aee0327d3 100644
--- a/.github/workflows/php-test-plugins.yml
+++ b/.github/workflows/php-test-plugins.yml
@@ -13,7 +13,6 @@ on:
- '**/package.json'
- 'package-lock.json'
- 'phpunit.xml.dist'
- - 'tests/multisite.xml'
- 'composer.json'
- 'composer.lock'
pull_request:
@@ -25,7 +24,6 @@ on:
- '**/package.json'
- 'package-lock.json'
- 'phpunit.xml.dist'
- - 'tests/multisite.xml'
- 'composer.json'
- 'composer.lock'
types:
@@ -52,10 +50,10 @@ jobs:
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
+ - uses: styfle/cancel-workflow-action@0.11.0
+ - uses: actions/checkout@v3
- name: Setup Node.js (.nvmrc)
- uses: actions/setup-node@v4
+ uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: npm
@@ -71,6 +69,6 @@ jobs:
- name: Composer update
run: npm run wp-env run tests-cli -- --env-cwd="wp-content/plugins/$(basename $(pwd))" composer update --no-interaction
- name: Running single site unit tests for plugins
- run: npm run test-php-plugins
+ run: npm run test:php:plugins
- name: Running multisite unit tests for plugins
- run: npm run test-php-multisite-plugins
+ run: npm run test:php:plugins:multisite
diff --git a/.github/workflows/php-test.yml b/.github/workflows/php-test.yml
index 81792a34ac..6d7c03304f 100644
--- a/.github/workflows/php-test.yml
+++ b/.github/workflows/php-test.yml
@@ -13,7 +13,6 @@ on:
- '**/package.json'
- 'package-lock.json'
- 'phpunit.xml.dist'
- - 'tests/multisite.xml'
- 'composer.json'
- 'composer.lock'
pull_request:
@@ -25,7 +24,6 @@ on:
- '**/package.json'
- 'package-lock.json'
- 'phpunit.xml.dist'
- - 'tests/multisite.xml'
- 'composer.json'
- 'composer.lock'
types:
@@ -53,10 +51,10 @@ jobs:
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
+ - uses: styfle/cancel-workflow-action@0.11.0
+ - uses: actions/checkout@v3
- name: Setup Node.js (.nvmrc)
- uses: actions/setup-node@v4
+ uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: npm
@@ -72,6 +70,6 @@ jobs:
- name: Composer update
run: npm run wp-env run tests-cli -- --env-cwd="wp-content/plugins/$(basename $(pwd))" composer update --no-interaction
- name: Running single site unit tests
- run: npm run test-php
+ run: npm run test:php
- name: Running multisite unit tests
- run: npm run test-php-multisite
+ run: npm run test:php:multisite
diff --git a/bin/phpunit/test.js b/bin/phpunit/test.js
new file mode 100755
index 0000000000..9fff03d03a
--- /dev/null
+++ b/bin/phpunit/test.js
@@ -0,0 +1,89 @@
+/**
+ * External dependencies
+ */
+const path = require( 'path' );
+const { spawnSync } = require( 'child_process' );
+
+/**
+ * Internal dependencies
+ */
+const { plugins } = require( '../../plugins.json' );
+const { formats } = require( '../plugin/lib/logger' );
+
+const args = process.argv.slice( 2 );
+const { WPP_PLUGIN, WPP_MULTISITE } = process.env;
+const pluginBasePath = path.resolve( __dirname, '../../' );
+const pluginBaseName = path.basename( pluginBasePath );
+const pluginsDir = path.resolve( pluginBasePath, 'plugins' );
+const phpunitBin = path.resolve( pluginBasePath, 'vendor/bin/phpunit' );
+const wpEnvBin = path.resolve( pluginBasePath, 'node_modules/.bin/wp-env' );
+const wpPluginsDir = `/var/www/html/wp-content/plugins/${ pluginBaseName }`;
+
+const _plugins = []; // Store absolute paths to plugins.
+
+if ( WPP_PLUGIN ) {
+ if (
+ 'performance-lab' !== WPP_PLUGIN &&
+ ! plugins.includes( WPP_PLUGIN )
+ ) {
+ // eslint-disable-next-line no-console
+ console.error(
+ formats.error(
+ `The plugin ${ WPP_PLUGIN } is not a valid plugin managed as part of this project.`
+ )
+ );
+
+ process.exit( 1 );
+ }
+
+ if ( 'performance-lab' === WPP_PLUGIN ) {
+ _plugins.push( pluginBasePath );
+ } else {
+ _plugins.push( path.resolve( pluginsDir, WPP_PLUGIN ) );
+ }
+} else {
+ plugins.forEach( ( plugin ) => {
+ _plugins.push( path.resolve( pluginsDir, plugin ) );
+ } );
+}
+
+const wpEnvRunArgs = {}; // Store plugin name with args provided to wp-env run command.
+
+_plugins.forEach( ( plugin ) => {
+ const command = [
+ 'run',
+ 'tests-cli',
+ `--env-cwd=${ plugin.replace( pluginBasePath, wpPluginsDir ) }`,
+ ];
+
+ if ( WPP_MULTISITE ) {
+ command.push( 'env', 'WP_MULTISITE=1' );
+ }
+
+ command.push( phpunitBin.replace( pluginBasePath, wpPluginsDir ) );
+
+ if ( WPP_MULTISITE ) {
+ command.push( '--exclude-group', 'ms-excluded' );
+ }
+
+ if ( args.length ) {
+ command.push( ...args );
+ }
+
+ wpEnvRunArgs[ path.basename( plugin ) ] = command;
+} );
+
+for ( const [ plugin, command ] of Object.entries( wpEnvRunArgs ) ) {
+ if ( Object.keys( wpEnvRunArgs ).length > 1 ) {
+ // eslint-disable-next-line no-console
+ console.log( formats.info( `\n> Running tests for ${ plugin }` ) );
+ }
+
+ // Execute tests synchronously for the sake of async fs.stat in loop.
+ // fs.stat is used by wp-env to determine if `/snap` is available on user's system.
+ const _process = spawnSync( wpEnvBin, command, { stdio: 'inherit' } );
+
+ if ( _process.signal ) {
+ process.exit( 1 );
+ }
+}
diff --git a/bin/plugin/lib/logger.js b/bin/plugin/lib/logger.js
index faa5574813..1dab943ba5 100644
--- a/bin/plugin/lib/logger.js
+++ b/bin/plugin/lib/logger.js
@@ -7,6 +7,7 @@ const title = chalk.bold;
const error = chalk.bold.red;
const warning = chalk.bold.keyword( 'orange' );
const success = chalk.bold.green;
+const info = chalk.bold.blue;
const log = console.log; // eslint-disable-line no-console
@@ -17,5 +18,6 @@ module.exports = {
error,
warning,
success,
+ info,
},
};
diff --git a/composer.json b/composer.json
index 3f2a4cc1c2..0d5cb2771b 100644
--- a/composer.json
+++ b/composer.json
@@ -25,6 +25,7 @@
"post-install-cmd": "if php -r 'exit( version_compare( phpversion(), \"8.1\", \">=\" ) ? 0 : 1 );'; then composer --working-dir=build-cs install --no-interaction; else echo 'Skipping composer install for build-cs since not on PHP 8.1+. You are running: '; php -v; fi",
"post-update-cmd": "if php -r 'exit( version_compare( phpversion(), \"8.1\", \">=\" ) ? 0 : 1 );'; then composer --working-dir=build-cs update --no-interaction; else echo 'Skipping composer update for build-cs since not on PHP 8.1+. You are running: '; php -v; fi",
"phpstan": "build-cs/vendor/bin/phpstan analyse --memory-limit=2048M",
+ "phpunit": "phpunit --verbose",
"format": "build-cs/vendor/bin/phpcbf --report-summary --report-source",
"lint": "build-cs/vendor/bin/phpcs",
"lint:all": [
@@ -41,45 +42,7 @@
"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: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",
- "test": "phpunit --verbose --testsuite performance-lab",
- "test-multisite": "phpunit -c tests/multisite.xml --verbose --testsuite performance-lab",
- "test:all": [
- "@test",
- "@test:plugins"
- ],
- "test-multisite:all": [
- "@test-multisite",
- "@test-multisite:plugins"
- ],
- "test:plugins": [
- "@test:auto-sizes",
- "@test:dominant-color-images",
- "@test:embed-optimizer",
- "@test:optimization-detective",
- "@test:speculation-rules",
- "@test:webp-uploads"
- ],
- "test-multisite:plugins": [
- "@test-multisite:auto-sizes",
- "@test-multisite:dominant-color-images",
- "@test-multisite:embed-optimizer",
- "@test-multisite:optimization-detective",
- "@test-multisite:speculation-rules",
- "@test-multisite:webp-uploads"
- ],
- "test:auto-sizes": "phpunit --verbose --testsuite auto-sizes",
- "test-multisite:auto-sizes": "phpunit -c tests/multisite.xml --verbose --testsuite auto-sizes",
- "test:dominant-color-images": "phpunit --verbose --testsuite dominant-color-images",
- "test-multisite:dominant-color-images": "phpunit -c tests/multisite.xml --verbose --testsuite dominant-color-images",
- "test:embed-optimizer": "phpunit --verbose --testsuite embed-optimizer",
- "test-multisite:embed-optimizer": "phpunit -c tests/multisite.xml --verbose --testsuite embed-optimizer",
- "test:optimization-detective": "phpunit --verbose --testsuite optimization-detective",
- "test-multisite:optimization-detective": "phpunit -c tests/multisite.xml --verbose --testsuite optimization-detective",
- "test:speculation-rules": "phpunit --verbose --testsuite speculation-rules",
- "test-multisite:speculation-rules": "phpunit -c tests/multisite.xml --verbose --testsuite speculation-rules",
- "test:webp-uploads": "phpunit --verbose --testsuite webp-uploads",
- "test-multisite:webp-uploads": "phpunit -c tests/multisite.xml --verbose --testsuite webp-uploads"
+ "lint:webp-uploads": "@lint -- ./plugins/webp-uploads --standard=./plugins/webp-uploads/phpcs.xml.dist"
},
"config": {
"allow-plugins": {
@@ -87,10 +50,5 @@
"phpstan/extension-installer": true,
"dealerdirect/phpcodesniffer-composer-installer": true
}
- },
- "autoload-dev": {
- "psr-4": {
- "PerformanceLab\\Tests\\": "tests/utils"
- }
}
}
diff --git a/package-lock.json b/package-lock.json
index 290d2a75d9..a07a2cb9d1 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -16,6 +16,7 @@
"chalk": "^4.1.2",
"commander": "^9.4.1",
"copy-webpack-plugin": "^12.0.2",
+ "cross-env": "^7.0.3",
"fast-glob": "^3.3.2",
"fs-extra": "^11.2.0",
"husky": "^8.0.2",
@@ -7385,6 +7386,74 @@
"node": "^14.15.0 || ^16.10.0 || >=18.0.0"
}
},
+ "node_modules/cross-env": {
+ "version": "7.0.3",
+ "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-7.0.3.tgz",
+ "integrity": "sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==",
+ "dev": true,
+ "dependencies": {
+ "cross-spawn": "^7.0.1"
+ },
+ "bin": {
+ "cross-env": "src/bin/cross-env.js",
+ "cross-env-shell": "src/bin/cross-env-shell.js"
+ },
+ "engines": {
+ "node": ">=10.14",
+ "npm": ">=6",
+ "yarn": ">=1"
+ }
+ },
+ "node_modules/cross-env/node_modules/cross-spawn": {
+ "version": "7.0.3",
+ "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
+ "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==",
+ "dev": true,
+ "dependencies": {
+ "path-key": "^3.1.0",
+ "shebang-command": "^2.0.0",
+ "which": "^2.0.1"
+ },
+ "engines": {
+ "node": ">= 8"
+ }
+ },
+ "node_modules/cross-env/node_modules/shebang-command": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz",
+ "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==",
+ "dev": true,
+ "dependencies": {
+ "shebang-regex": "^3.0.0"
+ },
+ "engines": {
+ "node": ">=8"
+ }
+ },
+ "node_modules/cross-env/node_modules/shebang-regex": {
+ "version": "3.0.0",
+ "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz",
+ "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==",
+ "dev": true,
+ "engines": {
+ "node": ">=8"
+ }
+ },
+ "node_modules/cross-env/node_modules/which": {
+ "version": "2.0.2",
+ "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
+ "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==",
+ "dev": true,
+ "dependencies": {
+ "isexe": "^2.0.0"
+ },
+ "bin": {
+ "node-which": "bin/node-which"
+ },
+ "engines": {
+ "node": ">= 8"
+ }
+ },
"node_modules/cross-fetch": {
"version": "3.1.5",
"resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.5.tgz",
diff --git a/package.json b/package.json
index 2bac718e88..2b890bffec 100644
--- a/package.json
+++ b/package.json
@@ -16,6 +16,7 @@
"chalk": "^4.1.2",
"commander": "^9.4.1",
"copy-webpack-plugin": "^12.0.2",
+ "cross-env": "^7.0.3",
"fast-glob": "^3.3.2",
"fs-extra": "^11.2.0",
"husky": "^8.0.2",
@@ -42,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": "cross-env WPP_PLUGIN=performance-lab node bin/phpunit/test.js",
+ "test:php:plugins": "cross-env WPP_PLUGIN=$npm_config_plugin node bin/phpunit/test.js",
+ "test:php:multisite": "cross-env WPP_PLUGIN=performance-lab WPP_MULTISITE=1 node bin/phpunit/test.js",
+ "test:php:plugins:multisite": "cross-env WPP_PLUGIN=$npm_config_plugin WPP_MULTISITE=1 node bin/phpunit/test.js",
"wp-env": "wp-env",
"prepare": "husky install"
},
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 7f37f4faaa..c8634b6481 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -5,35 +5,12 @@
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
+ defaultTestSuite="default"
>
-
+
./tests
./tests/utils
- ./tests/plugins
-
-
- ./tests/plugins/auto-sizes
-
-
- ./tests/plugins/dominant-color-images
-
-
- ./tests/plugins/embed-optimizer
-
-
- ./tests/plugins/optimization-detective
-
-
- ./tests/plugins/speculation-rules
-
-
- ./tests/plugins/webp-uploads
-
-
- ms-required
-
-
diff --git a/plugins/auto-sizes/phpunit.xml.dist b/plugins/auto-sizes/phpunit.xml.dist
new file mode 100644
index 0000000000..ca1f119b86
--- /dev/null
+++ b/plugins/auto-sizes/phpunit.xml.dist
@@ -0,0 +1,15 @@
+
+
+
+ ./tests
+
+
+
diff --git a/tests/plugins/auto-sizes/auto-sizes-test.php b/plugins/auto-sizes/tests/auto-sizes-test.php
similarity index 98%
rename from tests/plugins/auto-sizes/auto-sizes-test.php
rename to plugins/auto-sizes/tests/auto-sizes-test.php
index 7b347c97ac..1d159495d2 100644
--- a/tests/plugins/auto-sizes/auto-sizes-test.php
+++ b/plugins/auto-sizes/tests/auto-sizes-test.php
@@ -19,7 +19,7 @@ class AutoSizesTests extends WP_UnitTestCase {
* Setup shared fixtures.
*/
public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
- 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_ROOT . '/tests/data/images/leaves.jpg' );
}
/**
diff --git a/plugins/auto-sizes/tests/bootstrap.php b/plugins/auto-sizes/tests/bootstrap.php
new file mode 100644
index 0000000000..a956134694
--- /dev/null
+++ b/plugins/auto-sizes/tests/bootstrap.php
@@ -0,0 +1,23 @@
+ array( basename( TESTS_PLUGIN_DIR ) . '/auto-sizes.php' ),
+);
+
+// Start up the WP testing environment.
+require $_tests_dir . '/includes/bootstrap.php';
diff --git a/plugins/dominant-color-images/phpunit.xml.dist b/plugins/dominant-color-images/phpunit.xml.dist
new file mode 100644
index 0000000000..ca1f119b86
--- /dev/null
+++ b/plugins/dominant-color-images/phpunit.xml.dist
@@ -0,0 +1,15 @@
+
+
+
+ ./tests
+
+
+
diff --git a/plugins/dominant-color-images/tests/bootstrap.php b/plugins/dominant-color-images/tests/bootstrap.php
new file mode 100644
index 0000000000..9c5daa1566
--- /dev/null
+++ b/plugins/dominant-color-images/tests/bootstrap.php
@@ -0,0 +1,26 @@
+ array( basename( TESTS_PLUGIN_DIR ) . '/load.php' ),
+);
+
+// Start up the WP testing environment.
+require $_tests_dir . '/includes/bootstrap.php';
+
+// Load tests helpers.
+require_once TESTS_PLUGIN_DIR . '/tests/data/testcase.php';
diff --git a/tests/plugins/dominant-color-images/data/images/animated.gif b/plugins/dominant-color-images/tests/data/images/animated.gif
similarity index 100%
rename from tests/plugins/dominant-color-images/data/images/animated.gif
rename to plugins/dominant-color-images/tests/data/images/animated.gif
diff --git a/tests/plugins/dominant-color-images/data/images/green.gif b/plugins/dominant-color-images/tests/data/images/green.gif
similarity index 100%
rename from tests/plugins/dominant-color-images/data/images/green.gif
rename to plugins/dominant-color-images/tests/data/images/green.gif
diff --git a/tests/plugins/dominant-color-images/data/images/green.jpg b/plugins/dominant-color-images/tests/data/images/green.jpg
similarity index 100%
rename from tests/plugins/dominant-color-images/data/images/green.jpg
rename to plugins/dominant-color-images/tests/data/images/green.jpg
diff --git a/tests/plugins/dominant-color-images/data/images/green.png b/plugins/dominant-color-images/tests/data/images/green.png
similarity index 100%
rename from tests/plugins/dominant-color-images/data/images/green.png
rename to plugins/dominant-color-images/tests/data/images/green.png
diff --git a/tests/plugins/dominant-color-images/data/images/green.webp b/plugins/dominant-color-images/tests/data/images/green.webp
similarity index 100%
rename from tests/plugins/dominant-color-images/data/images/green.webp
rename to plugins/dominant-color-images/tests/data/images/green.webp
diff --git a/tests/plugins/dominant-color-images/data/images/red.gif b/plugins/dominant-color-images/tests/data/images/red.gif
similarity index 100%
rename from tests/plugins/dominant-color-images/data/images/red.gif
rename to plugins/dominant-color-images/tests/data/images/red.gif
diff --git a/tests/plugins/dominant-color-images/data/images/red.jpg b/plugins/dominant-color-images/tests/data/images/red.jpg
similarity index 100%
rename from tests/plugins/dominant-color-images/data/images/red.jpg
rename to plugins/dominant-color-images/tests/data/images/red.jpg
diff --git a/tests/plugins/dominant-color-images/data/images/red.png b/plugins/dominant-color-images/tests/data/images/red.png
similarity index 100%
rename from tests/plugins/dominant-color-images/data/images/red.png
rename to plugins/dominant-color-images/tests/data/images/red.png
diff --git a/tests/plugins/dominant-color-images/data/images/red.webp b/plugins/dominant-color-images/tests/data/images/red.webp
similarity index 100%
rename from tests/plugins/dominant-color-images/data/images/red.webp
rename to plugins/dominant-color-images/tests/data/images/red.webp
diff --git a/tests/plugins/dominant-color-images/data/images/small-video.mp4 b/plugins/dominant-color-images/tests/data/images/small-video.mp4
similarity index 100%
rename from tests/plugins/dominant-color-images/data/images/small-video.mp4
rename to plugins/dominant-color-images/tests/data/images/small-video.mp4
diff --git a/tests/plugins/dominant-color-images/data/images/test-image.bmp b/plugins/dominant-color-images/tests/data/images/test-image.bmp
similarity index 100%
rename from tests/plugins/dominant-color-images/data/images/test-image.bmp
rename to plugins/dominant-color-images/tests/data/images/test-image.bmp
diff --git a/tests/plugins/dominant-color-images/data/images/test-image.tiff b/plugins/dominant-color-images/tests/data/images/test-image.tiff
similarity index 100%
rename from tests/plugins/dominant-color-images/data/images/test-image.tiff
rename to plugins/dominant-color-images/tests/data/images/test-image.tiff
diff --git a/tests/plugins/dominant-color-images/data/images/trans.gif b/plugins/dominant-color-images/tests/data/images/trans.gif
similarity index 100%
rename from tests/plugins/dominant-color-images/data/images/trans.gif
rename to plugins/dominant-color-images/tests/data/images/trans.gif
diff --git a/tests/plugins/dominant-color-images/data/images/trans.png b/plugins/dominant-color-images/tests/data/images/trans.png
similarity index 100%
rename from tests/plugins/dominant-color-images/data/images/trans.png
rename to plugins/dominant-color-images/tests/data/images/trans.png
diff --git a/tests/plugins/dominant-color-images/data/images/trans.webp b/plugins/dominant-color-images/tests/data/images/trans.webp
similarity index 100%
rename from tests/plugins/dominant-color-images/data/images/trans.webp
rename to plugins/dominant-color-images/tests/data/images/trans.webp
diff --git a/tests/plugins/dominant-color-images/data/images/white.gif b/plugins/dominant-color-images/tests/data/images/white.gif
similarity index 100%
rename from tests/plugins/dominant-color-images/data/images/white.gif
rename to plugins/dominant-color-images/tests/data/images/white.gif
diff --git a/tests/plugins/dominant-color-images/data/images/white.jpg b/plugins/dominant-color-images/tests/data/images/white.jpg
similarity index 100%
rename from tests/plugins/dominant-color-images/data/images/white.jpg
rename to plugins/dominant-color-images/tests/data/images/white.jpg
diff --git a/tests/plugins/dominant-color-images/data/images/white.png b/plugins/dominant-color-images/tests/data/images/white.png
similarity index 100%
rename from tests/plugins/dominant-color-images/data/images/white.png
rename to plugins/dominant-color-images/tests/data/images/white.png
diff --git a/tests/plugins/dominant-color-images/data/images/white.webp b/plugins/dominant-color-images/tests/data/images/white.webp
similarity index 100%
rename from tests/plugins/dominant-color-images/data/images/white.webp
rename to plugins/dominant-color-images/tests/data/images/white.webp
diff --git a/tests/plugins/dominant-color-images/data/images/wordpress-gsoc-flyer.pdf b/plugins/dominant-color-images/tests/data/images/wordpress-gsoc-flyer.pdf
similarity index 100%
rename from tests/plugins/dominant-color-images/data/images/wordpress-gsoc-flyer.pdf
rename to plugins/dominant-color-images/tests/data/images/wordpress-gsoc-flyer.pdf
diff --git a/tests/utils/TestCase/DominantColorTestCase.php b/plugins/dominant-color-images/tests/data/testcase.php
similarity index 53%
rename from tests/utils/TestCase/DominantColorTestCase.php
rename to plugins/dominant-color-images/tests/data/testcase.php
index b5f5f3d8e1..21a05fbe0f 100644
--- a/tests/utils/TestCase/DominantColorTestCase.php
+++ b/plugins/dominant-color-images/tests/data/testcase.php
@@ -1,10 +1,10 @@
array(
- 'image_path' => TESTS_PLUGIN_DIR . '/tests/plugins/dominant-color-images/data/images/animated.gif',
+ 'image_path' => TESTS_PLUGIN_DIR . '/tests/data/images/animated.gif',
'expected_color' => array( '874e4e', '864e4e', 'df7f7f' ),
'expected_transparency' => true,
),
'red_jpg' => array(
- 'image_path' => TESTS_PLUGIN_DIR . '/tests/plugins/dominant-color-images/data/images/red.jpg',
+ 'image_path' => TESTS_PLUGIN_DIR . '/tests/data/images/red.jpg',
'expected_color' => array( 'ff0000', 'fe0000' ),
'expected_transparency' => false,
),
'green_jpg' => array(
- 'image_path' => TESTS_PLUGIN_DIR . '/tests/plugins/dominant-color-images/data/images/green.jpg',
+ 'image_path' => TESTS_PLUGIN_DIR . '/tests/data/images/green.jpg',
'expected_color' => array( '00ff00', '00ff01', '02ff01' ),
'expected_transparency' => false,
),
'white_jpg' => array(
- 'image_path' => TESTS_PLUGIN_DIR . '/tests/plugins/dominant-color-images/data/images/white.jpg',
+ 'image_path' => TESTS_PLUGIN_DIR . '/tests/data/images/white.jpg',
'expected_color' => array( 'ffffff' ),
'expected_transparency' => false,
),
'red_gif' => array(
- 'image_path' => TESTS_PLUGIN_DIR . '/tests/plugins/dominant-color-images/data/images/red.gif',
+ 'image_path' => TESTS_PLUGIN_DIR . '/tests/data/images/red.gif',
'expected_color' => array( 'ff0000' ),
'expected_transparency' => false,
),
'green_gif' => array(
- 'image_path' => TESTS_PLUGIN_DIR . '/tests/plugins/dominant-color-images/data/images/green.gif',
+ 'image_path' => TESTS_PLUGIN_DIR . '/tests/data/images/green.gif',
'expected_color' => array( '00ff00' ),
'expected_transparency' => false,
),
'white_gif' => array(
- 'image_path' => TESTS_PLUGIN_DIR . '/tests/plugins/dominant-color-images/data/images/white.gif',
+ 'image_path' => TESTS_PLUGIN_DIR . '/tests/data/images/white.gif',
'expected_color' => array( 'ffffff' ),
'expected_transparency' => false,
),
'trans_gif' => array(
- 'image_path' => TESTS_PLUGIN_DIR . '/tests/plugins/dominant-color-images/data/images/trans.gif',
+ 'image_path' => TESTS_PLUGIN_DIR . '/tests/data/images/trans.gif',
'expected_color' => array( '5a5a5a', '020202' ),
'expected_transparency' => true,
),
'red_png' => array(
- 'image_path' => TESTS_PLUGIN_DIR . '/tests/plugins/dominant-color-images/data/images/red.png',
+ 'image_path' => TESTS_PLUGIN_DIR . '/tests/data/images/red.png',
'expected_color' => array( 'ff0000' ),
'expected_transparency' => false,
),
'green_png' => array(
- 'image_path' => TESTS_PLUGIN_DIR . '/tests/plugins/dominant-color-images/data/images/green.png',
+ 'image_path' => TESTS_PLUGIN_DIR . '/tests/data/images/green.png',
'expected_color' => array( '00ff00' ),
'expected_transparency' => false,
),
'white_png' => array(
- 'image_path' => TESTS_PLUGIN_DIR . '/tests/plugins/dominant-color-images/data/images/white.png',
+ 'image_path' => TESTS_PLUGIN_DIR . '/tests/data/images/white.png',
'expected_color' => array( 'ffffff' ),
'expected_transparency' => false,
),
'trans_png' => array(
- 'image_path' => TESTS_PLUGIN_DIR . '/tests/plugins/dominant-color-images/data/images/trans.png',
+ 'image_path' => TESTS_PLUGIN_DIR . '/tests/data/images/trans.png',
'expected_color' => array( '000000' ),
'expected_transparency' => true,
),
'red_webp' => array(
- 'image_path' => TESTS_PLUGIN_DIR . '/tests/plugins/dominant-color-images/data/images/red.webp',
+ 'image_path' => TESTS_PLUGIN_DIR . '/tests/data/images/red.webp',
'expected_color' => array( 'ff0000' ),
'expected_transparency' => false,
),
'green_webp' => array(
- 'image_path' => TESTS_PLUGIN_DIR . '/tests/plugins/dominant-color-images/data/images/green.webp',
+ 'image_path' => TESTS_PLUGIN_DIR . '/tests/data/images/green.webp',
'expected_color' => array( '00ff00' ),
'expected_transparency' => false,
),
'white_webp' => array(
- 'image_path' => TESTS_PLUGIN_DIR . '/tests/plugins/dominant-color-images/data/images/white.webp',
+ 'image_path' => TESTS_PLUGIN_DIR . '/tests/data/images/white.webp',
'expected_color' => array( 'ffffff' ),
'expected_transparency' => false,
),
'trans_webp' => array(
- 'image_path' => TESTS_PLUGIN_DIR . '/tests/plugins/dominant-color-images/data/images/trans.webp',
+ 'image_path' => TESTS_PLUGIN_DIR . '/tests/data/images/trans.webp',
'expected_color' => array( '000000' ),
'expected_transparency' => true,
),
'balloons_webp' => array(
- 'image_path' => TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/balloons.webp',
+ 'image_path' => TESTS_PLUGIN_ROOT . '/tests/data/images/balloons.webp',
'expected_color' => array( 'c1bbb9', 'c0bbb9', 'c0bab8', 'c3bdbd', 'bfbab8' ),
'expected_transparency' => false,
),
@@ -111,10 +111,10 @@ public function provider_get_dominant_color() {
public function provider_get_dominant_color_invalid_images() {
return array(
'tiff' => array(
- 'image_path' => TESTS_PLUGIN_DIR . '/tests/plugins/dominant-color-images/data/images/test-image.tiff',
+ 'image_path' => TESTS_PLUGIN_DIR . '/tests/data/images/test-image.tiff',
),
'bmp' => array(
- 'image_path' => TESTS_PLUGIN_DIR . '/tests/plugins/dominant-color-images/data/images/test-image.bmp',
+ 'image_path' => TESTS_PLUGIN_DIR . '/tests/data/images/test-image.bmp',
),
);
}
@@ -127,10 +127,10 @@ public function provider_get_dominant_color_invalid_images() {
public function provider_get_dominant_color_none_images() {
return array(
'pdf' => array(
- 'files_path' => TESTS_PLUGIN_DIR . '/tests/plugins/dominant-color-images/data/images/wordpress-gsoc-flyer.pdf',
+ 'files_path' => TESTS_PLUGIN_DIR . '/tests/data/images/wordpress-gsoc-flyer.pdf',
),
'mp4' => array(
- 'files_path' => TESTS_PLUGIN_DIR . '/tests/plugins/dominant-color-images/data/images/small-video.mp4',
+ 'files_path' => TESTS_PLUGIN_DIR . '/tests/data/images/small-video.mp4',
),
);
}
diff --git a/tests/plugins/dominant-color-images/dominant-color-image-editor-gd-test.php b/plugins/dominant-color-images/tests/dominant-color-image-editor-gd-test.php
similarity index 83%
rename from tests/plugins/dominant-color-images/dominant-color-image-editor-gd-test.php
rename to plugins/dominant-color-images/tests/dominant-color-image-editor-gd-test.php
index 0fa1f65485..235852f11f 100644
--- a/tests/plugins/dominant-color-images/dominant-color-image-editor-gd-test.php
+++ b/plugins/dominant-color-images/tests/dominant-color-image-editor-gd-test.php
@@ -5,10 +5,27 @@
* @package dominant-color-images
*/
-use PerformanceLab\Tests\TestCase\DominantColorTestCase;
+use Dominant_Color_Image\Tests\TestCase as DominantColorTestCase;
class Dominant_Color_Image_Editor_GD_Test extends DominantColorTestCase {
+ /**
+ * Setup before class.
+ */
+ public static function wpSetUpBeforeClass() {
+ // Setup site options if it's a multisite network.
+ if ( is_multisite() ) {
+ $site_exts = explode( ' ', get_site_option( 'upload_filetypes', 'jpg jpeg png gif' ) );
+
+ // Add `tiff` and `bmp` to the list of allowed file types.
+ // These are removed by default in multisite.
+ $site_exts[] = 'tiff';
+ $site_exts[] = 'bmp';
+
+ update_site_option( 'upload_filetypes', implode( ' ', $site_exts ) );
+ }
+ }
+
/**
* Test if the function returns the correct color.
*
diff --git a/tests/plugins/dominant-color-images/dominant-color-image-editor-imagick-test.php b/plugins/dominant-color-images/tests/dominant-color-image-editor-imagick-test.php
similarity index 83%
rename from tests/plugins/dominant-color-images/dominant-color-image-editor-imagick-test.php
rename to plugins/dominant-color-images/tests/dominant-color-image-editor-imagick-test.php
index 8f8749155f..015b52039c 100644
--- a/tests/plugins/dominant-color-images/dominant-color-image-editor-imagick-test.php
+++ b/plugins/dominant-color-images/tests/dominant-color-image-editor-imagick-test.php
@@ -7,10 +7,27 @@
* @package dominant-color-images
*/
-use PerformanceLab\Tests\TestCase\DominantColorTestCase;
+use Dominant_Color_Image\Tests\TestCase as DominantColorTestCase;
class Dominant_Color_Image_Editor_Imagick_Test extends DominantColorTestCase {
+ /**
+ * Setup before class.
+ */
+ public static function wpSetUpBeforeClass() {
+ // Setup site options if it's a multisite network.
+ if ( is_multisite() ) {
+ $site_exts = explode( ' ', get_site_option( 'upload_filetypes', 'jpg jpeg png gif' ) );
+
+ // Add `tiff` and `bmp` to the list of allowed file types.
+ // These are removed by default in multisite.
+ $site_exts[] = 'tiff';
+ $site_exts[] = 'bmp';
+
+ update_site_option( 'upload_filetypes', implode( ' ', $site_exts ) );
+ }
+ }
+
/**
* Test if the function returns the correct color.
*
diff --git a/tests/plugins/dominant-color-images/dominant-color-test.php b/plugins/dominant-color-images/tests/dominant-color-test.php
similarity index 97%
rename from tests/plugins/dominant-color-images/dominant-color-test.php
rename to plugins/dominant-color-images/tests/dominant-color-test.php
index a2b032a892..8bb9727a07 100644
--- a/tests/plugins/dominant-color-images/dominant-color-test.php
+++ b/plugins/dominant-color-images/tests/dominant-color-test.php
@@ -1,6 +1,6 @@
attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/plugins/dominant-color-images/data/images/red.jpg' );
+ $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/red.jpg' );
wp_maybe_generate_attachment_metadata( get_post( $attachment_id ) );
$image_url = wp_get_attachment_image_url( $attachment_id );
@@ -192,7 +192,7 @@ public function data_dominant_color_img_tag_add_dominant_color_requires_proper_q
* @param string $expected The expected style attribute and value.
*/
public function test_dominant_color_img_tag_add_dominant_color_should_add_dominant_color_inline_style( $filtered_image, $expected ) {
- $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/plugins/dominant-color-images/data/images/red.jpg' );
+ $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/red.jpg' );
wp_maybe_generate_attachment_metadata( get_post( $attachment_id ) );
list( $src, $width, $height ) = wp_get_attachment_image_src( $attachment_id );
@@ -232,7 +232,7 @@ public function data_provider_dominant_color_check_inline_style() {
* @param string $expected The expected style attribute and value.
*/
public function test_dominant_color_update_attachment_image_attributes( $style_attr, $expected ) {
- $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/plugins/dominant-color-images/data/images/red.jpg' );
+ $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/red.jpg' );
$attachment_image = wp_get_attachment_image( $attachment_id, 'full', '', array( 'style' => $style_attr ) );
$this->assertStringContainsString( $expected, $attachment_image );
diff --git a/plugins/embed-optimizer/phpunit.xml.dist b/plugins/embed-optimizer/phpunit.xml.dist
new file mode 100644
index 0000000000..ca1f119b86
--- /dev/null
+++ b/plugins/embed-optimizer/phpunit.xml.dist
@@ -0,0 +1,15 @@
+
+
+
+ ./tests
+
+
+
diff --git a/plugins/embed-optimizer/tests/bootstrap.php b/plugins/embed-optimizer/tests/bootstrap.php
new file mode 100644
index 0000000000..5637c2e93f
--- /dev/null
+++ b/plugins/embed-optimizer/tests/bootstrap.php
@@ -0,0 +1,23 @@
+ array( basename( TESTS_PLUGIN_DIR ) . '/load.php' ),
+);
+
+// Start up the WP testing environment.
+require $_tests_dir . '/includes/bootstrap.php';
diff --git a/tests/plugins/embed-optimizer/embed-optimizer-test.php b/plugins/embed-optimizer/tests/embed-optimizer-test.php
similarity index 100%
rename from tests/plugins/embed-optimizer/embed-optimizer-test.php
rename to plugins/embed-optimizer/tests/embed-optimizer-test.php
diff --git a/plugins/optimization-detective/phpunit.xml.dist b/plugins/optimization-detective/phpunit.xml.dist
new file mode 100644
index 0000000000..b616103e7d
--- /dev/null
+++ b/plugins/optimization-detective/phpunit.xml.dist
@@ -0,0 +1,15 @@
+
+
+
+ ./tests
+
+
+
diff --git a/plugins/optimization-detective/tests/bootstrap.php b/plugins/optimization-detective/tests/bootstrap.php
new file mode 100644
index 0000000000..4aec62c1d9
--- /dev/null
+++ b/plugins/optimization-detective/tests/bootstrap.php
@@ -0,0 +1,23 @@
+ array( basename( TESTS_PLUGIN_DIR ) . '/load.php' ),
+);
+
+// Start up the WP testing environment.
+require $_tests_dir . '/includes/bootstrap.php';
diff --git a/tests/plugins/optimization-detective/class-od-html-tag-processor-tests.php b/plugins/optimization-detective/tests/class-od-html-tag-processor-tests.php
similarity index 100%
rename from tests/plugins/optimization-detective/class-od-html-tag-processor-tests.php
rename to plugins/optimization-detective/tests/class-od-html-tag-processor-tests.php
diff --git a/tests/plugins/optimization-detective/class-od-url-metric-tests.php b/plugins/optimization-detective/tests/class-od-url-metric-tests.php
similarity index 100%
rename from tests/plugins/optimization-detective/class-od-url-metric-tests.php
rename to plugins/optimization-detective/tests/class-od-url-metric-tests.php
diff --git a/tests/plugins/optimization-detective/class-od-url-metrics-group-collection-tests.php b/plugins/optimization-detective/tests/class-od-url-metrics-group-collection-tests.php
similarity index 100%
rename from tests/plugins/optimization-detective/class-od-url-metrics-group-collection-tests.php
rename to plugins/optimization-detective/tests/class-od-url-metrics-group-collection-tests.php
diff --git a/tests/plugins/optimization-detective/class-od-url-metrics-group-tests.php b/plugins/optimization-detective/tests/class-od-url-metrics-group-tests.php
similarity index 100%
rename from tests/plugins/optimization-detective/class-od-url-metrics-group-tests.php
rename to plugins/optimization-detective/tests/class-od-url-metrics-group-tests.php
diff --git a/tests/plugins/optimization-detective/detection-tests.php b/plugins/optimization-detective/tests/detection-tests.php
similarity index 100%
rename from tests/plugins/optimization-detective/detection-tests.php
rename to plugins/optimization-detective/tests/detection-tests.php
diff --git a/tests/plugins/optimization-detective/helper-tests.php b/plugins/optimization-detective/tests/helper-tests.php
similarity index 100%
rename from tests/plugins/optimization-detective/helper-tests.php
rename to plugins/optimization-detective/tests/helper-tests.php
diff --git a/tests/plugins/optimization-detective/hooks-tests.php b/plugins/optimization-detective/tests/hooks-tests.php
similarity index 100%
rename from tests/plugins/optimization-detective/hooks-tests.php
rename to plugins/optimization-detective/tests/hooks-tests.php
diff --git a/tests/plugins/optimization-detective/optimization-tests.php b/plugins/optimization-detective/tests/optimization-tests.php
similarity index 100%
rename from tests/plugins/optimization-detective/optimization-tests.php
rename to plugins/optimization-detective/tests/optimization-tests.php
diff --git a/tests/plugins/optimization-detective/storage/class-od-storage-lock-tests.php b/plugins/optimization-detective/tests/storage/class-od-storage-lock-tests.php
similarity index 100%
rename from tests/plugins/optimization-detective/storage/class-od-storage-lock-tests.php
rename to plugins/optimization-detective/tests/storage/class-od-storage-lock-tests.php
diff --git a/tests/plugins/optimization-detective/storage/class-od-url-metrics-post-type-tests.php b/plugins/optimization-detective/tests/storage/class-od-url-metrics-post-type-tests.php
similarity index 100%
rename from tests/plugins/optimization-detective/storage/class-od-url-metrics-post-type-tests.php
rename to plugins/optimization-detective/tests/storage/class-od-url-metrics-post-type-tests.php
diff --git a/tests/plugins/optimization-detective/storage/data-tests.php b/plugins/optimization-detective/tests/storage/data-tests.php
similarity index 100%
rename from tests/plugins/optimization-detective/storage/data-tests.php
rename to plugins/optimization-detective/tests/storage/data-tests.php
diff --git a/tests/plugins/optimization-detective/storage/rest-api-tests.php b/plugins/optimization-detective/tests/storage/rest-api-tests.php
similarity index 100%
rename from tests/plugins/optimization-detective/storage/rest-api-tests.php
rename to plugins/optimization-detective/tests/storage/rest-api-tests.php
diff --git a/tests/plugins/optimization-detective/uninstall-tests.php b/plugins/optimization-detective/tests/uninstall-tests.php
similarity index 100%
rename from tests/plugins/optimization-detective/uninstall-tests.php
rename to plugins/optimization-detective/tests/uninstall-tests.php
diff --git a/plugins/speculation-rules/phpunit.xml.dist b/plugins/speculation-rules/phpunit.xml.dist
new file mode 100644
index 0000000000..ca1f119b86
--- /dev/null
+++ b/plugins/speculation-rules/phpunit.xml.dist
@@ -0,0 +1,15 @@
+
+
+
+ ./tests
+
+
+
diff --git a/plugins/speculation-rules/tests/bootstrap.php b/plugins/speculation-rules/tests/bootstrap.php
new file mode 100644
index 0000000000..bdc9fb8704
--- /dev/null
+++ b/plugins/speculation-rules/tests/bootstrap.php
@@ -0,0 +1,23 @@
+ array( basename( TESTS_PLUGIN_DIR ) . '/load.php' ),
+);
+
+// Start up the WP testing environment.
+require $_tests_dir . '/includes/bootstrap.php';
diff --git a/tests/plugins/speculation-rules/plsr-url-pattern-prefixer-test.php b/plugins/speculation-rules/tests/plsr-url-pattern-prefixer-test.php
similarity index 100%
rename from tests/plugins/speculation-rules/plsr-url-pattern-prefixer-test.php
rename to plugins/speculation-rules/tests/plsr-url-pattern-prefixer-test.php
diff --git a/tests/plugins/speculation-rules/speculation-rules-helper-test.php b/plugins/speculation-rules/tests/speculation-rules-helper-test.php
similarity index 100%
rename from tests/plugins/speculation-rules/speculation-rules-helper-test.php
rename to plugins/speculation-rules/tests/speculation-rules-helper-test.php
diff --git a/tests/plugins/speculation-rules/speculation-rules-settings-test.php b/plugins/speculation-rules/tests/speculation-rules-settings-test.php
similarity index 100%
rename from tests/plugins/speculation-rules/speculation-rules-settings-test.php
rename to plugins/speculation-rules/tests/speculation-rules-settings-test.php
diff --git a/tests/plugins/speculation-rules/speculation-rules-test.php b/plugins/speculation-rules/tests/speculation-rules-test.php
similarity index 100%
rename from tests/plugins/speculation-rules/speculation-rules-test.php
rename to plugins/speculation-rules/tests/speculation-rules-test.php
diff --git a/plugins/webp-uploads/phpunit.xml.dist b/plugins/webp-uploads/phpunit.xml.dist
new file mode 100644
index 0000000000..ca1f119b86
--- /dev/null
+++ b/plugins/webp-uploads/phpunit.xml.dist
@@ -0,0 +1,15 @@
+
+
+
+ ./tests
+
+
+
diff --git a/plugins/webp-uploads/tests/bootstrap.php b/plugins/webp-uploads/tests/bootstrap.php
new file mode 100644
index 0000000000..1556f707fc
--- /dev/null
+++ b/plugins/webp-uploads/tests/bootstrap.php
@@ -0,0 +1,30 @@
+ array( basename( TESTS_PLUGIN_DIR ) . '/load.php' ),
+);
+
+// Start up the WP testing environment.
+require $_tests_dir . '/includes/bootstrap.php';
+
+// Load tests helpers.
+require_once TESTS_PLUGIN_DIR . '/tests/data/testcase.php';
+require_once TESTS_PLUGIN_DIR . '/tests/data/class-wp-image-edit.php';
+require_once TESTS_PLUGIN_DIR . '/tests/data/class-wp-image-doesnt-support-webp.php';
+require_once TESTS_PLUGIN_DIR . '/tests/data/class-image-has-source-constraint.php';
+require_once TESTS_PLUGIN_DIR . '/tests/data/class-image-has-size-source-constraint.php';
diff --git a/tests/utils/Constraint/ImageHasSizeSource.php b/plugins/webp-uploads/tests/data/class-image-has-size-source-constraint.php
similarity index 96%
rename from tests/utils/Constraint/ImageHasSizeSource.php
rename to plugins/webp-uploads/tests/data/class-image-has-size-source-constraint.php
index 0688ce6c1e..bb46049ad5 100644
--- a/tests/utils/Constraint/ImageHasSizeSource.php
+++ b/plugins/webp-uploads/tests/data/class-image-has-size-source-constraint.php
@@ -1,6 +1,8 @@
array(
- self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/car.jpeg' ),
+ self::factory()->attachment->create_upload_object( TESTS_PLUGIN_ROOT . '/tests/data/images/car.jpeg' ),
'medium',
array(),
'image/avif',
@@ -38,21 +38,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_ROOT . '/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_ROOT . '/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_ROOT . '/tests/data/images/car.jpeg' ),
'medium',
array(
'width' => -10,
@@ -62,7 +62,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_ROOT . '/tests/data/images/car.jpeg' ),
'medium',
array(
'width' => 0,
@@ -85,7 +85,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_ROOT . '/tests/data/images/car.jpeg' );
$size_data = array(
'width' => 300,
'height' => 300,
@@ -115,7 +115,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_ROOT . '/tests/data/images/car.jpeg' );
$size_data = array(
'width' => 300,
'height' => 300,
@@ -141,7 +141,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, $size ) {
$attachment_id = self::factory()->attachment->create_upload_object(
- TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/balloons.webp'
+ TESTS_PLUGIN_ROOT . '/tests/data/images/balloons.webp'
);
$metadata = wp_get_attachment_metadata( $attachment_id );
wp_update_attachment_metadata( $attachment_id, $callback( $metadata ) );
@@ -189,7 +189,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_ROOT . '/tests/data/images/leaves.jpg'
);
$file = get_attached_file( $attachment_id );
$original_file = wp_get_original_image_path( $attachment_id );
@@ -213,7 +213,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() {
$attachment_id = self::factory()->attachment->create_upload_object(
- TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg'
+ TESTS_PLUGIN_ROOT . '/tests/data/images/leaves.jpg'
);
// Make sure no editor is available.
@@ -230,7 +230,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() {
$attachment_id = self::factory()->attachment->create_upload_object(
- TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg'
+ TESTS_PLUGIN_ROOT . '/tests/data/images/leaves.jpg'
);
$result = webp_uploads_generate_image_size( $attachment_id, 'medium', 'image/vnd.zbrush.pcx' );
$this->assertWPError( $result );
@@ -245,7 +245,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() {
// 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_ROOT . '/tests/data/images/leaves.jpg'
);
add_filter(
@@ -268,7 +268,7 @@ static function () {
public function it_should_create_an_image_with_filter_webp_uploads_pre_generate_additional_image_source() {
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_ROOT . '/tests/data/images/car.jpeg' );
add_filter(
'webp_uploads_pre_generate_additional_image_source',
@@ -302,7 +302,7 @@ static function () {
public function it_should_use_filesize_when_filter_webp_uploads_pre_generate_additional_image_source_returns_filesize() {
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_ROOT . '/tests/data/images/car.jpeg' );
add_filter(
'webp_uploads_pre_generate_additional_image_source',
@@ -337,7 +337,7 @@ static function () {
public function it_should_return_an_error_when_filter_webp_uploads_pre_generate_additional_image_source_returns_wp_error() {
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_ROOT . '/tests/data/images/car.jpeg' );
add_filter(
'webp_uploads_pre_generate_additional_image_source',
@@ -582,8 +582,8 @@ public function it_should_add_original_image_extension_to_the_webp_file_name_to_
public function data_provider_same_image_name() {
return array(
array(
- TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/image.jpeg',
- TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/image.jpg',
+ TESTS_PLUGIN_ROOT . '/tests/data/images/image.jpeg',
+ TESTS_PLUGIN_ROOT . '/tests/data/images/image.jpg',
),
);
}
diff --git a/tests/plugins/webp-uploads/image-edit-tests.php b/plugins/webp-uploads/tests/image-edit-test.php
similarity index 94%
rename from tests/plugins/webp-uploads/image-edit-tests.php
rename to plugins/webp-uploads/tests/image-edit-test.php
index 1685439430..8c36d23a57 100644
--- a/tests/plugins/webp-uploads/image-edit-tests.php
+++ b/plugins/webp-uploads/tests/image-edit-test.php
@@ -6,7 +6,7 @@
* @subpackage image-edit
*/
-use PerformanceLab\Tests\TestCase\ImagesTestCase;
+use WebP_Uploads\Tests\TestCase as ImagesTestCase;
class WebP_Uploads_Image_Edit_Tests extends ImagesTestCase {
@@ -22,7 +22,7 @@ public function set_up() {
* @test
*/
public function it_should_backup_the_sources_structure_alongside_the_full_size() {
- $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_ROOT . '/tests/data/images/leaves.jpg' );
$metadata = wp_get_attachment_metadata( $attachment_id );
$this->assertEmpty( get_post_meta( $attachment_id, '_wp_attachment_backup_sizes', true ) );
@@ -68,7 +68,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_ROOT . '/tests/data/images/leaves.jpg' );
$metadata = wp_get_attachment_metadata( $attachment_id );
$editor = new WP_Image_Edit( $attachment_id );
@@ -122,7 +122,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_ROOT . '/tests/data/images/leaves.jpg' );
$metadata = wp_get_attachment_metadata( $attachment_id );
$this->assertArrayNotHasKey( 'sources', $metadata );
@@ -155,7 +155,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_ROOT . '/tests/data/images/leaves.jpg' );
$metadata = wp_get_attachment_metadata( $attachment_id );
$this->assertArrayHasKey( 'sources', $metadata );
@@ -207,7 +207,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_ROOT . '/tests/data/images/leaves.jpg' );
$metadata = wp_get_attachment_metadata( $attachment_id );
$editor = new WP_Image_Edit( $attachment_id );
@@ -262,7 +262,7 @@ static function () {
);
$attachment_id = self::factory()->attachment->create_upload_object(
- TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg'
+ TESTS_PLUGIN_ROOT . '/tests/data/images/leaves.jpg'
);
$this->assertNotSame( wp_get_original_image_path( $attachment_id ), get_attached_file( $attachment_id ) );
@@ -310,7 +310,7 @@ public function it_should_validate_source_attribute_update_when_webp_edited() {
$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_ROOT . '/tests/data/images/leaves.jpg' );
$editor = new WP_Image_Edit( $attachment_id );
$editor->crop( 1000, 200, 0, 0 )->save();
@@ -339,7 +339,7 @@ public function it_should_validate_source_attribute_update_when_webp_edited() {
* @test
*/
public function it_should_not_return_a_target_if_no_backup_image_exists() {
- $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_ROOT . '/tests/data/images/leaves.jpg' );
$this->assertNull( webp_uploads_get_next_full_size_key_from_backup( $attachment_id ) );
}
@@ -352,7 +352,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_ROOT . '/tests/data/images/leaves.jpg' );
$editor = new WP_Image_Edit( $attachment_id );
$editor->rotate_right()->save();
@@ -366,7 +366,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() {
- $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_ROOT . '/tests/data/images/leaves.jpg' );
$editor = new WP_Image_Edit( $attachment_id );
$editor->rotate_right()->save();
@@ -383,7 +383,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_ROOT . '/tests/data/images/leaves.jpg' );
$editor = new WP_Image_Edit( $attachment_id );
$editor->rotate_right()->save();
@@ -405,7 +405,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_ROOT . '/tests/data/images/leaves.jpg' );
$editor = new WP_Image_Edit( $attachment_id );
$editor->rotate_right()->save();
$this->assertTrue( $editor->success() );
@@ -425,7 +425,7 @@ public function it_should_store_the_metadata_on_the_next_available_hash() {
// 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_ROOT . '/tests/data/images/leaves.jpg' );
$editor = new WP_Image_Edit( $attachment_id );
$editor->rotate_right()->save();
@@ -457,7 +457,7 @@ public function it_should_prevent_to_store_an_empty_set_of_sources() {
// 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_ROOT . '/tests/data/images/leaves.jpg' );
$editor = new WP_Image_Edit( $attachment_id );
$editor->rotate_right()->save();
@@ -477,7 +477,7 @@ public function it_should_store_the_next_image_hash_on_the_backup_sources() {
$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_ROOT . '/tests/data/images/leaves.jpg' );
$editor = new WP_Image_Edit( $attachment_id );
// Edit the image.
$editor->rotate_right()->save();
@@ -506,7 +506,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_ROOT . '/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/plugins/webp-uploads/tests/load-test.php
similarity index 93%
rename from tests/plugins/webp-uploads/load-tests.php
rename to plugins/webp-uploads/tests/load-test.php
index 45fd358e72..c4cf887555 100644
--- a/tests/plugins/webp-uploads/load-tests.php
+++ b/plugins/webp-uploads/tests/load-test.php
@@ -5,7 +5,7 @@
* @package webp-uploads
*/
-use PerformanceLab\Tests\TestCase\ImagesTestCase;
+use WebP_Uploads\Tests\TestCase as ImagesTestCase;
class WebP_Uploads_Load_Tests extends ImagesTestCase {
@@ -43,7 +43,7 @@ static function ( $filename ) {
* @test
*/
public function it_should_not_create_the_original_mime_type_for_jpeg_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_ROOT . '/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() {
* @test
*/
public function it_should_create_the_original_mime_type_as_well_with_all_the_available_sources_for_the_specified_mime() {
- $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_ROOT . '/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() {
$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_ROOT . '/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() {
public function it_should_create_jpeg_and_webp_for_jpeg_images_if_generate_webp_and_jpeg_set() {
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_ROOT . '/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_ROOT . '/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_ROOT . '/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_ROOT . '/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() {
$attachment_id = self::factory()->attachment->create_upload_object(
- TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg'
+ TESTS_PLUGIN_ROOT . '/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_ROOT . '/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_ROOT . '/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() {
$attachment_id = self::factory()->attachment->create_upload_object(
- TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg'
+ TESTS_PLUGIN_ROOT . '/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() {
$attachment_id = self::factory()->attachment->create_upload_object(
- TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg'
+ TESTS_PLUGIN_ROOT . '/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() {
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_ROOT . '/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() {
*/
public function it_should_remove_the_backup_sizes_and_sources_if_the_attachment_is_deleted_after_edit() {
$attachment_id = self::factory()->attachment->create_upload_object(
- TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg'
+ TESTS_PLUGIN_ROOT . '/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() {
$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_ROOT . '/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() {
*/
public function it_should_prevent_replacing_a_jpg_image_if_the_image_does_not_have_the_target_class_name() {
$attachment_id = self::factory()->attachment->create_upload_object(
- TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg'
+ TESTS_PLUGIN_ROOT . '/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() {
- 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_ROOT . '/tests/data/images/leaves.jpg' );
+ yield 'An image with a .jpeg extension' => array( TESTS_PLUGIN_ROOT . '/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_ROOT . '/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() {
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_ROOT . '/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() {
- 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_ROOT . '/tests/data/images/dice.png' );
+ yield 'GIFT image' => array( TESTS_PLUGIN_ROOT . '/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_ROOT . '/tests/data/images/paint.jpeg' );
$metadata = wp_get_attachment_metadata( $attachment_id );
foreach ( $metadata['sizes'] as $size ) {
@@ -650,8 +650,8 @@ static function () {
}
$this->assertIsString( $size['sources']['image/webp']['file'] );
- $this->assertStringContainsString( $size['width'], $size['sources']['image/webp']['file'] );
- $this->assertStringContainsString( $size['height'], $size['sources']['image/webp']['file'] );
+ $this->assertStringContainsString( (string) $size['width'], $size['sources']['image/webp']['file'] );
+ $this->assertStringContainsString( (string) $size['height'], $size['sources']['image/webp']['file'] );
$this->assertStringContainsString(
// Remove the extension from the file.
substr( $size['sources']['image/webp']['file'], 0, -13 ),
@@ -669,7 +669,7 @@ public function it_should_preserve_jpeg_subsizes_using_transform_filter() {
// 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_ROOT . '/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_ROOT . '/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() {
- $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_ROOT . '/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_ROOT . '/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() {
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_ROOT . '/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_ROOT . '/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_ROOT . '/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() {
remove_all_actions( 'wp_footer' );
$attachment_id = self::factory()->attachment->create_upload_object(
- TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg'
+ TESTS_PLUGIN_ROOT . '/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_ROOT . '/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_ROOT . '/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() {
// 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_ROOT . '/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() {
$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_ROOT . '/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/plugins/webp-uploads/tests/rest-api-test.php
similarity index 95%
rename from tests/plugins/webp-uploads/rest-api-tests.php
rename to plugins/webp-uploads/tests/rest-api-test.php
index e6c154858b..d87a2f3ec4 100644
--- a/tests/plugins/webp-uploads/rest-api-tests.php
+++ b/plugins/webp-uploads/tests/rest-api-test.php
@@ -29,7 +29,7 @@ static function ( $transforms ) {
}
);
- $file_location = TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg';
+ $file_location = TESTS_PLUGIN_ROOT . '/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() {
- $file_location = TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leaves.jpg';
+ $file_location = TESTS_PLUGIN_ROOT . '/tests/data/images/leaves.jpg';
$attachment_id = self::factory()->attachment->create_upload_object( $file_location );
$request = new WP_REST_Request();
diff --git a/tests/bootstrap-functions.php b/tests/bootstrap-functions.php
new file mode 100644
index 0000000000..5e04b8f335
--- /dev/null
+++ b/tests/bootstrap-functions.php
@@ -0,0 +1,122 @@
+.
+ *
+ * @return string|false The path to the WP test directory, or false if it could not be determined.
+ */
+function get_path_to_wp_test_dir() {
+ if ( false !== getenv( 'WP_TESTS_DIR' ) ) {
+ $tests_dir = getenv( 'WP_TESTS_DIR' );
+ $tests_dir = realpath( $tests_dir );
+ if ( false !== $tests_dir ) {
+ $tests_dir = normalize_path( $tests_dir ) . '/';
+ if ( is_dir( $tests_dir ) === true
+ && file_exists( $tests_dir . 'includes/bootstrap.php' )
+ ) {
+ return $tests_dir;
+ }
+ }
+
+ unset( $tests_dir );
+ }
+
+ if ( false !== getenv( 'WP_DEVELOP_DIR' ) ) {
+ $dev_dir = getenv( 'WP_DEVELOP_DIR' );
+ $dev_dir = realpath( $dev_dir );
+ if ( false !== $dev_dir ) {
+ $dev_dir = normalize_path( $dev_dir ) . '/';
+ if ( is_dir( $dev_dir ) === true
+ && file_exists( $dev_dir . 'tests/phpunit/includes/bootstrap.php' )
+ ) {
+ return $dev_dir . 'tests/phpunit/';
+ }
+ }
+
+ unset( $dev_dir );
+ }
+
+ /*
+ * If neither of the constants was set, check whether the plugin is installed
+ * in `src/wp-content/plugins`. In that case, this file would be in
+ * `src/wp-content/plugins/performance/tests`.
+ */
+ if ( file_exists( __DIR__ . '/../../../../../tests/phpunit/includes/bootstrap.php' ) ) {
+ $tests_dir = __DIR__ . '/../../../../../tests/phpunit/';
+ $tests_dir = realpath( $tests_dir );
+ if ( false !== $tests_dir ) {
+ return normalize_path( $tests_dir ) . '/';
+ }
+
+ unset( $tests_dir );
+ }
+
+ /*
+ * Last resort: see if this is a typical WP-CLI scaffold command set-up where a subset of
+ * the WP test files have been put in the system temp directory.
+ */
+ $tests_dir = sys_get_temp_dir() . '/wordpress-tests-lib';
+ $tests_dir = realpath( $tests_dir );
+ if ( false !== $tests_dir ) {
+ $tests_dir = normalize_path( $tests_dir ) . '/';
+ if ( true === is_dir( $tests_dir )
+ && file_exists( $tests_dir . 'includes/bootstrap.php' )
+ ) {
+ return $tests_dir;
+ }
+ }
+
+ return false;
+}
+
+/**
+ * Normalizes all slashes in a file path to forward slashes.
+ *
+ * @param string $path File path.
+ *
+ * @return string The file path with normalized slashes.
+ */
+function normalize_path( $path ) {
+ return \str_replace( '\\', '/', $path );
+}
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index bad90cfb8e..09f50587f0 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -7,81 +7,27 @@
define( 'TESTS_PLUGIN_DIR', dirname( __DIR__ ) );
-// Determine correct location for plugins directory to use.
-if ( false !== getenv( 'WP_PLUGIN_DIR' ) ) {
- define( 'WP_PLUGIN_DIR', getenv( 'WP_PLUGIN_DIR' ) );
-} else {
- define( 'WP_PLUGIN_DIR', dirname( TESTS_PLUGIN_DIR ) );
-}
-
-// Load Composer dependencies if applicable.
-if ( file_exists( TESTS_PLUGIN_DIR . '/vendor/autoload.php' ) ) {
- require_once TESTS_PLUGIN_DIR . '/vendor/autoload.php';
-}
-
-// Detect where to load the WordPress tests environment from.
-if ( false !== getenv( 'WP_TESTS_DIR' ) ) {
- $_test_root = getenv( 'WP_TESTS_DIR' );
-} elseif ( false !== getenv( 'WP_DEVELOP_DIR' ) ) {
- $_test_root = getenv( 'WP_DEVELOP_DIR' ) . '/tests/phpunit';
-} elseif ( false !== getenv( 'WP_PHPUNIT__DIR' ) ) {
- $_test_root = getenv( 'WP_PHPUNIT__DIR' );
-} elseif ( file_exists( TESTS_PLUGIN_DIR . '/../../../../tests/phpunit/includes/functions.php' ) ) {
- $_test_root = TESTS_PLUGIN_DIR . '/../../../../tests/phpunit';
-} else { // Fallback.
- $_test_root = '/tmp/wordpress-tests-lib';
-}
-
-require_once $_test_root . '/includes/functions.php';
-
-// Check if we use the plugin's test suite. If so, disable the PL plugin and only load the requested plugin.
-$plugin_name = '';
-foreach ( $_SERVER['argv'] as $index => $arg ) {
- 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 ];
- }
-}
-
-if ( $plugin_name ) {
- $plugin_test_path = TESTS_PLUGIN_DIR . '/plugins/' . $plugin_name;
- tests_add_filter(
- 'plugins_loaded',
- static function () use ( $plugin_test_path, $plugin_name ) {
- // 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
- );
-} 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 () {
- 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
- );
-}
+// Load bootstrap functions.
+require_once TESTS_PLUGIN_DIR . '/tests/bootstrap-functions.php';
+
+// Initialize the WP testing environment.
+$_tests_dir = PerformanceLab\Tests\init( TESTS_PLUGIN_DIR );
+
+// 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 for tests.
+tests_add_filter(
+ 'plugins_loaded',
+ static function () {
+ 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
+);
// Start up the WP testing environment.
-require $_test_root . '/includes/bootstrap.php';
+require $_tests_dir . '/includes/bootstrap.php';
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/testdata/modules/site-health/audit-enqueued-assets/class-audit-assets-transients-set.php b/tests/includes/site-health/audit-enqueued-assets/data/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/includes/site-health/audit-enqueued-assets/data/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/includes/site-health/audit-enqueued-assets/data/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/includes/site-health/audit-enqueued-assets/data/class-site-health-mock-responses.php
diff --git a/tests/multisite.xml b/tests/multisite.xml
deleted file mode 100644
index 8f03b47fbe..0000000000
--- a/tests/multisite.xml
+++ /dev/null
@@ -1,30 +0,0 @@
-
-
-
-
-
-
- ./
- ./utils
- ./plugins
-
-
- ./plugins/auto-sizes
-
-
- ./plugins/speculation-rules
-
-
-
-
- ms-excluded
-
-
-
diff --git a/webpack.config.js b/webpack.config.js
index 2de1217bc1..2a59455df7 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -120,9 +120,11 @@ const buildPlugin = ( env ) => {
globOptions: {
dot: true,
ignore: [
+ '**/tests',
+ '**/*.[Cc]ache',
'**/.wordpress-org',
'**/phpcs.xml.dist',
- '**/*.[Cc]ache',
+ '**/phpunit.xml.dist',
],
},
},