Skip to content

Commit

Permalink
Merge pull request #1804 from ShyamGadde/update/remove-root-tests-dir
Browse files Browse the repository at this point in the history
Clear out and remove `/tests` directory
  • Loading branch information
westonruter authored Jan 28, 2025
2 parents 10f4dc0 + a985976 commit d94977f
Show file tree
Hide file tree
Showing 26 changed files with 67 additions and 56 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/php-test-plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ on:
- '**/package.json'
- 'package-lock.json'
- 'phpunit.xml.dist'
- 'tests/multisite.xml'
- 'composer.json'
- 'composer.lock'
pull_request:
Expand All @@ -25,7 +24,6 @@ on:
- '**/package.json'
- 'package-lock.json'
- 'phpunit.xml.dist'
- 'tests/multisite.xml'
- 'composer.json'
- 'composer.lock'
types:
Expand Down
1 change: 0 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ parameters:
treatPhpDocTypesAsCertain: false
paths:
- plugins
- tests
- performance.php
- plugins/performance-lab/load.php
bootstrapFiles:
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<phpunit
colors="true"
backupGlobals="false"
bootstrap="tests/bootstrap.php"
bootstrap="tools/phpunit/bootstrap.php"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
Expand Down
10 changes: 0 additions & 10 deletions plugins/auto-sizes/tests/bootstrap.php

This file was deleted.

File renamed without changes
42 changes: 21 additions & 21 deletions plugins/dominant-color-images/tests/data/class-testcase.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,85 +13,85 @@ abstract class TestCase extends WP_UnitTestCase {
public function provider_get_dominant_color(): array {
return array(
'animated_gif' => array(
'image_path' => __DIR__ . '/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' => __DIR__ . '/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' => __DIR__ . '/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' => __DIR__ . '/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' => __DIR__ . '/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' => __DIR__ . '/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' => __DIR__ . '/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' => __DIR__ . '/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' => __DIR__ . '/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' => __DIR__ . '/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' => __DIR__ . '/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' => __DIR__ . '/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' => __DIR__ . '/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' => __DIR__ . '/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' => __DIR__ . '/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' => __DIR__ . '/images/trans.webp',
'image_path' => TESTS_PLUGIN_DIR . '/tests/data/images/trans.webp',
'expected_color' => array( '000000' ),
'expected_transparency' => true,
),
Expand All @@ -101,7 +101,7 @@ public function provider_get_dominant_color(): array {
'expected_transparency' => false,
),
'half_opaque' => array(
'image_path' => __DIR__ . '/images/half-opaque.png',
'image_path' => TESTS_PLUGIN_DIR . '/tests/data/images/half-opaque.png',
'expected_color' => array( '7e7e7e' ),
'expected_transparency' => true,
),
Expand All @@ -116,10 +116,10 @@ public function provider_get_dominant_color(): array {
public function provider_get_dominant_color_invalid_images(): array {
return array(
'tiff' => array(
'image_path' => __DIR__ . '/images/test-image.tiff',
'image_path' => TESTS_PLUGIN_DIR . '/tests/data/images/test-image.tiff',
),
'bmp' => array(
'image_path' => __DIR__ . '/images/test-image.bmp',
'image_path' => TESTS_PLUGIN_DIR . '/tests/data/images/test-image.bmp',
),
);
}
Expand All @@ -132,10 +132,10 @@ public function provider_get_dominant_color_invalid_images(): array {
public function provider_get_dominant_color_none_images(): array {
return array(
'pdf' => array(
'files_path' => __DIR__ . '/images/wordpress-gsoc-flyer.pdf',
'files_path' => TESTS_PLUGIN_DIR . '/tests/data/images/wordpress-gsoc-flyer.pdf',
),
'mp4' => array(
'files_path' => __DIR__ . '/images/small-video.mp4',
'files_path' => TESTS_PLUGIN_DIR . '/tests/data/images/small-video.mp4',
),
);
}
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions plugins/dominant-color-images/tests/test-dominant-color.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public function test_tag_add_adjust_to_image_attributes( string $image_path, arr
* @param bool $expected Whether the dominant color should be added.
*/
public function test_dominant_color_img_tag_add_dominant_color_requires_proper_quotes( string $image, bool $expected ): void {
$attachment_id = self::factory()->attachment->create_upload_object( __DIR__ . '/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 );
Expand Down Expand Up @@ -206,7 +206,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( string $filtered_image, string $expected ): void {
$attachment_id = self::factory()->attachment->create_upload_object( __DIR__ . '/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 );
Expand Down Expand Up @@ -246,7 +246,7 @@ public function data_provider_dominant_color_check_inline_style(): array {
* @param string $expected The expected style attribute and value.
*/
public function test_dominant_color_update_attachment_image_attributes( string $style_attr, string $expected ): void {
$attachment_id = self::factory()->attachment->create_upload_object( __DIR__ . '/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', false, array( 'style' => $style_attr ) );
$this->assertStringContainsString( $expected, $attachment_image );
Expand Down
5 changes: 4 additions & 1 deletion plugins/embed-optimizer/tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
*/

// Require the suggested plugin.
require_once __DIR__ . '/../../optimization-detective/load.php';
require_once TESTS_REPO_ROOT_DIR . '/plugins/optimization-detective/load.php';

// Load the test helpers.
require_once TESTS_REPO_ROOT_DIR . '/plugins/optimization-detective/tests/class-optimization-detective-test-helpers.php';
9 changes: 9 additions & 0 deletions plugins/image-prioritizer/tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
/**
* Test Bootstrap for Image Prioritizer.
*
* @package image-prioritizer
*/

// Load the test helpers.
require_once TESTS_REPO_ROOT_DIR . '/plugins/optimization-detective/tests/class-optimization-detective-test-helpers.php';
File renamed without changes
9 changes: 9 additions & 0 deletions plugins/optimization-detective/tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
/**
* Test Bootstrap for Optimiztaion Detective.
*
* @package optimization-detective
*/

// Load the test helpers.
require_once TESTS_REPO_ROOT_DIR . '/plugins/optimization-detective/tests/class-optimization-detective-test-helpers.php';
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Helper trait for Optimization Detective tests.
*
* @package performance-lab
* @package optimization-detective
*
* @noinspection PhpDocMissingThrowsInspection
* @noinspection PhpUnhandledExceptionInspection
Expand Down
2 changes: 1 addition & 1 deletion plugins/optimization-detective/tests/test-uninstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static function set_up_before_class(): void {
* Load uninstall.php.
*/
private function require_uninstall(): void {
require __DIR__ . '/../../../plugins/optimization-detective/uninstall.php';
require TESTS_PLUGIN_DIR . '/uninstall.php';
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static function set_up_before_class(): void {
* Load uninstall.php.
*/
private function require_uninstall(): void {
require __DIR__ . '/../../../plugins/speculation-rules/uninstall.php';
require TESTS_PLUGIN_DIR . '/uninstall.php';
}

/**
Expand Down
Binary file not shown.
Binary file added plugins/webp-uploads/tests/data/images/car.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
3 changes: 3 additions & 0 deletions tools/phpcs/phpcs.ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,15 @@
</rule>
<rule ref="WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents">
<exclude-pattern>tests/*</exclude-pattern>
<exclude-pattern>tools/phpunit/*</exclude-pattern>
</rule>
<rule ref="WordPress.Security.EscapeOutput.OutputNotEscaped">
<exclude-pattern>tests/*</exclude-pattern>
<exclude-pattern>tools/phpunit/*</exclude-pattern>
</rule>
<rule ref="WordPress.WP.AlternativeFunctions.unlink_unlink">
<exclude-pattern>tests/*</exclude-pattern>
<exclude-pattern>tools/phpunit/*</exclude-pattern>
</rule>
<rule ref="WordPress.WP.GlobalVariablesOverride.Prohibited">
<exclude-pattern>tests/*</exclude-pattern>
Expand Down
1 change: 1 addition & 0 deletions tools/phpstan/constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

define( 'TESTS_PLUGIN_DIR', './' );
define( 'TESTS_REPO_ROOT_DIR', './' );
define( 'WPINC', 'wp-includes' );

define( 'SPECULATION_RULES_VERSION', '0.0.0' );
Expand Down
27 changes: 13 additions & 14 deletions tests/bootstrap.php → tools/phpunit/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
* @package performance-lab
*/

define( 'TESTS_PLUGIN_DIR', dirname( __DIR__ ) );
define( 'TESTS_REPO_ROOT_DIR', dirname( __DIR__, 2 ) );

// 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 ) );
define( 'WP_PLUGIN_DIR', dirname( TESTS_REPO_ROOT_DIR ) );
}

// Load Composer dependencies if applicable.
if ( file_exists( TESTS_PLUGIN_DIR . '/vendor/autoload.php' ) ) {
require_once TESTS_PLUGIN_DIR . '/vendor/autoload.php';
if ( file_exists( TESTS_REPO_ROOT_DIR . '/vendor/autoload.php' ) ) {
require_once TESTS_REPO_ROOT_DIR . '/vendor/autoload.php';
}

// Detect where to load the WordPress tests environment from.
Expand All @@ -26,8 +26,8 @@
$_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';
} elseif ( file_exists( TESTS_REPO_ROOT_DIR . '/../../../../tests/phpunit/includes/functions.php' ) ) {
$_test_root = TESTS_REPO_ROOT_DIR . '/../../../../tests/phpunit';
} else { // Fallback.
$_test_root = '/tmp/wordpress-tests-lib';
}
Expand All @@ -47,7 +47,7 @@
if (
'--testsuite' === $arg &&
isset( $_SERVER['argv'][ $index + 1 ] ) &&
file_exists( TESTS_PLUGIN_DIR . '/plugins/' . $_SERVER['argv'][ $index + 1 ] )
file_exists( TESTS_REPO_ROOT_DIR . '/plugins/' . $_SERVER['argv'][ $index + 1 ] )
) {
$plugin_name = $_SERVER['argv'][ $index + 1 ];
}
Expand All @@ -58,13 +58,15 @@
$plugin_name = 'performance-lab';
}

define( 'TESTS_PLUGIN_DIR', TESTS_REPO_ROOT_DIR . "/plugins/$plugin_name" );

/**
* Load plugin bootstrap and any dependencies.
*
* @param string $plugin_name Plugin slug to load.
*/
$load_plugin = static function ( string $plugin_name ) use ( &$load_plugin ): void {
$plugin_test_path = TESTS_PLUGIN_DIR . '/plugins/' . $plugin_name;
$plugin_test_path = TESTS_REPO_ROOT_DIR . '/plugins/' . $plugin_name;
if ( file_exists( $plugin_test_path . '/' . $plugin_name . '.php' ) ) {
$plugin_file = $plugin_test_path . '/' . $plugin_name . '.php';
} elseif ( file_exists( $plugin_test_path . '/load.php' ) ) {
Expand Down Expand Up @@ -102,9 +104,9 @@ static function () use ( $load_plugin, $plugin_name ): void {
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';
require_once TESTS_REPO_ROOT_DIR . '/plugins/' . $plugin_name . '/includes/admin/load.php';
require_once TESTS_REPO_ROOT_DIR . '/plugins/' . $plugin_name . '/includes/admin/server-timing.php';
require_once TESTS_REPO_ROOT_DIR . '/plugins/' . $plugin_name . '/includes/admin/plugins.php';
},
1
);
Expand All @@ -127,8 +129,5 @@ static function ( bool $passthrough ): bool {
}
);

// Require helper classes.
require_once __DIR__ . '/class-optimization-detective-test-helpers.php';

// Start up the WP testing environment.
require $_test_root . '/includes/bootstrap.php';

0 comments on commit d94977f

Please sign in to comment.