diff --git a/package.json b/package.json index eed123e0b..61c504e6b 100644 --- a/package.json +++ b/package.json @@ -21,4 +21,4 @@ "test:js": "cd ../../wpps-scripts; sh test-js.sh $npm_package_wpps_options -p \"${OLDPWD}\";", "zip": "cd ../../wpps-scripts; sh zip.sh $npm_package_wpps_options -p \"${OLDPWD}\";" } -} +} \ No newline at end of file diff --git a/wp-modules/api-data/tests/ApiDataTest.php b/wp-modules/api-data/tests/ApiDataTest.php index afe95cf80..163d6a185 100644 --- a/wp-modules/api-data/tests/ApiDataTest.php +++ b/wp-modules/api-data/tests/ApiDataTest.php @@ -22,7 +22,7 @@ class ApiDataTest extends WP_UnitTestCase { /** * @inheritDoc */ - public function setUp() { + public function setUp() : void { parent::setUp(); add_filter( 'request_filesystem_credentials', '__return_true' ); add_filter( 'stylesheet_directory', [ $this, 'get_fixtures_directory' ] ); @@ -31,7 +31,7 @@ public function setUp() { /** * @inheritDoc */ - public function tearDown() { + public function tearDown() : void { unset( $GLOBALS['wp_rest_server'] ); remove_filter( 'request_filesystem_credentials', '__return_true' ); remove_filter( 'stylesheet_directory', [ $this, 'get_fixtures_directory' ] ); diff --git a/wp-modules/editor/tests/EditorTest.php b/wp-modules/editor/tests/EditorTest.php index 7ea22af1d..5dfe4bea9 100644 --- a/wp-modules/editor/tests/EditorTest.php +++ b/wp-modules/editor/tests/EditorTest.php @@ -38,12 +38,30 @@ public function test_register_pattern_post_type() { public function test_register_pattern_post_type_meta_types() { register_pattern_post_type(); - foreach ( array_diff( get_pattern_defaults(), [ 'title' => null ] ) as $meta_key => $default_value ) { - $expected_type = get_registered_meta_keys( 'post', 'pm_pattern' )[ $meta_key ]['type']; + $pattern_default_keys = get_pattern_defaults(); + $registered_keys = get_registered_meta_keys( 'post', 'pm_pattern' ); + + // Loop through each default key to make sure its type matches what was actually registered by WP. + foreach ( $pattern_default_keys as $meta_key => $default_value ) { + + // The title and content pattern defaults are not registered meta keys, so skip them. + if ( 'title' === $meta_key || 'content' === $meta_key ) { + continue; + } + + $expected_type = $registered_keys[ $meta_key ]['type']; + + // Fix the typing for numbers. + if ( 'number' === $expected_type ) { + $expected_type = 'integer'; + } + + $actual_type = gettype( $default_value ); + $this->assertSame( - 'number' === $expected_type ? 'integer' : $expected_type, - gettype( $default_value ), - "the type of the default for {$meta_key} is wrong" + $expected_type, + $actual_type, + "The type of the default for {$meta_key} is wrong. It should be {$expected_type} but it was {$actual_type}" ); } } @@ -54,11 +72,23 @@ public function test_register_pattern_post_type_meta_types() { public function test_register_pattern_post_type_meta_defaults() { register_pattern_post_type(); - foreach ( array_diff( get_pattern_defaults(), [ 'title' => null ] ) as $meta_key => $default_value ) { + $pattern_default_keys = get_pattern_defaults(); + $registered_keys = get_registered_meta_keys( 'post', 'pm_pattern' ); + + // Loop through each default key to make sure its default value matches what was actually registered by WP. + foreach ( $pattern_default_keys as $meta_key => $default_value ) { + + // The title and content pattern defaults are not registered meta keys, so skip them. + if ( 'title' === $meta_key || 'content' === $meta_key ) { + continue; + } + + $actual_value = $registered_keys[ $meta_key ]['default']; + $this->assertSame( $default_value, - get_registered_meta_keys( 'post', 'pm_pattern' )[ $meta_key ]['default'], - "the default value of {$meta_key} is wrong" + $actual_value, + "The value of the default for {$meta_key} is wrong." ); } } diff --git a/wp-modules/editor/tests/UtilsTest.php b/wp-modules/editor/tests/UtilsTest.php index bef2f5f9a..a4dbc116e 100644 --- a/wp-modules/editor/tests/UtilsTest.php +++ b/wp-modules/editor/tests/UtilsTest.php @@ -19,7 +19,7 @@ class UtilsTest extends WP_UnitTestCase { /** * @inheritDoc */ - public function tearDown() { + public function tearDown() : void { delete_pattern_posts(); parent::tearDown(); } diff --git a/wp-modules/get-module-data/tests/GetModuleDataTest.php b/wp-modules/get-module-data/tests/PatternManagerGetModuleDataTest.php similarity index 94% rename from wp-modules/get-module-data/tests/GetModuleDataTest.php rename to wp-modules/get-module-data/tests/PatternManagerGetModuleDataTest.php index 47ddf2dfa..6a6882895 100644 --- a/wp-modules/get-module-data/tests/GetModuleDataTest.php +++ b/wp-modules/get-module-data/tests/PatternManagerGetModuleDataTest.php @@ -1,6 +1,6 @@ user_id = $this->factory->user->create(); @@ -33,7 +33,7 @@ public function setUp() { /** * @inheritDoc */ - public function tearDown() { + public function tearDown() : void { delete_user_meta( $this->user_id, get_version_control_meta_key() ); wp_delete_user( $this->user_id ); diff --git a/wp-modules/pattern-data-handlers/tests/PatternDataHandlersTest.php b/wp-modules/pattern-data-handlers/tests/PatternDataHandlersTest.php index 187b3e918..78badf51e 100644 --- a/wp-modules/pattern-data-handlers/tests/PatternDataHandlersTest.php +++ b/wp-modules/pattern-data-handlers/tests/PatternDataHandlersTest.php @@ -20,7 +20,7 @@ class PatternDataHandlersTest extends WP_UnitTestCase { /** * @inheritDoc */ - public function setUp() { + public function setUp() : void { parent::setUp(); add_filter( 'request_filesystem_credentials', '__return_true' ); add_filter( 'stylesheet_directory', [ $this, 'get_fixtures_directory' ] ); @@ -30,7 +30,7 @@ public function setUp() { /** * @inheritDoc */ - public function tearDown() { + public function tearDown() : void { remove_filter( 'request_filesystem_credentials', '__return_true' ); remove_filter( 'stylesheet_directory', [ $this, 'get_fixtures_directory' ] ); remove_filter( 'stylesheet_directory_uri', [ $this, 'get_stylesheet_directory_uri' ] );