diff --git a/composer.json b/composer.json index f12abd3f7d0..cf3cec1b3df 100644 --- a/composer.json +++ b/composer.json @@ -50,11 +50,10 @@ }, "autoload-dev": { "classmap": [ - "config/", - "tests/WP" + "config/" ], "psr-4": { - "Yoast\\WP\\SEO\\Tests\\Unit\\": "tests/Unit/" + "Yoast\\WP\\SEO\\Tests\\": "tests/" } }, "config": { @@ -84,7 +83,7 @@ "Yoast\\WP\\SEO\\Composer\\Actions::check_coding_standards" ], "check-cs-thresholds": [ - "@putenv YOASTCS_THRESHOLD_ERRORS=129", + "@putenv YOASTCS_THRESHOLD_ERRORS=127", "@putenv YOASTCS_THRESHOLD_WARNINGS=202", "Yoast\\WP\\SEO\\Composer\\Actions::check_cs_thresholds" ], diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 4b240fb9d5d..566a6392e4a 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -242,7 +242,7 @@ - /tests/Unit/* + /tests/* @@ -283,7 +283,7 @@ /config/*\.php$ /lib/*\.php$ /src/*\.php$ - /tests/Unit/*\.php$ + /tests/*\.php$ @@ -303,13 +303,13 @@ - /tests/Unit/*\.php$ + /tests/*\.php$ /tests/Unit/*\.php$ - /tests/Unit/*_*/*\.php$ + /tests/(Unit|WP)/*_*/*\.php$ /tests/*/bootstrap\.php$ diff --git a/phpunit-wp.xml.dist b/phpunit-wp.xml.dist index 37e440c9639..a155bbefe75 100644 --- a/phpunit-wp.xml.dist +++ b/phpunit-wp.xml.dist @@ -20,7 +20,7 @@ > - ./tests/WP + ./tests/WP diff --git a/tests/WP/Admin/test-class-admin-asset-dev-server-location.php b/tests/WP/Admin/Asset_Dev_Server_Location_Test.php similarity index 87% rename from tests/WP/Admin/test-class-admin-asset-dev-server-location.php rename to tests/WP/Admin/Asset_Dev_Server_Location_Test.php index 47d12fac6ff..1892d6fca08 100644 --- a/tests/WP/Admin/test-class-admin-asset-dev-server-location.php +++ b/tests/WP/Admin/Asset_Dev_Server_Location_Test.php @@ -1,16 +1,15 @@ getMockBuilder( 'WPSEO_Admin_Asset_Manager' ) + ->getMockBuilder( WPSEO_Admin_Asset_Manager::class ) ->setMethods( [ 'register_scripts', @@ -88,7 +87,7 @@ public function test_enqueue_script() { $class_instance->register_assets(); $class_instance->enqueue_script( 'post-edit' ); - $this->assertTrue( wp_script_is( WPSEO_Admin_Asset_Manager::PREFIX . 'post-edit', 'enqueued' ) ); + $this->assertTrue( \wp_script_is( WPSEO_Admin_Asset_Manager::PREFIX . 'post-edit', 'enqueued' ) ); } /** @@ -101,7 +100,7 @@ public function test_enqueue_style() { $class_instance->register_assets(); $class_instance->enqueue_style( 'metabox-css' ); - $this->assertTrue( wp_style_is( WPSEO_Admin_Asset_Manager::PREFIX . 'metabox-css', 'enqueued' ) ); + $this->assertTrue( \wp_style_is( WPSEO_Admin_Asset_Manager::PREFIX . 'metabox-css', 'enqueued' ) ); } /** @@ -114,7 +113,7 @@ public function test_wrong_enqueue_style() { $class_instance->register_assets(); $class_instance->enqueue_style( 'nonexisting' ); - $this->assertFalse( wp_style_is( WPSEO_Admin_Asset_Manager::PREFIX . 'nonexisting', 'enqueued' ) ); + $this->assertFalse( \wp_style_is( WPSEO_Admin_Asset_Manager::PREFIX . 'nonexisting', 'enqueued' ) ); } /** @@ -141,7 +140,7 @@ public function test_register_script() { $result = $wp_scripts->registered[ WPSEO_Admin_Asset_Manager::PREFIX . 'handle' ]; $this->assertEquals( WPSEO_Admin_Asset_Manager::PREFIX . 'handle', $result->handle ); - $this->assertEquals( 'http://' . WP_TESTS_DOMAIN . '/wp-content/plugins/wordpress-seo/js/dist/src.js', $result->src ); + $this->assertEquals( 'http://' . \WP_TESTS_DOMAIN . '/wp-content/plugins/wordpress-seo/js/dist/src.js', $result->src ); $this->assertEquals( [ 'deps' ], $result->deps ); $this->assertEquals( 'version', $result->ver ); $this->assertEquals( [ 'group' => 1 ], $result->extra ); @@ -193,7 +192,7 @@ public function test_register_style() { $result = $wp_styles->registered[ WPSEO_Admin_Asset_Manager::PREFIX . 'handle' ]; $this->assertEquals( WPSEO_Admin_Asset_Manager::PREFIX . 'handle', $result->handle ); - $this->assertEquals( 'http://' . WP_TESTS_DOMAIN . '/wp-content/plugins/wordpress-seo/css/dist/src.css', $result->src ); + $this->assertEquals( 'http://' . \WP_TESTS_DOMAIN . '/wp-content/plugins/wordpress-seo/css/dist/src.css', $result->src ); $this->assertEquals( [ 'deps' ], $result->deps ); $this->assertEquals( 'version', $result->ver ); $this->assertEquals( 'print', $result->args ); @@ -241,7 +240,7 @@ public function test_register_scripts() { ], ]; - $class_instance = $this->getMockBuilder( 'WPSEO_Admin_Asset_Manager' ) + $class_instance = $this->getMockBuilder( WPSEO_Admin_Asset_Manager::class ) ->setMethods( [ 'register_script' ] ) ->getMock(); @@ -276,7 +275,7 @@ public function test_register_styles() { ], ]; - $class_instance = $this->getMockBuilder( 'WPSEO_Admin_Asset_Manager' ) + $class_instance = $this->getMockBuilder( WPSEO_Admin_Asset_Manager::class ) ->setMethods( [ 'register_style' ] ) ->getMock(); @@ -298,7 +297,7 @@ public function test_register_styles() { */ public function test_register_assets() { - $class_instance = $this->getMockBuilder( 'WPSEO_Admin_Asset_Manager' ) + $class_instance = $this->getMockBuilder( WPSEO_Admin_Asset_Manager::class ) ->setMethods( [ 'register_scripts', 'register_styles' ] ) ->getMock(); diff --git a/tests/WP/Admin/test-class-admin-asset-seo-location.php b/tests/WP/Admin/Asset_SEO_Location_Test.php similarity index 66% rename from tests/WP/Admin/test-class-admin-asset-seo-location.php rename to tests/WP/Admin/Asset_SEO_Location_Test.php index c261a0aea4b..421110efd18 100644 --- a/tests/WP/Admin/test-class-admin-asset-seo-location.php +++ b/tests/WP/Admin/Asset_SEO_Location_Test.php @@ -1,16 +1,15 @@ get_url( $asset, WPSEO_Admin_Asset::TYPE_JS ); $actual_css = $location->get_url( $asset, WPSEO_Admin_Asset::TYPE_CSS ); diff --git a/tests/WP/test-class-admin-asset.php b/tests/WP/Admin/Asset_Test.php similarity index 95% rename from tests/WP/test-class-admin-asset.php rename to tests/WP/Admin/Asset_Test.php index c2950821206..1b340445287 100644 --- a/tests/WP/test-class-admin-asset.php +++ b/tests/WP/Admin/Asset_Test.php @@ -1,16 +1,15 @@ assertTrue( in_array( $proxy_table_name, $wpdb->tables, true ) ); + $this->assertTrue( \in_array( $proxy_table_name, $wpdb->tables, true ) ); } /** @@ -447,6 +445,6 @@ public function test_register_table_global() { $proxy_table_name = self::$proxy_table_name . '_duplicate'; - $this->assertTrue( in_array( $proxy_table_name, $wpdb->ms_global_tables, true ) ); + $this->assertTrue( \in_array( $proxy_table_name, $wpdb->ms_global_tables, true ) ); } } diff --git a/tests/WP/Admin/test-class-admin-editor-specific-replace-vars.php b/tests/WP/Admin/Editor_Specific_Replace_Vars_Test.php similarity index 95% rename from tests/WP/Admin/test-class-admin-editor-specific-replace-vars.php rename to tests/WP/Admin/Editor_Specific_Replace_Vars_Test.php index 010bd1336fc..1e60d05338b 100644 --- a/tests/WP/Admin/test-class-admin-editor-specific-replace-vars.php +++ b/tests/WP/Admin/Editor_Specific_Replace_Vars_Test.php @@ -1,17 +1,15 @@ getMockBuilder( 'WPSEO_Admin_Editor_Specific_Replace_Vars' ) + ->getMockBuilder( WPSEO_Admin_Editor_Specific_Replace_Vars::class ) ->setMethods( [ 'has_for_page_type' ] ) ->getMock(); @@ -294,7 +292,7 @@ private function create_and_get_with_post_type( $post_type = 'post' ) { * @covers WPSEO_Admin_Editor_Specific_Replace_Vars::get */ public function test_editor_specific_replacement_variables_filter() { - add_filter( 'wpseo_editor_specific_replace_vars', [ $this, 'filter_editor_specific_replacement_variables' ] ); + \add_filter( 'wpseo_editor_specific_replace_vars', [ $this, 'filter_editor_specific_replacement_variables' ] ); $expected_replacement_variables = [ 'page' => [ 'pt_single', 'pt_plural', 'parent_title' ], @@ -313,7 +311,7 @@ public function test_editor_specific_replacement_variables_filter() { $this->class_instance->get() ); - remove_filter( 'wpseo_editor_specific_replace_vars', [ $this, 'filter_editor_specific_replacement_variables' ] ); + \remove_filter( 'wpseo_editor_specific_replace_vars', [ $this, 'filter_editor_specific_replacement_variables' ] ); } /** @@ -322,7 +320,7 @@ public function test_editor_specific_replacement_variables_filter() { * @covers WPSEO_Admin_Editor_Specific_Replace_Vars::get */ public function test_editor_specific_replacement_variables_filter_with_wrong_return_value() { - add_filter( 'wpseo_editor_specific_replace_vars', '__return_false' ); + \add_filter( 'wpseo_editor_specific_replace_vars', '__return_false' ); $expected_replacement_variables = [ // Posts types. @@ -342,7 +340,7 @@ public function test_editor_specific_replacement_variables_filter_with_wrong_ret $this->class_instance->get() ); - remove_filter( 'wpseo_editor_specific_replace_vars', '__return_false' ); + \remove_filter( 'wpseo_editor_specific_replace_vars', '__return_false' ); } /** diff --git a/tests/WP/Admin/Exceptions/test-file-size-exception.php b/tests/WP/Admin/Exceptions/File_Size_Exception_Test.php similarity index 87% rename from tests/WP/Admin/Exceptions/test-file-size-exception.php rename to tests/WP/Admin/Exceptions/File_Size_Exception_Test.php index 93f96c392b7..341fe899bf2 100644 --- a/tests/WP/Admin/Exceptions/test-file-size-exception.php +++ b/tests/WP/Admin/Exceptions/File_Size_Exception_Test.php @@ -1,16 +1,14 @@ assertContains( 'WPSEO_Import_AIOSEO', WPSEO_Plugin_Importers::get() ); + $this->assertContains( WPSEO_Import_AIOSEO::class, WPSEO_Plugin_Importers::get() ); } /** @@ -93,12 +95,12 @@ public function test_import_with_data() { $post_id = $this->setup_post(); $result = $this->class_instance->run_import(); - $seo_title = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'title', true ); - $seo_desc = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'metadesc', true ); - $robots_noindex = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', true ); - $robots_nofollow = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-nofollow', true ); - $opengraph_image = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'opengraph-image', true ); - $opengraph_title = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'opengraph-title', true ); + $seo_title = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'title', true ); + $seo_desc = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'metadesc', true ); + $robots_noindex = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', true ); + $robots_nofollow = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-nofollow', true ); + $opengraph_image = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'opengraph-image', true ); + $opengraph_title = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'opengraph-title', true ); $this->assertEquals( 'Test title', $seo_title ); $this->assertEquals( 'Test description', $seo_desc ); @@ -125,8 +127,8 @@ public function test_import_without_rights_to_temp_table() { // Save for later return. $original_wpdb = $wpdb; - $wpdb = $this->getMockBuilder( 'wpdb' ) - ->setConstructorArgs( [ DB_USER, DB_PASSWORD, DB_NAME, DB_HOST ] ) + $wpdb = $this->getMockBuilder( wpdb::class ) + ->setConstructorArgs( [ \DB_USER, \DB_PASSWORD, \DB_NAME, \DB_HOST ] ) ->setMethods( [ 'query' ] ) ->getMock(); $wpdb->expects( $this->any() ) @@ -157,12 +159,12 @@ public function test_import_without_overwriting_data() { $post_id = $this->setup_post( true ); $result = $this->class_instance->run_import(); - $seo_title = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'title', true ); - $seo_desc = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'metadesc', true ); - $robots_noindex = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', true ); - $robots_nofollow = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-nofollow', true ); - $opengraph_image = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'opengraph-image', true ); - $opengraph_title = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'opengraph-title', true ); + $seo_title = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'title', true ); + $seo_desc = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'metadesc', true ); + $robots_noindex = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', true ); + $robots_nofollow = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-nofollow', true ); + $opengraph_image = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'opengraph-image', true ); + $opengraph_title = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'opengraph-title', true ); $this->assertEquals( 'Test title', $seo_title ); $this->assertEquals( 'Existing Yoast SEO Test description', $seo_desc ); @@ -193,8 +195,8 @@ public function test_cleanup() { $post_id = $this->setup_post(); $result = $this->class_instance->run_cleanup(); - $seo_title = get_post_meta( $post_id, '_aioseop_title', true ); - $seo_desc = get_post_meta( $post_id, '_aioseop_description', true ); + $seo_title = \get_post_meta( $post_id, '_aioseop_title', true ); + $seo_desc = \get_post_meta( $post_id, '_aioseop_description', true ); $this->assertEquals( $seo_title, false ); $this->assertEquals( $seo_desc, false ); @@ -215,8 +217,8 @@ public function test_cleanup_gone_bad() { global $wpdb; $original_wpdb = $wpdb; - $wpdb = $this->getMockBuilder( 'wpdb' ) - ->setConstructorArgs( [ DB_USER, DB_PASSWORD, DB_NAME, DB_HOST ] ) + $wpdb = $this->getMockBuilder( wpdb::class ) + ->setConstructorArgs( [ \DB_USER, \DB_PASSWORD, \DB_NAME, \DB_HOST ] ) ->setMethods( [ 'query' ] ) ->getMock(); $wpdb->expects( $this->any() ) @@ -252,16 +254,16 @@ private function status( $action, $status ) { */ private function setup_post( $pre_existing_yoast_data = false ) { $post_id = $this->factory()->post->create(); - update_post_meta( $post_id, '_aioseop_title', 'Test title' ); - update_post_meta( $post_id, '_aioseop_description', 'Test description' ); - update_post_meta( $post_id, '_aioseop_noindex', 'on' ); - update_post_meta( $post_id, '_aioseop_nofollow', 'on' ); - update_post_meta( $post_id, '_aioseop_opengraph_settings', 'a:15:{s:32:"aioseop_opengraph_settings_title";s:22:"OpenGraph AIOSEO title";s:31:"aioseop_opengraph_settings_desc";s:28:"OpenGraph AIOSEO description";s:36:"aioseop_opengraph_settings_customimg";s:73:"http://local.wordpress.test/wp-content/uploads/2018/01/actionable-seo.png";s:37:"aioseop_opengraph_settings_imagewidth";s:0:"";s:38:"aioseop_opengraph_settings_imageheight";s:0:"";s:32:"aioseop_opengraph_settings_video";s:0:"";s:37:"aioseop_opengraph_settings_videowidth";s:0:"";s:38:"aioseop_opengraph_settings_videoheight";s:0:"";s:35:"aioseop_opengraph_settings_category";s:8:"activity";s:34:"aioseop_opengraph_settings_section";s:0:"";s:30:"aioseop_opengraph_settings_tag";s:0:"";s:34:"aioseop_opengraph_settings_setcard";s:7:"summary";s:44:"aioseop_opengraph_settings_customimg_twitter";s:73:"http://local.wordpress.test/wp-content/uploads/2018/01/actionable-seo.png";s:44:"aioseop_opengraph_settings_customimg_checker";s:1:"1";s:32:"aioseop_opengraph_settings_image";s:73:"http://local.wordpress.test/wp-content/uploads/2018/01/actionable-seo.png";}' ); + \update_post_meta( $post_id, '_aioseop_title', 'Test title' ); + \update_post_meta( $post_id, '_aioseop_description', 'Test description' ); + \update_post_meta( $post_id, '_aioseop_noindex', 'on' ); + \update_post_meta( $post_id, '_aioseop_nofollow', 'on' ); + \update_post_meta( $post_id, '_aioseop_opengraph_settings', 'a:15:{s:32:"aioseop_opengraph_settings_title";s:22:"OpenGraph AIOSEO title";s:31:"aioseop_opengraph_settings_desc";s:28:"OpenGraph AIOSEO description";s:36:"aioseop_opengraph_settings_customimg";s:73:"http://local.wordpress.test/wp-content/uploads/2018/01/actionable-seo.png";s:37:"aioseop_opengraph_settings_imagewidth";s:0:"";s:38:"aioseop_opengraph_settings_imageheight";s:0:"";s:32:"aioseop_opengraph_settings_video";s:0:"";s:37:"aioseop_opengraph_settings_videowidth";s:0:"";s:38:"aioseop_opengraph_settings_videoheight";s:0:"";s:35:"aioseop_opengraph_settings_category";s:8:"activity";s:34:"aioseop_opengraph_settings_section";s:0:"";s:30:"aioseop_opengraph_settings_tag";s:0:"";s:34:"aioseop_opengraph_settings_setcard";s:7:"summary";s:44:"aioseop_opengraph_settings_customimg_twitter";s:73:"http://local.wordpress.test/wp-content/uploads/2018/01/actionable-seo.png";s:44:"aioseop_opengraph_settings_customimg_checker";s:1:"1";s:32:"aioseop_opengraph_settings_image";s:73:"http://local.wordpress.test/wp-content/uploads/2018/01/actionable-seo.png";}' ); if ( $pre_existing_yoast_data ) { - update_post_meta( $post_id, '_yoast_wpseo_metadesc', 'Existing Yoast SEO Test description' ); - update_post_meta( $post_id, '_yoast_wpseo_meta-robots-noindex', 0 ); - update_post_meta( $post_id, '_yoast_wpseo_opengraph-title', 'Pre-existing Yoast SEO test OpenGraph title' ); + \update_post_meta( $post_id, '_yoast_wpseo_metadesc', 'Existing Yoast SEO Test description' ); + \update_post_meta( $post_id, '_yoast_wpseo_meta-robots-noindex', 0 ); + \update_post_meta( $post_id, '_yoast_wpseo_opengraph-title', 'Pre-existing Yoast SEO test OpenGraph title' ); } return $post_id; } diff --git a/tests/WP/Admin/Import/test-class-import-greg-high-performance-seo.php b/tests/WP/Admin/Import/Greg_SEO_Test.php similarity index 82% rename from tests/WP/Admin/Import/test-class-import-greg-high-performance-seo.php rename to tests/WP/Admin/Import/Greg_SEO_Test.php index 0683c0b6370..6b7416e22d1 100644 --- a/tests/WP/Admin/Import/test-class-import-greg-high-performance-seo.php +++ b/tests/WP/Admin/Import/Greg_SEO_Test.php @@ -1,16 +1,17 @@ assertContains( 'WPSEO_Import_Greg_SEO', WPSEO_Plugin_Importers::get() ); + $this->assertContains( WPSEO_Import_Greg_SEO::class, WPSEO_Plugin_Importers::get() ); } /** @@ -89,8 +90,8 @@ public function test_import() { $post_id = $this->setup_post(); $result = $this->class_instance->run_import(); - $seo_title = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'title', true ); - $seo_desc = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'metadesc', true ); + $seo_title = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'title', true ); + $seo_desc = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'metadesc', true ); $this->assertEquals( $seo_title, 'Test title' ); $this->assertEquals( $seo_desc, 'Test description' ); @@ -116,8 +117,8 @@ public function test_cleanup() { $post_id = $this->setup_post(); $result = $this->class_instance->run_cleanup(); - $seo_title = get_post_meta( $post_id, '_su_title', true ); - $seo_desc = get_post_meta( $post_id, '_su_description', true ); + $seo_title = \get_post_meta( $post_id, '_su_title', true ); + $seo_desc = \get_post_meta( $post_id, '_su_description', true ); $this->assertEquals( $seo_title, false ); $this->assertEquals( $seo_desc, false ); @@ -143,8 +144,8 @@ private function status( $action, $status ) { */ private function setup_post() { $post_id = $this->factory()->post->create(); - update_post_meta( $post_id, '_ghpseo_secondary_title', 'Test title' ); - update_post_meta( $post_id, '_ghpseo_alternative_description', 'Test description' ); + \update_post_meta( $post_id, '_ghpseo_secondary_title', 'Test title' ); + \update_post_meta( $post_id, '_ghpseo_alternative_description', 'Test description' ); return $post_id; } diff --git a/tests/WP/Admin/Import/test-class-import-headspace.php b/tests/WP/Admin/Import/HeadSpace_Test.php similarity index 82% rename from tests/WP/Admin/Import/test-class-import-headspace.php rename to tests/WP/Admin/Import/HeadSpace_Test.php index bd18825c10a..d723156a7ab 100644 --- a/tests/WP/Admin/Import/test-class-import-headspace.php +++ b/tests/WP/Admin/Import/HeadSpace_Test.php @@ -1,16 +1,17 @@ assertContains( 'WPSEO_Import_HeadSpace', WPSEO_Plugin_Importers::get() ); + $this->assertContains( WPSEO_Import_HeadSpace::class, WPSEO_Plugin_Importers::get() ); } /** @@ -90,8 +91,8 @@ public function test_import_with_data() { $post_id = $this->setup_post(); $result = $this->class_instance->run_import(); - $seo_title = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'title', true ); - $seo_desc = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'metadesc', true ); + $seo_title = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'title', true ); + $seo_desc = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'metadesc', true ); $this->assertEquals( $seo_title, 'Test title' ); $this->assertEquals( $seo_desc, 'Test description' ); @@ -118,8 +119,8 @@ public function test_cleanup() { $post_id = $this->setup_post(); $result = $this->class_instance->run_cleanup(); - $seo_title = get_post_meta( $post_id, '_headspace_page_title', true ); - $seo_desc = get_post_meta( $post_id, '_headspace_description', true ); + $seo_title = \get_post_meta( $post_id, '_headspace_page_title', true ); + $seo_desc = \get_post_meta( $post_id, '_headspace_description', true ); $this->assertEquals( $seo_title, false ); $this->assertEquals( $seo_desc, false ); @@ -145,8 +146,8 @@ private function status( $action, $status ) { */ private function setup_post() { $post_id = $this->factory()->post->create(); - update_post_meta( $post_id, '_headspace_page_title', 'Test title' ); - update_post_meta( $post_id, '_headspace_description', 'Test description' ); + \update_post_meta( $post_id, '_headspace_page_title', 'Test title' ); + \update_post_meta( $post_id, '_headspace_description', 'Test description' ); return $post_id; } diff --git a/tests/WP/Admin/Import/test-class-import-jetpack.php b/tests/WP/Admin/Import/Jetpack_SEO_Test.php similarity index 86% rename from tests/WP/Admin/Import/test-class-import-jetpack.php rename to tests/WP/Admin/Import/Jetpack_SEO_Test.php index bee54b58731..9c9337c61f4 100644 --- a/tests/WP/Admin/Import/test-class-import-jetpack.php +++ b/tests/WP/Admin/Import/Jetpack_SEO_Test.php @@ -1,16 +1,17 @@ assertContains( 'WPSEO_Import_Jetpack_SEO', WPSEO_Plugin_Importers::get() ); + $this->assertContains( WPSEO_Import_Jetpack_SEO::class, WPSEO_Plugin_Importers::get() ); } /** @@ -89,7 +90,7 @@ public function test_import() { $post_id = $this->setup_post(); $result = $this->class_instance->run_import(); - $seo_desc = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'metadesc', true ); + $seo_desc = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'metadesc', true ); $this->assertEquals( $seo_desc, 'Test description' ); $this->assertEquals( $this->status( 'import', true ), $result ); @@ -115,7 +116,7 @@ public function test_cleanup() { $post_id = $this->setup_post(); $result = $this->class_instance->run_cleanup(); - $seo_desc = get_post_meta( $post_id, 'advanced_seo_description', true ); + $seo_desc = \get_post_meta( $post_id, 'advanced_seo_description', true ); $this->assertEquals( $seo_desc, false ); $this->assertEquals( $this->status( 'cleanup', true ), $result ); @@ -140,7 +141,7 @@ private function status( $action, $status ) { */ private function setup_post() { $post_id = $this->factory()->post->create(); - update_post_meta( $post_id, 'advanced_seo_description', 'Test description' ); + \update_post_meta( $post_id, 'advanced_seo_description', 'Test description' ); return $post_id; } diff --git a/tests/WP/Admin/Import/test-class-import-platinum-seo-pack.php b/tests/WP/Admin/Import/Platinum_SEO_Test.php similarity index 79% rename from tests/WP/Admin/Import/test-class-import-platinum-seo-pack.php rename to tests/WP/Admin/Import/Platinum_SEO_Test.php index da20d5664d5..ddadd842614 100644 --- a/tests/WP/Admin/Import/test-class-import-platinum-seo-pack.php +++ b/tests/WP/Admin/Import/Platinum_SEO_Test.php @@ -1,16 +1,17 @@ assertContains( 'WPSEO_Import_Platinum_SEO', WPSEO_Plugin_Importers::get() ); + $this->assertContains( WPSEO_Import_Platinum_SEO::class, WPSEO_Plugin_Importers::get() ); } /** @@ -92,10 +93,10 @@ public function test_import() { $post_id = $this->setup_post(); $result = $this->class_instance->run_import(); - $seo_title = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'title', true ); - $seo_desc = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'metadesc', true ); - $robots_noindex = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', true ); - $robots_nofollow = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-nofollow', true ); + $seo_title = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'title', true ); + $seo_desc = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'metadesc', true ); + $robots_noindex = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', true ); + $robots_nofollow = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-nofollow', true ); $this->assertEquals( 'Test title', $seo_title ); $this->assertEquals( 'Test description', $seo_desc ); @@ -123,8 +124,8 @@ public function test_cleanup() { $post_id = $this->setup_post(); $result = $this->class_instance->run_cleanup(); - $seo_title = get_post_meta( $post_id, 'title', true ); - $seo_desc = get_post_meta( $post_id, 'description', true ); + $seo_title = \get_post_meta( $post_id, 'title', true ); + $seo_desc = \get_post_meta( $post_id, 'description', true ); $this->assertEquals( $seo_title, false ); $this->assertEquals( $seo_desc, false ); @@ -150,9 +151,9 @@ private function status( $action, $status ) { */ private function setup_post() { $post_id = $this->factory()->post->create(); - update_post_meta( $post_id, 'title', 'Test title' ); - update_post_meta( $post_id, 'description', 'Test description' ); - update_post_meta( $post_id, 'robotsmeta', 'noindex,nofollow' ); + \update_post_meta( $post_id, 'title', 'Test title' ); + \update_post_meta( $post_id, 'description', 'Test description' ); + \update_post_meta( $post_id, 'robotsmeta', 'noindex,nofollow' ); return $post_id; } diff --git a/tests/WP/Admin/Import/test-class-importers.php b/tests/WP/Admin/Import/Plugin_Importers_Test.php similarity index 69% rename from tests/WP/Admin/Import/test-class-importers.php rename to tests/WP/Admin/Import/Plugin_Importers_Test.php index ae9f5419a68..7cafcf34c5e 100644 --- a/tests/WP/Admin/Import/test-class-importers.php +++ b/tests/WP/Admin/Import/Plugin_Importers_Test.php @@ -1,16 +1,14 @@ factory()->post->create(); - update_post_meta( $post_id, '_aioseop_title', 'Test title' ); - update_post_meta( $post_id, '_aioseop_description', 'Test description' ); + \update_post_meta( $post_id, '_aioseop_title', 'Test title' ); + \update_post_meta( $post_id, '_aioseop_description', 'Test description' ); return $post_id; } diff --git a/tests/WP/Admin/Import/test-class-import-detector.php b/tests/WP/Admin/Import/Plugins_Detector_Test.php similarity index 76% rename from tests/WP/Admin/Import/test-class-import-detector.php rename to tests/WP/Admin/Import/Plugins_Detector_Test.php index 96279ac3d5d..f08498ca7d2 100644 --- a/tests/WP/Admin/Import/test-class-import-detector.php +++ b/tests/WP/Admin/Import/Plugins_Detector_Test.php @@ -1,16 +1,14 @@ factory()->post->create(); - update_post_meta( $post_id, '_aioseop_title', 'Test title' ); - update_post_meta( $post_id, '_aioseop_description', 'Test description' ); + \update_post_meta( $post_id, '_aioseop_title', 'Test title' ); + \update_post_meta( $post_id, '_aioseop_description', 'Test description' ); return $post_id; } diff --git a/tests/WP/Admin/Import/test-class-import-premium-seo-pack.php b/tests/WP/Admin/Import/Premium_SEO_Pack_Test.php similarity index 81% rename from tests/WP/Admin/Import/test-class-import-premium-seo-pack.php rename to tests/WP/Admin/Import/Premium_SEO_Pack_Test.php index 6360b5487c4..a95287de907 100644 --- a/tests/WP/Admin/Import/test-class-import-premium-seo-pack.php +++ b/tests/WP/Admin/Import/Premium_SEO_Pack_Test.php @@ -1,16 +1,18 @@ class_instance->run_cleanup(); - add_filter( 'query', [ $this, '_create_temporary_tables' ] ); - add_filter( 'query', [ $this, '_drop_temporary_tables' ] ); + \add_filter( 'query', [ $this, '_create_temporary_tables' ] ); + \add_filter( 'query', [ $this, '_drop_temporary_tables' ] ); parent::tear_down(); } @@ -54,7 +56,7 @@ public function test_plugin_name() { * @covers WPSEO_Plugin_Importers::get */ public function test_importer_registered() { - $this->assertContains( 'WPSEO_Import_Premium_SEO_Pack', WPSEO_Plugin_Importers::get() ); + $this->assertContains( WPSEO_Import_Premium_SEO_Pack::class, WPSEO_Plugin_Importers::get() ); } /** @@ -107,13 +109,13 @@ public function test_import_with_data() { $post_id = $this->setup_post(); $result = $this->class_instance->run_import(); - $seo_title = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'title', true ); - $seo_desc = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'metadesc', true ); - $robots_noindex = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', true ); - $robots_nofollow = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-nofollow', true ); - $opengraph_image = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'opengraph-image', true ); - $opengraph_title = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'opengraph-title', true ); - $cornerstone = get_post_meta( $post_id, '_yst_is_cornerstone', true ); + $seo_title = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'title', true ); + $seo_desc = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'metadesc', true ); + $robots_noindex = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', true ); + $robots_nofollow = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-nofollow', true ); + $opengraph_image = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'opengraph-image', true ); + $opengraph_title = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'opengraph-title', true ); + $cornerstone = \get_post_meta( $post_id, '_yst_is_cornerstone', true ); $this->assertEquals( 'Test title', $seo_title ); $this->assertEquals( 'Test description', $seo_desc ); @@ -139,12 +141,12 @@ public function test_import_without_overwriting_data() { $post_id = $this->setup_post( true ); $result = $this->class_instance->run_import(); - $seo_title = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'title', true ); - $seo_desc = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'metadesc', true ); - $robots_noindex = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', true ); - $robots_nofollow = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-nofollow', true ); - $opengraph_image = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'opengraph-image', true ); - $opengraph_title = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'opengraph-title', true ); + $seo_title = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'title', true ); + $seo_desc = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'metadesc', true ); + $robots_noindex = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', true ); + $robots_nofollow = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-nofollow', true ); + $opengraph_image = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'opengraph-image', true ); + $opengraph_title = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'opengraph-title', true ); $this->assertEquals( 'Test title', $seo_title ); $this->assertEquals( 'Existing Yoast SEO Test description', $seo_desc ); @@ -220,8 +222,8 @@ public function test_cleanup_gone_bad() { global $wpdb; $original_wpdb = $wpdb; - $wpdb = $this->getMockBuilder( 'wpdb' ) - ->setConstructorArgs( [ DB_USER, DB_PASSWORD, DB_NAME, DB_HOST ] ) + $wpdb = $this->getMockBuilder( wpdb::class ) + ->setConstructorArgs( [ \DB_USER, \DB_PASSWORD, \DB_NAME, \DB_HOST ] ) ->setMethods( [ 'query', 'get_var' ] ) ->getMock(); $wpdb->expects( $this->any() ) @@ -278,9 +280,9 @@ private function setup_post( $pre_existing_yoast_data = false ) { $this->insert_post( $post_id, $blob ); if ( $pre_existing_yoast_data ) { - update_post_meta( $post_id, '_yoast_wpseo_metadesc', 'Existing Yoast SEO Test description' ); - update_post_meta( $post_id, '_yoast_wpseo_meta-robots-noindex', 0 ); - update_post_meta( $post_id, '_yoast_wpseo_opengraph-title', 'Pre-existing Yoast SEO test OpenGraph title' ); + \update_post_meta( $post_id, '_yoast_wpseo_metadesc', 'Existing Yoast SEO Test description' ); + \update_post_meta( $post_id, '_yoast_wpseo_meta-robots-noindex', 0 ); + \update_post_meta( $post_id, '_yoast_wpseo_opengraph-title', 'Pre-existing Yoast SEO test OpenGraph title' ); } return $post_id; @@ -294,7 +296,7 @@ private function setup_post( $pre_existing_yoast_data = false ) { * @return array Complete array */ private function build_data_blob( $data = [] ) { - return array_merge( + return \array_merge( [ 'doseo' => 1, 'noindex' => 0, @@ -342,11 +344,11 @@ private function insert_post( $post_id, $blob ) { %s, %s );', - get_current_blog_id(), + \get_current_blog_id(), $post_id, - get_permalink( $post_id ), - md5( get_permalink( $post_id ) ), - serialize( $blob ) + \get_permalink( $post_id ), + \md5( \get_permalink( $post_id ) ), + \serialize( $blob ) ) ); } @@ -356,7 +358,7 @@ private function insert_post( $post_id, $blob ) { */ private function create_table() { // We need to test creating and dropping tables, so we can't have this. - remove_all_filters( 'query' ); + \remove_all_filters( 'query' ); global $wpdb; $wpdb->query( diff --git a/tests/WP/Admin/Import/test-class-import-rankmath.php b/tests/WP/Admin/Import/RankMath_Test.php similarity index 75% rename from tests/WP/Admin/Import/test-class-import-rankmath.php rename to tests/WP/Admin/Import/RankMath_Test.php index 015e14c0641..363bd47d813 100644 --- a/tests/WP/Admin/Import/test-class-import-rankmath.php +++ b/tests/WP/Admin/Import/RankMath_Test.php @@ -1,16 +1,18 @@ assertContains( 'WPSEO_Import_RankMath', WPSEO_Plugin_Importers::get() ); + $this->assertContains( WPSEO_Import_RankMath::class, WPSEO_Plugin_Importers::get() ); } /** @@ -91,12 +93,12 @@ public function test_import() { $this->setup_options(); $result = $this->class_instance->run_import(); - $seo_title = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'title', true ); - $seo_desc = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'metadesc', true ); - $robots_noindex = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', true ); - $robots_nofollow = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-nofollow', true ); - $twitter_title = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'twitter-title', true ); - $twitter_desc = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'twitter-description', true ); + $seo_title = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'title', true ); + $seo_desc = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'metadesc', true ); + $robots_noindex = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', true ); + $robots_nofollow = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-nofollow', true ); + $twitter_title = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'twitter-title', true ); + $twitter_desc = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'twitter-description', true ); $homepage_title = WPSEO_Options::get( 'title-home-wpseo' ); $homepage_desc = WPSEO_Options::get( 'metadesc-home-wpseo' ); @@ -134,10 +136,10 @@ public function test_cleanup() { $post_id = $this->setup_post(); $result = $this->class_instance->run_cleanup(); - $seo_title = get_post_meta( $post_id, 'rank_math_title', true ); - $seo_desc = get_post_meta( $post_id, 'rank_math_description', true ); + $seo_title = \get_post_meta( $post_id, 'rank_math_title', true ); + $seo_desc = \get_post_meta( $post_id, 'rank_math_description', true ); - $title_option = get_option( 'rank-math-options-titles' ); + $title_option = \get_option( 'rank-math-options-titles' ); $this->assertEquals( $title_option, false ); $this->assertEquals( $seo_title, false ); @@ -165,11 +167,11 @@ private function status( $action, $status ) { */ private function setup_post() { $post_id = $this->factory()->post->create(); - update_post_meta( $post_id, 'rank_math_title', 'Test title' ); - update_post_meta( $post_id, 'rank_math_description', 'Test description' ); - update_post_meta( $post_id, 'rank_math_robots', [ 'noindex', 'nofollow' ] ); - update_post_meta( $post_id, 'rank_math_twitter_title', 'Test Twitter title' ); - update_post_meta( $post_id, 'rank_math_twitter_description', 'Test Twitter description' ); + \update_post_meta( $post_id, 'rank_math_title', 'Test title' ); + \update_post_meta( $post_id, 'rank_math_description', 'Test description' ); + \update_post_meta( $post_id, 'rank_math_robots', [ 'noindex', 'nofollow' ] ); + \update_post_meta( $post_id, 'rank_math_twitter_title', 'Test Twitter title' ); + \update_post_meta( $post_id, 'rank_math_twitter_description', 'Test Twitter description' ); return $post_id; } @@ -178,7 +180,7 @@ private function setup_post() { * Sets up a fake RankMath settings array. */ private function setup_options() { - update_option( + \update_option( 'rank-math-options-titles', [ 'homepage_title' => 'Test homepage title', diff --git a/tests/WP/Admin/Import/test-class-import-seopressor.php b/tests/WP/Admin/Import/SEOPressor_Test.php similarity index 76% rename from tests/WP/Admin/Import/test-class-import-seopressor.php rename to tests/WP/Admin/Import/SEOPressor_Test.php index 84d4e3d9003..20efd2b5cd8 100644 --- a/tests/WP/Admin/Import/test-class-import-seopressor.php +++ b/tests/WP/Admin/Import/SEOPressor_Test.php @@ -1,16 +1,17 @@ assertContains( 'WPSEO_Import_SEOPressor', WPSEO_Plugin_Importers::get() ); + $this->assertContains( WPSEO_Import_SEOPressor::class, WPSEO_Plugin_Importers::get() ); } /** @@ -92,12 +93,12 @@ public function test_import() { $post_id = $this->setup_post(); $result = $this->class_instance->run_import(); - $seo_title = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'title', true ); - $seo_desc = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'metadesc', true ); - $robots_noindex = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', true ); - $robots_nofollow = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-nofollow', true ); - $focus_kw = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'focuskw', true ); - $extra_focus_kw = json_decode( get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'focuskeywords', true ) ); + $seo_title = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'title', true ); + $seo_desc = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'metadesc', true ); + $robots_noindex = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', true ); + $robots_nofollow = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-nofollow', true ); + $focus_kw = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'focuskw', true ); + $extra_focus_kw = \json_decode( \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'focuskeywords', true ) ); $this->assertEquals( 'Test title', $seo_title ); $this->assertEquals( 'Test description', $seo_desc ); @@ -127,7 +128,7 @@ public function test_cleanup() { $post_id = $this->setup_post(); $result = $this->class_instance->run_cleanup(); - $seo_options = get_post_meta( $post_id, '_seop_settings', true ); + $seo_options = \get_post_meta( $post_id, '_seop_settings', true ); $this->assertEquals( $seo_options, false ); $this->assertEquals( $this->status( 'cleanup', true ), $result ); @@ -157,10 +158,10 @@ private function setup_post() { 'meta_description' => 'Test description', 'meta_rules' => 'noindex#|#|#nofollow', ]; - update_post_meta( $post_id, '_seop_settings', $settings ); - update_post_meta( $post_id, '_seop_kw_1', 'Test focus kw' ); - update_post_meta( $post_id, '_seop_kw_2', 'Test focus kw 2' ); - update_post_meta( $post_id, '_seop_kw_3', 'Test focus kw 3' ); + \update_post_meta( $post_id, '_seop_settings', $settings ); + \update_post_meta( $post_id, '_seop_kw_1', 'Test focus kw' ); + \update_post_meta( $post_id, '_seop_kw_2', 'Test focus kw 2' ); + \update_post_meta( $post_id, '_seop_kw_3', 'Test focus kw 3' ); return $post_id; } diff --git a/tests/WP/Admin/Import/test-class-import-seo-framework.php b/tests/WP/Admin/Import/SEO_Framework_Test.php similarity index 72% rename from tests/WP/Admin/Import/test-class-import-seo-framework.php rename to tests/WP/Admin/Import/SEO_Framework_Test.php index 03ee0828bed..440c4c02950 100644 --- a/tests/WP/Admin/Import/test-class-import-seo-framework.php +++ b/tests/WP/Admin/Import/SEO_Framework_Test.php @@ -1,16 +1,17 @@ assertContains( 'WPSEO_Import_SEO_Framework', WPSEO_Plugin_Importers::get() ); + $this->assertContains( WPSEO_Import_SEO_Framework::class, WPSEO_Plugin_Importers::get() ); } /** @@ -89,12 +90,12 @@ public function test_import() { $post_id = $this->setup_post(); $result = $this->class_instance->run_import(); - $seo_title = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'title', true ); - $seo_desc = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'metadesc', true ); - $robots_noindex = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', true ); - $robots_nofollow = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-nofollow', true ); - $twitter_title = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'twitter-title', true ); - $twitter_desc = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'twitter-description', true ); + $seo_title = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'title', true ); + $seo_desc = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'metadesc', true ); + $robots_noindex = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', true ); + $robots_nofollow = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-nofollow', true ); + $twitter_title = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'twitter-title', true ); + $twitter_desc = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'twitter-description', true ); $this->assertEquals( 1, $robots_noindex ); $this->assertEquals( 1, $robots_nofollow ); @@ -124,8 +125,8 @@ public function test_cleanup() { $post_id = $this->setup_post(); $result = $this->class_instance->run_cleanup(); - $seo_title = get_post_meta( $post_id, '_su_title', true ); - $seo_desc = get_post_meta( $post_id, '_su_description', true ); + $seo_title = \get_post_meta( $post_id, '_su_title', true ); + $seo_desc = \get_post_meta( $post_id, '_su_description', true ); $this->assertEquals( $seo_title, false ); $this->assertEquals( $seo_desc, false ); @@ -152,12 +153,12 @@ private function status( $action, $status ) { */ private function setup_post() { $post_id = $this->factory()->post->create(); - update_post_meta( $post_id, '_genesis_title', 'Test title' ); - update_post_meta( $post_id, '_genesis_description', 'Test description' ); - update_post_meta( $post_id, '_genesis_noindex', 1 ); - update_post_meta( $post_id, '_genesis_nofollow', 1 ); - update_post_meta( $post_id, '_twitter_title', 'Test Twitter title' ); - update_post_meta( $post_id, '_twitter_description', 'Test Twitter description' ); + \update_post_meta( $post_id, '_genesis_title', 'Test title' ); + \update_post_meta( $post_id, '_genesis_description', 'Test description' ); + \update_post_meta( $post_id, '_genesis_noindex', 1 ); + \update_post_meta( $post_id, '_genesis_nofollow', 1 ); + \update_post_meta( $post_id, '_twitter_title', 'Test Twitter title' ); + \update_post_meta( $post_id, '_twitter_description', 'Test Twitter description' ); return $post_id; } diff --git a/tests/WP/Admin/Import/test-class-import-settings.php b/tests/WP/Admin/Import/Settings_Test.php similarity index 92% rename from tests/WP/Admin/Import/test-class-import-settings.php rename to tests/WP/Admin/Import/Settings_Test.php index cf4ea803869..d3ad472bdb3 100644 --- a/tests/WP/Admin/Import/test-class-import-settings.php +++ b/tests/WP/Admin/Import/Settings_Test.php @@ -1,10 +1,8 @@ assertContains( 'WPSEO_Import_Smartcrawl_SEO', WPSEO_Plugin_Importers::get() ); + $this->assertContains( WPSEO_Import_Smartcrawl_SEO::class, WPSEO_Plugin_Importers::get() ); } /** @@ -95,14 +97,14 @@ public function test_import_with_data() { $post_id = $this->setup_post(); $result = $this->class_instance->run_import(); - $seo_title = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'title', true ); - $seo_desc = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'metadesc', true ); - $robots_noindex = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', true ); - $robots_nofollow = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-nofollow', true ); - $opengraph_image = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'opengraph-image', true ); - $opengraph_title = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'opengraph-title', true ); - $twitter_title = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'twitter-title', true ); - $focuskw = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'focuskw', true ); + $seo_title = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'title', true ); + $seo_desc = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'metadesc', true ); + $robots_noindex = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', true ); + $robots_nofollow = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-nofollow', true ); + $opengraph_image = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'opengraph-image', true ); + $opengraph_title = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'opengraph-title', true ); + $twitter_title = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'twitter-title', true ); + $focuskw = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'focuskw', true ); $this->assertEquals( 'Test title', $seo_title ); $this->assertEquals( 'Test description', $seo_desc ); @@ -130,14 +132,14 @@ public function test_import_with_data() { */ public function test_import_without_opengraph_data() { $post_id = $this->setup_post(); - delete_post_meta( $post_id, '_wds_twitter' ); - delete_post_meta( $post_id, '_wds_opengraph' ); + \delete_post_meta( $post_id, '_wds_twitter' ); + \delete_post_meta( $post_id, '_wds_opengraph' ); $result = $this->class_instance->run_import(); - $seo_title = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'title', true ); - $seo_desc = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'metadesc', true ); - $robots_noindex = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', true ); - $robots_nofollow = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-nofollow', true ); + $seo_title = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'title', true ); + $seo_desc = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'metadesc', true ); + $robots_noindex = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', true ); + $robots_nofollow = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-nofollow', true ); $this->assertEquals( 'Test title', $seo_title ); $this->assertEquals( 'Test description', $seo_desc ); @@ -165,8 +167,8 @@ public function test_import_without_rights_to_temp_table() { // Save for later return. $original_wpdb = $wpdb; - $wpdb = $this->getMockBuilder( 'wpdb' ) - ->setConstructorArgs( [ DB_USER, DB_PASSWORD, DB_NAME, DB_HOST ] ) + $wpdb = $this->getMockBuilder( wpdb::class ) + ->setConstructorArgs( [ \DB_USER, \DB_PASSWORD, \DB_NAME, \DB_HOST ] ) ->setMethods( [ 'query' ] ) ->getMock(); $wpdb->expects( $this->any() ) @@ -198,12 +200,12 @@ public function test_import_without_overwriting_data() { $post_id = $this->setup_post( true ); $result = $this->class_instance->run_import(); - $seo_title = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'title', true ); - $seo_desc = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'metadesc', true ); - $robots_noindex = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', true ); - $robots_nofollow = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-nofollow', true ); - $opengraph_image = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'opengraph-image', true ); - $opengraph_title = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'opengraph-title', true ); + $seo_title = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'title', true ); + $seo_desc = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'metadesc', true ); + $robots_noindex = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', true ); + $robots_nofollow = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-nofollow', true ); + $opengraph_image = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'opengraph-image', true ); + $opengraph_title = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'opengraph-title', true ); $this->assertEquals( 'Test title', $seo_title ); $this->assertEquals( 'Existing Yoast SEO Test description', $seo_desc ); @@ -234,9 +236,9 @@ public function test_cleanup() { $post_id = $this->setup_post(); $result = $this->class_instance->run_cleanup(); - $seo_title = get_post_meta( $post_id, '_wds_metadesc', true ); - $seo_desc = get_post_meta( $post_id, '_wds_title', true ); - $twitter = get_post_meta( $post_id, '_wds_twitter', true ); + $seo_title = \get_post_meta( $post_id, '_wds_metadesc', true ); + $seo_desc = \get_post_meta( $post_id, '_wds_title', true ); + $twitter = \get_post_meta( $post_id, '_wds_twitter', true ); $this->assertEquals( $seo_title, false ); $this->assertEquals( $seo_desc, false ); @@ -258,8 +260,8 @@ public function test_cleanup_gone_bad() { global $wpdb; $original_wpdb = $wpdb; - $wpdb = $this->getMockBuilder( 'wpdb' ) - ->setConstructorArgs( [ DB_USER, DB_PASSWORD, DB_NAME, DB_HOST ] ) + $wpdb = $this->getMockBuilder( wpdb::class ) + ->setConstructorArgs( [ \DB_USER, \DB_PASSWORD, \DB_NAME, \DB_HOST ] ) ->setMethods( [ 'query' ] ) ->getMock(); $wpdb->expects( $this->any() ) @@ -295,18 +297,18 @@ private function status( $action, $status ) { */ private function setup_post( $pre_existing_yoast_data = false ) { $post_id = $this->factory()->post->create(); - update_post_meta( $post_id, '_wds_title', 'Test title' ); - update_post_meta( $post_id, '_wds_metadesc', 'Test description' ); - update_post_meta( $post_id, '_wds_focus-keywords', 'smartcrawl focuskw' ); - update_post_meta( $post_id, '_wds_meta-robots-noindex', 1 ); - update_post_meta( $post_id, '_wds_meta-robots-nofollow', 1 ); - update_post_meta( $post_id, '_wds_opengraph', 'a:4:{s:8:"disabled";b:0;s:5:"title";s:31:"smartcrawl test opengraph title";s:11:"description";s:30:"smartcrawl test opengraph desc";s:6:"images";a:1:{i:0;s:73:"http://local.wordpress.test/wp-content/uploads/2018/01/actionable-seo.png";}}' ); - update_post_meta( $post_id, '_wds_twitter', 'a:3:{s:8:"disabled";b:0;s:6:"use_og";b:0;s:5:"title";s:29:"smartcrawl test twitter title";}' ); + \update_post_meta( $post_id, '_wds_title', 'Test title' ); + \update_post_meta( $post_id, '_wds_metadesc', 'Test description' ); + \update_post_meta( $post_id, '_wds_focus-keywords', 'smartcrawl focuskw' ); + \update_post_meta( $post_id, '_wds_meta-robots-noindex', 1 ); + \update_post_meta( $post_id, '_wds_meta-robots-nofollow', 1 ); + \update_post_meta( $post_id, '_wds_opengraph', 'a:4:{s:8:"disabled";b:0;s:5:"title";s:31:"smartcrawl test opengraph title";s:11:"description";s:30:"smartcrawl test opengraph desc";s:6:"images";a:1:{i:0;s:73:"http://local.wordpress.test/wp-content/uploads/2018/01/actionable-seo.png";}}' ); + \update_post_meta( $post_id, '_wds_twitter', 'a:3:{s:8:"disabled";b:0;s:6:"use_og";b:0;s:5:"title";s:29:"smartcrawl test twitter title";}' ); if ( $pre_existing_yoast_data ) { - update_post_meta( $post_id, '_yoast_wpseo_metadesc', 'Existing Yoast SEO Test description' ); - update_post_meta( $post_id, '_yoast_wpseo_meta-robots-noindex', 0 ); - update_post_meta( $post_id, '_yoast_wpseo_opengraph-title', 'Pre-existing Yoast SEO test OpenGraph title' ); + \update_post_meta( $post_id, '_yoast_wpseo_metadesc', 'Existing Yoast SEO Test description' ); + \update_post_meta( $post_id, '_yoast_wpseo_meta-robots-noindex', 0 ); + \update_post_meta( $post_id, '_yoast_wpseo_opengraph-title', 'Pre-existing Yoast SEO test OpenGraph title' ); } return $post_id; } diff --git a/tests/WP/Admin/Import/test-class-import-squirrly.php b/tests/WP/Admin/Import/Squirrly_Test.php similarity index 78% rename from tests/WP/Admin/Import/test-class-import-squirrly.php rename to tests/WP/Admin/Import/Squirrly_Test.php index 08acc6f2fde..cc6e4c284db 100644 --- a/tests/WP/Admin/Import/test-class-import-squirrly.php +++ b/tests/WP/Admin/Import/Squirrly_Test.php @@ -1,16 +1,18 @@ class_instance->run_cleanup(); - add_filter( 'query', [ $this, '_create_temporary_tables' ] ); - add_filter( 'query', [ $this, '_drop_temporary_tables' ] ); + \add_filter( 'query', [ $this, '_create_temporary_tables' ] ); + \add_filter( 'query', [ $this, '_drop_temporary_tables' ] ); parent::tear_down(); } @@ -54,7 +56,7 @@ public function test_plugin_name() { * @covers WPSEO_Plugin_Importers::get */ public function test_importer_registered() { - $this->assertContains( 'WPSEO_Import_Squirrly', WPSEO_Plugin_Importers::get() ); + $this->assertContains( WPSEO_Import_Squirrly::class, WPSEO_Plugin_Importers::get() ); } /** @@ -107,13 +109,13 @@ public function test_import_with_data() { $post_id = $this->setup_post(); $result = $this->class_instance->run_import(); - $seo_title = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'title', true ); - $seo_desc = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'metadesc', true ); - $robots_noindex = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', true ); - $robots_nofollow = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-nofollow', true ); - $opengraph_image = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'opengraph-image', true ); - $opengraph_title = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'opengraph-title', true ); - $cornerstone = get_post_meta( $post_id, '_yst_is_cornerstone', true ); + $seo_title = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'title', true ); + $seo_desc = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'metadesc', true ); + $robots_noindex = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', true ); + $robots_nofollow = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-nofollow', true ); + $opengraph_image = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'opengraph-image', true ); + $opengraph_title = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'opengraph-title', true ); + $cornerstone = \get_post_meta( $post_id, '_yst_is_cornerstone', true ); $this->assertEquals( 'Test title', $seo_title ); $this->assertEquals( 'Test description', $seo_desc ); @@ -139,12 +141,12 @@ public function test_import_without_overwriting_data() { $post_id = $this->setup_post( true ); $result = $this->class_instance->run_import(); - $seo_title = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'title', true ); - $seo_desc = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'metadesc', true ); - $robots_noindex = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', true ); - $robots_nofollow = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-nofollow', true ); - $opengraph_image = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'opengraph-image', true ); - $opengraph_title = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'opengraph-title', true ); + $seo_title = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'title', true ); + $seo_desc = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'metadesc', true ); + $robots_noindex = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', true ); + $robots_nofollow = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-nofollow', true ); + $opengraph_image = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'opengraph-image', true ); + $opengraph_title = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'opengraph-title', true ); $this->assertEquals( 'Test title', $seo_title ); $this->assertEquals( 'Existing Yoast SEO Test description', $seo_desc ); @@ -168,16 +170,16 @@ public function test_import_without_overwriting_data() { */ public function test_import_without_focus_keyword() { $post_id = $this->setup_post( true ); - delete_post_meta( $post_id, '_sq_post_keyword' ); + \delete_post_meta( $post_id, '_sq_post_keyword' ); $result = $this->class_instance->run_import(); - $seo_title = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'title', true ); - $seo_desc = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'metadesc', true ); - $robots_noindex = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', true ); - $robots_nofollow = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-nofollow', true ); - $opengraph_image = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'opengraph-image', true ); - $opengraph_title = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'opengraph-title', true ); + $seo_title = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'title', true ); + $seo_desc = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'metadesc', true ); + $robots_noindex = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', true ); + $robots_nofollow = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-nofollow', true ); + $opengraph_image = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'opengraph-image', true ); + $opengraph_title = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'opengraph-title', true ); $this->assertEquals( 'Test title', $seo_title ); $this->assertEquals( 'Existing Yoast SEO Test description', $seo_desc ); @@ -226,7 +228,7 @@ public function test_cleanup_without_data() { * @covers WPSEO_Import_Squirrly::cleanup */ public function test_cleanup() { - remove_all_filters( 'query' ); + \remove_all_filters( 'query' ); $this->setup_post(); $result = $this->class_instance->run_cleanup(); @@ -254,8 +256,8 @@ public function test_cleanup_gone_bad() { global $wpdb; $original_wpdb = $wpdb; - $wpdb = $this->getMockBuilder( 'wpdb' ) - ->setConstructorArgs( [ DB_USER, DB_PASSWORD, DB_NAME, DB_HOST ] ) + $wpdb = $this->getMockBuilder( wpdb::class ) + ->setConstructorArgs( [ \DB_USER, \DB_PASSWORD, \DB_NAME, \DB_HOST ] ) ->setMethods( [ 'query', 'get_var' ] ) ->getMock(); $wpdb->expects( $this->any() ) @@ -310,12 +312,12 @@ private function setup_post( $pre_existing_yoast_data = false ) { ] ); $this->insert_post( $post_id, $blob ); - update_post_meta( $post_id, '_sq_post_keyword', '{"keyword":"squirrly test","update":1521207189}' ); + \update_post_meta( $post_id, '_sq_post_keyword', '{"keyword":"squirrly test","update":1521207189}' ); if ( $pre_existing_yoast_data ) { - update_post_meta( $post_id, '_yoast_wpseo_metadesc', 'Existing Yoast SEO Test description' ); - update_post_meta( $post_id, '_yoast_wpseo_meta-robots-noindex', 0 ); - update_post_meta( $post_id, '_yoast_wpseo_opengraph-title', 'Pre-existing Yoast SEO test OpenGraph title' ); + \update_post_meta( $post_id, '_yoast_wpseo_metadesc', 'Existing Yoast SEO Test description' ); + \update_post_meta( $post_id, '_yoast_wpseo_meta-robots-noindex', 0 ); + \update_post_meta( $post_id, '_yoast_wpseo_opengraph-title', 'Pre-existing Yoast SEO test OpenGraph title' ); } return $post_id; @@ -329,7 +331,7 @@ private function setup_post( $pre_existing_yoast_data = false ) { * @return array Complete array. */ private function build_data_blob( $data = [] ) { - return array_merge( + return \array_merge( [ 'doseo' => 1, 'noindex' => 0, @@ -377,11 +379,11 @@ private function insert_post( $post_id, $blob ) { %s, %s );', - get_current_blog_id(), + \get_current_blog_id(), $post_id, - get_permalink( $post_id ), - md5( get_permalink( $post_id ) ), - serialize( $blob ) + \get_permalink( $post_id ), + \md5( \get_permalink( $post_id ) ), + \serialize( $blob ) ) ); } @@ -391,7 +393,7 @@ private function insert_post( $post_id, $blob ) { */ private function create_table() { // We need to test creating and dropping tables, so we can't have this. - remove_all_filters( 'query' ); + \remove_all_filters( 'query' ); global $wpdb; $wpdb->query( diff --git a/tests/WP/Admin/Import/test-class-import-status.php b/tests/WP/Admin/Import/Status_Test.php similarity index 97% rename from tests/WP/Admin/Import/test-class-import-status.php rename to tests/WP/Admin/Import/Status_Test.php index 7d9b7686800..bd50102d0f0 100644 --- a/tests/WP/Admin/Import/test-class-import-status.php +++ b/tests/WP/Admin/Import/Status_Test.php @@ -1,16 +1,14 @@ assertContains( 'WPSEO_Import_Ultimate_SEO', WPSEO_Plugin_Importers::get() ); + $this->assertContains( WPSEO_Import_Ultimate_SEO::class, WPSEO_Plugin_Importers::get() ); } /** @@ -89,10 +90,10 @@ public function test_import() { $post_id = $this->setup_post(); $result = $this->class_instance->run_import(); - $seo_title = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'title', true ); - $seo_desc = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'metadesc', true ); - $robots_noindex = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', true ); - $robots_nofollow = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-nofollow', true ); + $seo_title = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'title', true ); + $seo_desc = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'metadesc', true ); + $robots_noindex = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', true ); + $robots_nofollow = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-nofollow', true ); $this->assertEquals( 1, $robots_noindex ); $this->assertEquals( 1, $robots_nofollow ); @@ -120,8 +121,8 @@ public function test_cleanup() { $post_id = $this->setup_post(); $result = $this->class_instance->run_cleanup(); - $seo_title = get_post_meta( $post_id, '_su_title', true ); - $seo_desc = get_post_meta( $post_id, '_su_description', true ); + $seo_title = \get_post_meta( $post_id, '_su_title', true ); + $seo_desc = \get_post_meta( $post_id, '_su_description', true ); $this->assertEquals( $seo_title, false ); $this->assertEquals( $seo_desc, false ); @@ -147,10 +148,10 @@ private function status( $action, $status ) { */ private function setup_post() { $post_id = $this->factory()->post->create(); - update_post_meta( $post_id, '_su_title', 'Test title' ); - update_post_meta( $post_id, '_su_description', 'Test description' ); - update_post_meta( $post_id, '_su_meta_robots_noindex', 'on' ); - update_post_meta( $post_id, '_su_meta_robots_nofollow', 'on' ); + \update_post_meta( $post_id, '_su_title', 'Test title' ); + \update_post_meta( $post_id, '_su_description', 'Test description' ); + \update_post_meta( $post_id, '_su_meta_robots_noindex', 'on' ); + \update_post_meta( $post_id, '_su_meta_robots_nofollow', 'on' ); return $post_id; } } diff --git a/tests/WP/Admin/Import/test-class-import-wpseo.php b/tests/WP/Admin/Import/WPSEO_Test.php similarity index 78% rename from tests/WP/Admin/Import/test-class-import-wpseo.php rename to tests/WP/Admin/Import/WPSEO_Test.php index ff1e9080eb2..c6336897d81 100644 --- a/tests/WP/Admin/Import/test-class-import-wpseo.php +++ b/tests/WP/Admin/Import/WPSEO_Test.php @@ -1,16 +1,18 @@ assertContains( 'WPSEO_Import_WPSEO', WPSEO_Plugin_Importers::get() ); + $this->assertContains( WPSEO_Import_WPSEO::class, WPSEO_Plugin_Importers::get() ); } /** @@ -91,12 +93,12 @@ public function test_import() { $post_id = $this->setup_data(); $result = $this->class_instance->run_import(); - $seo_title = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'title', true ); - $seo_desc = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'metadesc', true ); - $og_title = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'opengraph-title', true ); - $tw_title = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'twitter-title', true ); - $robots_noindex = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', true ); - $robots_nofollow = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-nofollow', true ); + $seo_title = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'title', true ); + $seo_desc = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'metadesc', true ); + $og_title = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'opengraph-title', true ); + $tw_title = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'twitter-title', true ); + $robots_noindex = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', true ); + $robots_nofollow = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-nofollow', true ); $this->assertEquals( 'Test title', $seo_title ); $this->assertEquals( 'Test description', $seo_desc ); @@ -144,10 +146,10 @@ public function test_import_category() { */ public function test_import_faulty_robots() { $post_id = $this->setup_data(); - update_post_meta( $post_id, '_wpseo_edit_robots', 9 ); + \update_post_meta( $post_id, '_wpseo_edit_robots', 9 ); $this->class_instance->run_import(); - $robots_noindex = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', true ); + $robots_noindex = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', true ); $this->assertEquals( 2, $robots_noindex ); } @@ -173,8 +175,8 @@ public function test_cleanup() { $post_id = $this->setup_data(); $result = $this->class_instance->run_cleanup(); - $seo_title = get_post_meta( $post_id, '_wpseo_edit_title', true ); - $seo_desc = get_post_meta( $post_id, '_wpseo_edit_description', true ); + $seo_title = \get_post_meta( $post_id, '_wpseo_edit_title', true ); + $seo_desc = \get_post_meta( $post_id, '_wpseo_edit_description', true ); $this->assertEquals( $seo_title, false ); $this->assertEquals( $seo_desc, false ); @@ -200,11 +202,11 @@ private function status( $action, $status ) { */ private function setup_data() { $post_id = $this->factory()->post->create(); - update_post_meta( $post_id, '_wpseo_edit_title', 'Test title' ); - update_post_meta( $post_id, '_wpseo_edit_description', 'Test description' ); - update_post_meta( $post_id, '_wpseo_edit_robots', 5 ); - update_post_meta( $post_id, '_wpseo_edit_og_title', 'Test OG title' ); - update_post_meta( $post_id, '_wpseo_edit_twittercard_title', 'Test Twitter title' ); + \update_post_meta( $post_id, '_wpseo_edit_title', 'Test title' ); + \update_post_meta( $post_id, '_wpseo_edit_description', 'Test description' ); + \update_post_meta( $post_id, '_wpseo_edit_robots', 5 ); + \update_post_meta( $post_id, '_wpseo_edit_og_title', 'Test OG title' ); + \update_post_meta( $post_id, '_wpseo_edit_twittercard_title', 'Test Twitter title' ); return $post_id; } @@ -225,7 +227,7 @@ private function create_category_metadata( $name, $desc, $robots ) { 'taxonomy' => 'category', ] ); - update_option( 'wpseo_category_' . $term_id, $desc ); - update_option( 'wpseo_category_' . $term_id . '_robots', $robots ); + \update_option( 'wpseo_category_' . $term_id, $desc ); + \update_option( 'wpseo_category_' . $term_id . '_robots', $robots ); } } diff --git a/tests/WP/Admin/Import/test-class-import-wp-meta-seo.php b/tests/WP/Admin/Import/WP_Meta_SEO_Test.php similarity index 76% rename from tests/WP/Admin/Import/test-class-import-wp-meta-seo.php rename to tests/WP/Admin/Import/WP_Meta_SEO_Test.php index 8dd11c67f5e..a03b9de6921 100644 --- a/tests/WP/Admin/Import/test-class-import-wp-meta-seo.php +++ b/tests/WP/Admin/Import/WP_Meta_SEO_Test.php @@ -1,16 +1,17 @@ assertContains( 'WPSEO_Import_WP_Meta_SEO', WPSEO_Plugin_Importers::get() ); + $this->assertContains( WPSEO_Import_WP_Meta_SEO::class, WPSEO_Plugin_Importers::get() ); } /** @@ -89,10 +90,10 @@ public function test_import() { $post_id = $this->setup_post(); $result = $this->class_instance->run_import(); - $seo_title = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'title', true ); - $seo_desc = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'metadesc', true ); - $robots_noindex = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', true ); - $robots_nofollow = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-nofollow', true ); + $seo_title = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'title', true ); + $seo_desc = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'metadesc', true ); + $robots_noindex = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', true ); + $robots_nofollow = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'meta-robots-nofollow', true ); $this->assertEquals( 1, $robots_noindex ); $this->assertEquals( 0, $robots_nofollow ); @@ -120,8 +121,8 @@ public function test_cleanup() { $post_id = $this->setup_post(); $result = $this->class_instance->run_cleanup(); - $seo_title = get_post_meta( $post_id, '_su_title', true ); - $seo_desc = get_post_meta( $post_id, '_su_description', true ); + $seo_title = \get_post_meta( $post_id, '_su_title', true ); + $seo_desc = \get_post_meta( $post_id, '_su_description', true ); $this->assertEquals( $seo_title, false ); $this->assertEquals( $seo_desc, false ); @@ -147,10 +148,10 @@ private function status( $action, $status ) { */ private function setup_post() { $post_id = $this->factory()->post->create(); - update_post_meta( $post_id, '_metaseo_metatitle', 'Test title' ); - update_post_meta( $post_id, '_metaseo_metadesc', 'Test description' ); - update_post_meta( $post_id, '_metaseo_metafollow', 'follow' ); - update_post_meta( $post_id, '_metaseo_metaindex', 'noindex' ); + \update_post_meta( $post_id, '_metaseo_metatitle', 'Test title' ); + \update_post_meta( $post_id, '_metaseo_metadesc', 'Test description' ); + \update_post_meta( $post_id, '_metaseo_metafollow', 'follow' ); + \update_post_meta( $post_id, '_metaseo_metaindex', 'noindex' ); return $post_id; } diff --git a/tests/WP/Admin/Import/test-class-import-woothemes-seo.php b/tests/WP/Admin/Import/WooThemes_SEO_Test.php similarity index 82% rename from tests/WP/Admin/Import/test-class-import-woothemes-seo.php rename to tests/WP/Admin/Import/WooThemes_SEO_Test.php index 31df7981ac8..aaafd1213ee 100644 --- a/tests/WP/Admin/Import/test-class-import-woothemes-seo.php +++ b/tests/WP/Admin/Import/WooThemes_SEO_Test.php @@ -1,16 +1,18 @@ class_instance = new WPSEO_Import_WooThemes_SEO(); } @@ -47,7 +49,7 @@ public function test_plugin_name() { * @covers WPSEO_Plugin_Importers::get */ public function test_importer_registered() { - $this->assertContains( 'WPSEO_Import_WooThemes_SEO', WPSEO_Plugin_Importers::get() ); + $this->assertContains( WPSEO_Import_WooThemes_SEO::class, WPSEO_Plugin_Importers::get() ); } /** @@ -94,8 +96,8 @@ public function test_import() { $post_id = $this->setup_post(); $result = $this->class_instance->run_import(); - $seo_title = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'title', true ); - $seo_desc = get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'metadesc', true ); + $seo_title = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'title', true ); + $seo_desc = \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'metadesc', true ); $this->assertEquals( $seo_title, 'Test title' ); $this->assertEquals( $seo_desc, 'Test description' ); @@ -125,8 +127,8 @@ public function test_cleanup() { $post_id = $this->setup_post(); $result = $this->class_instance->run_cleanup(); - $seo_title = get_post_meta( $post_id, 'seo_title', true ); - $seo_desc = get_post_meta( $post_id, 'seo_description', true ); + $seo_title = \get_post_meta( $post_id, 'seo_title', true ); + $seo_desc = \get_post_meta( $post_id, 'seo_description', true ); $this->assertEquals( false, $seo_title ); $this->assertEquals( false, $seo_desc ); @@ -152,8 +154,8 @@ private function status( $action, $status ) { */ private function setup_post() { $post_id = $this->factory()->post->create(); - update_post_meta( $post_id, 'seo_title', 'Test title' ); - update_post_meta( $post_id, 'seo_description', 'Test description' ); + \update_post_meta( $post_id, 'seo_title', 'Test title' ); + \update_post_meta( $post_id, 'seo_description', 'Test description' ); return $post_id; } diff --git a/tests/WP/Admin/test-class-yoast-input-select.php b/tests/WP/Admin/Input_Select_Test.php similarity index 97% rename from tests/WP/Admin/test-class-yoast-input-select.php rename to tests/WP/Admin/Input_Select_Test.php index 8fa448f7211..ea888f97e34 100644 --- a/tests/WP/Admin/test-class-yoast-input-select.php +++ b/tests/WP/Admin/Input_Select_Test.php @@ -1,16 +1,14 @@ getMockBuilder( 'WP_User' ) + $user = $this->getMockBuilder( WP_User::class ) ->getMock(); // Option may be filled if the user has not set it. @@ -343,7 +343,7 @@ public function test_column_hidden_HIDE_COLUMNS() { */ public function test_column_hidden_KEEP_OPTION() { // Option shouldn't be touched if the user has set it already. - $user = $this->getMockBuilder( 'WP_User' ) + $user = $this->getMockBuilder( WP_User::class ) ->getMock(); $user->expects( $this->any() ) @@ -366,7 +366,7 @@ public function test_column_hidden_KEEP_OPTION() { * @covers WPSEO_Meta_Columns::column_hidden */ public function test_column_hidden_UNEXPECTED_VALUE() { - $user = $this->getMockBuilder( 'WP_User' ) + $user = $this->getMockBuilder( WP_User::class ) ->getMock(); $user->expects( $this->any() ) diff --git a/tests/WP/test-class-wpseo-metabox.php b/tests/WP/Admin/Metabox/Metabox_Test.php similarity index 88% rename from tests/WP/test-class-wpseo-metabox.php rename to tests/WP/Admin/Metabox/Metabox_Test.php index f02d7d61c25..072269785f2 100644 --- a/tests/WP/test-class-wpseo-metabox.php +++ b/tests/WP/Admin/Metabox/Metabox_Test.php @@ -1,16 +1,19 @@ enqueue(); - $enqueued = wp_script_is( 'post-edit', 'enqueued' ); + $enqueued = \wp_script_is( 'post-edit', 'enqueued' ); $this->assertFalse( $enqueued ); } @@ -62,7 +65,7 @@ public function test_enqueue_firing_on_new_post_page() { // Call enqueue function. self::$class_instance->enqueue(); - $enqueued = wp_script_is( WPSEO_Admin_Asset_Manager::PREFIX . 'post-edit', 'enqueued' ); + $enqueued = \wp_script_is( WPSEO_Admin_Asset_Manager::PREFIX . 'post-edit', 'enqueued' ); $this->assertTrue( $enqueued ); } @@ -75,7 +78,7 @@ public function test_add_metabox() { global $wp_meta_boxes; $stub = $this - ->getMockBuilder( 'WPSEO_Metabox' ) + ->getMockBuilder( WPSEO_Metabox::class ) ->setMethods( [ 'is_metabox_hidden' ] ) ->getMock(); @@ -103,19 +106,20 @@ public function test_add_metabox() { public function test_save_postdata() { // Create and go to post. $post_id = $this->factory->post->create(); - $this->go_to( get_permalink( $post_id ) ); + $this->go_to( \get_permalink( $post_id ) ); - $post = get_post( $post_id ); + $post = \get_post( $post_id ); $_POST['ID'] = $post_id; - $_POST['yoast_free_metabox_nonce'] = wp_create_nonce( 'yoast_free_metabox' ); + $_POST['yoast_free_metabox_nonce'] = \wp_create_nonce( 'yoast_free_metabox' ); // Setup. + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- This has to match the expected name. $GLOBALS['wpseo_admin'] = new WPSEO_Admin(); // Vars. - $meta_fields = apply_filters( 'wpseo_save_metaboxes', [] ); - $meta_fields = array_merge( + $meta_fields = \apply_filters( 'wpseo_save_metaboxes', [] ); + $meta_fields = \array_merge( $meta_fields, WPSEO_Meta::get_meta_field_defs( 'general', $post->post_type ), WPSEO_Meta::get_meta_field_defs( 'advanced' ), @@ -141,7 +145,7 @@ public function test_save_postdata() { self::$class_instance->save_postdata( $post->ID ); // Check if output matches. - $custom = get_post_custom( $post->ID ); + $custom = \get_post_custom( $post->ID ); foreach ( $meta_fields as $key => $field ) { if ( ! isset( $custom[ WPSEO_Meta::$meta_prefix . $key ][0] ) ) { @@ -178,7 +182,7 @@ public function test_save_postdata() { public function test_save_postdata_for_separate_fields( $field_name, $field_value, $expected_value, $message ) { // Create and go to post. $post_id = $this->factory->post->create(); - $this->go_to( get_permalink( $post_id ) ); + $this->go_to( \get_permalink( $post_id ) ); $prefixed_field_name = WPSEO_Meta::$form_prefix . $field_name; @@ -186,10 +190,11 @@ public function test_save_postdata_for_separate_fields( $field_name, $field_valu 'ID' => $post_id, 'post_type' => 'post', $prefixed_field_name => $field_value, - 'yoast_free_metabox_nonce' => wp_create_nonce( 'yoast_free_metabox' ), + 'yoast_free_metabox_nonce' => \wp_create_nonce( 'yoast_free_metabox' ), ]; // Setup. + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- This has to match the expected name. $GLOBALS['wpseo_admin'] = new WPSEO_Admin(); $disabled_advanced_meta = WPSEO_Options::get( 'disableadvanced_meta' ); diff --git a/tests/WP/Admin/test-class-yoast-network-admin.php b/tests/WP/Admin/Network_Admin_Test.php similarity index 68% rename from tests/WP/Admin/test-class-yoast-network-admin.php rename to tests/WP/Admin/Network_Admin_Test.php index 91da5594372..fb239869da8 100644 --- a/tests/WP/Admin/test-class-yoast-network-admin.php +++ b/tests/WP/Admin/Network_Admin_Test.php @@ -1,16 +1,15 @@ user->create( [ 'role' => 'administrator' ] ); - grant_super_admin( self::$network_administrator ); + \grant_super_admin( self::$network_administrator ); } /** @@ -37,7 +36,7 @@ public static function wpSetUpBeforeClass( $factory ) { * @return void */ public static function wpTearDownAfterClass() { - revoke_super_admin( self::$network_administrator ); + \revoke_super_admin( self::$network_administrator ); self::delete_user( self::$network_administrator ); } @@ -53,15 +52,15 @@ public function test_get_site_choices() { $admin = new Yoast_Network_Admin(); - $site_ids = array_map( 'strval', array_merge( [ get_current_blog_id() ], self::factory()->blog->create_many( 5 ) ) ); + $site_ids = \array_map( 'strval', \array_merge( [ \get_current_blog_id() ], self::factory()->blog->create_many( 5 ) ) ); $choices = $admin->get_site_choices(); - $this->assertSame( $site_ids, array_map( 'strval', array_keys( $choices ) ) ); + $this->assertSame( $site_ids, \array_map( 'strval', \array_keys( $choices ) ) ); - array_unshift( $site_ids, '-' ); + \array_unshift( $site_ids, '-' ); $choices = $admin->get_site_choices( true ); - $this->assertSame( $site_ids, array_map( 'strval', array_keys( $choices ) ) ); + $this->assertSame( $site_ids, \array_map( 'strval', \array_keys( $choices ) ) ); } /** @@ -77,15 +76,15 @@ public function test_get_site_choices_output() { $admin = new Yoast_Network_Admin(); - $site = get_site(); + $site = \get_site(); $choices = $admin->get_site_choices(); - $this->assertSame( $site->id, (int) key( $choices ) ); + $this->assertSame( $site->id, (int) \key( $choices ) ); $this->assertStringStartsWith( (string) $site->id, $choices[ $site->id ] ); $this->assertStringContainsString( $site->domain . $site->path, $choices[ $site->id ] ); $choices = $admin->get_site_choices( false, true ); - $this->assertSame( $site->id, (int) key( $choices ) ); + $this->assertSame( $site->id, (int) \key( $choices ) ); $this->assertStringStartsWith( (string) $site->id, $choices[ $site->id ] ); $this->assertStringContainsString( $site->blogname, $choices[ $site->id ] ); $this->assertStringContainsString( $site->domain . $site->path, $choices[ $site->id ] ); @@ -109,10 +108,10 @@ public function test_get_site_states() { ]; $site_id = self::factory()->blog->create(); - update_blog_details( $site_id, $active_states ); + \update_blog_details( $site_id, $active_states ); - $site_states = $admin->get_site_states( get_site( $site_id ) ); - $this->assertSame( array_keys( $active_states ), array_keys( $site_states ) ); + $site_states = $admin->get_site_states( \get_site( $site_id ) ); + $this->assertSame( \array_keys( $active_states ), \array_keys( $site_states ) ); } /** @@ -123,7 +122,7 @@ public function test_get_site_states() { public function test_handle_update_options_request() { $_POST['network_option_group'] = 'wpseo'; $admin = $this - ->getMockBuilder( 'Yoast_Network_Admin' ) + ->getMockBuilder( Yoast_Network_Admin::class ) ->setMethods( [ 'verify_request', 'terminate_request' ] ) ->getMock(); @@ -146,7 +145,7 @@ public function test_handle_update_options_request() { */ public function test_handle_restore_site_request() { $admin = $this - ->getMockBuilder( 'Yoast_Network_Admin' ) + ->getMockBuilder( Yoast_Network_Admin::class ) ->setMethods( [ 'verify_request', 'terminate_request' ] ) ->getMock(); @@ -172,14 +171,14 @@ public function test_settings_fields() { $group = 'yst_ms_group'; - ob_start(); + \ob_start(); $admin->settings_fields( $group ); - $output = ob_get_clean(); + $output = \ob_get_clean(); - $this->assertTrue( (bool) strpos( $output, 'name="network_option_group" value="' . $group . '"' ) ); - $this->assertTrue( (bool) strpos( $output, 'name="action" value="' . Yoast_Network_Admin::UPDATE_OPTIONS_ACTION . '"' ) ); - $this->assertTrue( (bool) preg_match( '/name="_wpnonce" value="([a-z0-9]+)"/', $output, $matches ) ); - $this->assertTrue( (bool) wp_verify_nonce( $matches[1], $group . '-network-options' ) ); + $this->assertTrue( (bool) \strpos( $output, 'name="network_option_group" value="' . $group . '"' ) ); + $this->assertTrue( (bool) \strpos( $output, 'name="action" value="' . Yoast_Network_Admin::UPDATE_OPTIONS_ACTION . '"' ) ); + $this->assertTrue( (bool) \preg_match( '/name="_wpnonce" value="([a-z0-9]+)"/', $output, $matches ) ); + $this->assertTrue( (bool) \wp_verify_nonce( $matches[1], $group . '-network-options' ) ); } /** @@ -188,7 +187,7 @@ public function test_settings_fields() { * @covers Yoast_Network_Admin::register_hooks */ public function test_register_hooks() { - $admin = $this->getMockBuilder( 'Yoast_Network_Admin' ) + $admin = $this->getMockBuilder( Yoast_Network_Admin::class ) ->setMethods( [ 'meets_requirements' ] ) ->getMock(); @@ -198,8 +197,8 @@ public function test_register_hooks() { ->will( $this->returnValue( true ) ); $admin->register_hooks(); - $this->assertIsInt( has_action( 'admin_action_' . Yoast_Network_Admin::UPDATE_OPTIONS_ACTION, [ $admin, 'handle_update_options_request' ] ) ); - $this->assertIsInt( has_action( 'admin_action_' . Yoast_Network_Admin::RESTORE_SITE_ACTION, [ $admin, 'handle_restore_site_request' ] ) ); + $this->assertIsInt( \has_action( 'admin_action_' . Yoast_Network_Admin::UPDATE_OPTIONS_ACTION, [ $admin, 'handle_update_options_request' ] ) ); + $this->assertIsInt( \has_action( 'admin_action_' . Yoast_Network_Admin::RESTORE_SITE_ACTION, [ $admin, 'handle_restore_site_request' ] ) ); } /** @@ -211,8 +210,8 @@ public function test_register_ajax_hooks() { $admin = new Yoast_Network_Admin(); $admin->register_ajax_hooks(); - $this->assertIsInt( has_action( 'wp_ajax_' . Yoast_Network_Admin::UPDATE_OPTIONS_ACTION, [ $admin, 'handle_update_options_request' ] ) ); - $this->assertIsInt( has_action( 'wp_ajax_' . Yoast_Network_Admin::RESTORE_SITE_ACTION, [ $admin, 'handle_restore_site_request' ] ) ); + $this->assertIsInt( \has_action( 'wp_ajax_' . Yoast_Network_Admin::UPDATE_OPTIONS_ACTION, [ $admin, 'handle_update_options_request' ] ) ); + $this->assertIsInt( \has_action( 'wp_ajax_' . Yoast_Network_Admin::RESTORE_SITE_ACTION, [ $admin, 'handle_restore_site_request' ] ) ); } /** @@ -235,12 +234,12 @@ public function test_meets_requirements() { public function test_verify_request_with_invalid_nonce() { $admin = new Yoast_Network_Admin(); - $_REQUEST['_wp_http_referer'] = admin_url(); + $_REQUEST['_wp_http_referer'] = \admin_url(); $_REQUEST['_wpnonce'] = ''; $expected_message = 'The link you followed has expired.'; - $this->expectException( 'WPDieException' ); + $this->expectException( WPDieException::class ); $this->expectExceptionMessage( $expected_message ); $admin->verify_request( 'my_action' ); @@ -254,10 +253,10 @@ public function test_verify_request_with_invalid_nonce() { public function test_verify_request_with_valid_nonce_but_lacking_caps() { $admin = new Yoast_Network_Admin(); - $_REQUEST['_wp_http_referer'] = admin_url(); - $_REQUEST['_wpnonce'] = wp_create_nonce( 'my_action' ); + $_REQUEST['_wp_http_referer'] = \admin_url(); + $_REQUEST['_wpnonce'] = \wp_create_nonce( 'my_action' ); - $this->expectException( 'WPDieException' ); + $this->expectException( WPDieException::class ); $this->expectExceptionMessage( 'You are not allowed to perform this action.' ); $admin->verify_request( 'my_action' ); @@ -271,11 +270,11 @@ public function test_verify_request_with_valid_nonce_but_lacking_caps() { public function test_verify_request_with_valid_nonce_and_caps() { $admin = new Yoast_Network_Admin(); - wp_set_current_user( self::$network_administrator ); - wp_get_current_user()->add_cap( 'wpseo_manage_network_options' ); + \wp_set_current_user( self::$network_administrator ); + \wp_get_current_user()->add_cap( 'wpseo_manage_network_options' ); - $_REQUEST['_wp_http_referer'] = admin_url(); - $_REQUEST['_wpnonce'] = wp_create_nonce( 'my_action' ); + $_REQUEST['_wp_http_referer'] = \admin_url(); + $_REQUEST['_wpnonce'] = \wp_create_nonce( 'my_action' ); $e = null; try { @@ -295,12 +294,12 @@ public function test_verify_request_with_valid_nonce_and_caps() { public function test_verify_request_ajax_with_invalid_nonce() { $admin = new Yoast_Network_Admin(); - add_filter( 'wp_doing_ajax', '__return_true' ); - add_filter( 'wp_die_ajax_handler', [ $this, 'get_wp_die_handler' ] ); + \add_filter( 'wp_doing_ajax', '__return_true' ); + \add_filter( 'wp_die_ajax_handler', [ $this, 'get_wp_die_handler' ] ); $_REQUEST['_wpnonce'] = ''; - $this->expectException( 'WPDieException' ); + $this->expectException( WPDieException::class ); $this->expectExceptionMessage( '-1' ); $admin->verify_request( 'my_action' ); @@ -314,12 +313,12 @@ public function test_verify_request_ajax_with_invalid_nonce() { public function test_verify_request_ajax_with_valid_nonce_but_lacking_caps() { $admin = new Yoast_Network_Admin(); - add_filter( 'wp_doing_ajax', '__return_true' ); - add_filter( 'wp_die_ajax_handler', [ $this, 'get_wp_die_handler' ] ); + \add_filter( 'wp_doing_ajax', '__return_true' ); + \add_filter( 'wp_die_ajax_handler', [ $this, 'get_wp_die_handler' ] ); - $_REQUEST['_wpnonce'] = wp_create_nonce( 'my_action' ); + $_REQUEST['_wpnonce'] = \wp_create_nonce( 'my_action' ); - $this->expectException( 'WPDieException' ); + $this->expectException( WPDieException::class ); $this->expectExceptionMessage( '-1' ); $admin->verify_request( 'my_action' ); @@ -333,13 +332,13 @@ public function test_verify_request_ajax_with_valid_nonce_but_lacking_caps() { public function test_verify_request_ajax_with_valid_nonce_and_caps() { $admin = new Yoast_Network_Admin(); - add_filter( 'wp_doing_ajax', '__return_true' ); - add_filter( 'wp_die_ajax_handler', [ $this, 'get_wp_die_handler' ] ); + \add_filter( 'wp_doing_ajax', '__return_true' ); + \add_filter( 'wp_die_ajax_handler', [ $this, 'get_wp_die_handler' ] ); - wp_set_current_user( self::$network_administrator ); - wp_get_current_user()->add_cap( 'wpseo_manage_network_options' ); + \wp_set_current_user( self::$network_administrator ); + \wp_get_current_user()->add_cap( 'wpseo_manage_network_options' ); - $_REQUEST['_wpnonce'] = wp_create_nonce( 'my_action' ); + $_REQUEST['_wpnonce'] = \wp_create_nonce( 'my_action' ); $e = null; try { @@ -358,7 +357,7 @@ public function test_verify_request_ajax_with_valid_nonce_and_caps() { */ public function test_terminate_request() { $admin = $this - ->getMockBuilder( 'Yoast_Network_Admin' ) + ->getMockBuilder( Yoast_Network_Admin::class ) ->setMethods( [ 'persist_settings_errors', 'redirect_back' ] ) ->getMock(); @@ -384,12 +383,12 @@ public function test_terminate_request() { public function test_terminate_request_ajax() { $admin = new Yoast_Network_Admin(); - add_filter( 'wp_doing_ajax', '__return_true' ); - add_filter( 'wp_die_ajax_handler', [ $this, 'get_wp_die_handler' ] ); + \add_filter( 'wp_doing_ajax', '__return_true' ); + \add_filter( 'wp_die_ajax_handler', [ $this, 'get_wp_die_handler' ] ); - $_REQUEST['_wpnonce'] = wp_create_nonce( 'my_action' ); + $_REQUEST['_wpnonce'] = \wp_create_nonce( 'my_action' ); - $this->expectException( 'WPDieException' ); + $this->expectException( WPDieException::class ); $this->expectExceptionMessage( '' ); $this->expectOutputContains( 'success' ); @@ -397,7 +396,7 @@ public function test_terminate_request_ajax() { try { $admin->terminate_request(); } catch ( WPDieException $e ) { - $output_decoded = json_decode( $this->getActualOutput(), true ); + $output_decoded = \json_decode( $this->getActualOutput(), true ); $this->assertArrayHasKey( 'success', $output_decoded ); throw $e; } diff --git a/tests/WP/Admin/test-class-yoast-network-settings-api.php b/tests/WP/Admin/Network_Settings_API_Test.php similarity index 84% rename from tests/WP/Admin/test-class-yoast-network-settings-api.php rename to tests/WP/Admin/Network_Settings_API_Test.php index 12307eb467e..2f6e99d995d 100644 --- a/tests/WP/Admin/test-class-yoast-network-settings-api.php +++ b/tests/WP/Admin/Network_Settings_API_Test.php @@ -1,16 +1,14 @@ register_setting( 'yst_ms_group', 'yst_ms_option', $setting_args ); - $this->assertIsInt( has_filter( 'sanitize_option_yst_ms_option', [ $api, 'filter_sanitize_option' ] ) ); - $this->assertIsInt( has_filter( 'default_site_option_yst_ms_option', [ $api, 'filter_default_option' ] ) ); + $this->assertIsInt( \has_filter( 'sanitize_option_yst_ms_option', [ $api, 'filter_sanitize_option' ] ) ); + $this->assertIsInt( \has_filter( 'default_site_option_yst_ms_option', [ $api, 'filter_default_option' ] ) ); } /** @@ -46,7 +44,7 @@ public function test_get_registered_settings() { $api = new Yoast_Network_Settings_API(); $api->register_setting( $group, $name, $args ); - $args = array_merge( [ 'group' => $group ], $args ); + $args = \array_merge( [ 'group' => $group ], $args ); $expected = [ $name => $args ]; $this->assertSame( $expected, $api->get_registered_settings() ); @@ -113,7 +111,7 @@ public function test_filter_default_option() { * @covers Yoast_Network_Settings_API::get */ public function test_get() { - $this->assertInstanceOf( 'Yoast_Network_Settings_API', Yoast_Network_Settings_API::get() ); + $this->assertInstanceOf( Yoast_Network_Settings_API::class, Yoast_Network_Settings_API::get() ); } /** @@ -124,6 +122,6 @@ public function test_get() { public function test_meets_requirements() { $api = new Yoast_Network_Settings_API(); - $this->assertSame( is_multisite(), $api->meets_requirements() ); + $this->assertSame( \is_multisite(), $api->meets_requirements() ); } } diff --git a/tests/WP/Admin/test-class-option-tab.php b/tests/WP/Admin/Option_Tab_Test.php similarity index 94% rename from tests/WP/Admin/test-class-option-tab.php rename to tests/WP/Admin/Option_Tab_Test.php index 91da93f046d..1b9f2a40aea 100644 --- a/tests/WP/Admin/test-class-option-tab.php +++ b/tests/WP/Admin/Option_Tab_Test.php @@ -1,16 +1,14 @@ class_instance = $this->getMockBuilder( 'WPSEO_Primary_Term_Admin' ) + $this->class_instance = $this->getMockBuilder( WPSEO_Primary_Term_Admin::class ) ->setMethods( [ 'get_primary_term_taxonomies', 'include_js_templates', 'save_primary_term', 'get_primary_term' ] ) ->getMock(); } @@ -80,7 +79,7 @@ public function test_wp_footer_INCLUDE_WITH_taxonomies() { public function test_enqueue_assets_EMPTY_taxonomies_DO_NOT_enqueue_scripts() { $this->class_instance->enqueue_assets(); - $this->assertFalse( wp_style_is( 'wpseo-primary-category', 'registered' ) ); + $this->assertFalse( \wp_style_is( 'wpseo-primary-category', 'registered' ) ); } /** @@ -97,7 +96,7 @@ public function test_enqueue_assets_DO_NOT_enqueue_scripts() { $this->class_instance->enqueue_assets(); - $this->assertFalse( wp_style_is( 'wpseo-primary-category', 'registered' ) ); + $this->assertFalse( \wp_style_is( 'wpseo-primary-category', 'registered' ) ); } /** @@ -132,6 +131,6 @@ public function test_enqueue_assets_WITH_taxonomies_DO_enqueue_scripts() { $this->class_instance->enqueue_assets(); - $this->assertTrue( wp_style_is( WPSEO_Admin_Asset_Manager::PREFIX . 'primary-category', 'registered' ) ); + $this->assertTrue( \wp_style_is( WPSEO_Admin_Asset_Manager::PREFIX . 'primary-category', 'registered' ) ); } } diff --git a/tests/WP/Admin/test-class-admin-recommended-replace-vars.php b/tests/WP/Admin/Recommended_Replace_Vars_Test.php similarity index 94% rename from tests/WP/Admin/test-class-admin-recommended-replace-vars.php rename to tests/WP/Admin/Recommended_Replace_Vars_Test.php index f8c811e71a2..83d1b1f2486 100644 --- a/tests/WP/Admin/test-class-admin-recommended-replace-vars.php +++ b/tests/WP/Admin/Recommended_Replace_Vars_Test.php @@ -1,16 +1,14 @@ class_instance = new WPSEO_Admin_Recommended_Replace_Vars(); - add_filter( 'wpseo_recommended_replace_vars', [ $this, 'filter_recommended_replacevars' ] ); + \add_filter( 'wpseo_recommended_replace_vars', [ $this, 'filter_recommended_replacevars' ] ); } /** @@ -73,20 +71,20 @@ public function test_determine_for_post_without_a_wp_post_instance() { */ public function test_determine_for_post_with_a_homepage() { // Backup the current values for these options. - $show_on_front = get_option( 'show_on_front' ); - $page_on_front = get_option( 'page_on_front' ); + $show_on_front = \get_option( 'show_on_front' ); + $page_on_front = \get_option( 'page_on_front' ); $post = $this->create_and_get_with_post_type( 'page' ); // Overwrite the options used in the is_homepage function. - update_option( 'show_on_front', 'page' ); - update_option( 'page_on_front', $post->ID ); + \update_option( 'show_on_front', 'page' ); + \update_option( 'page_on_front', $post->ID ); $this->assertEquals( 'homepage', $this->class_instance->determine_for_post( $post ) ); // Revert the options their original values. - update_option( 'show_on_front', $show_on_front ); - update_option( 'page_on_front', $page_on_front ); + \update_option( 'show_on_front', $show_on_front ); + \update_option( 'page_on_front', $page_on_front ); } /** diff --git a/tests/WP/Admin/test-class-schema-person-upgrade-notification.php b/tests/WP/Admin/Schema_Person_Upgrade_Notification_Test.php similarity index 77% rename from tests/WP/Admin/test-class-schema-person-upgrade-notification.php rename to tests/WP/Admin/Schema_Person_Upgrade_Notification_Test.php index fcd4275cf00..c5fb31e6ce7 100644 --- a/tests/WP/Admin/test-class-schema-person-upgrade-notification.php +++ b/tests/WP/Admin/Schema_Person_Upgrade_Notification_Test.php @@ -1,10 +1,9 @@ getMockBuilder( 'WPSEO_Schema_Person_Upgrade_Notification' ) + $instance = $this->getMockBuilder( WPSEO_Schema_Person_Upgrade_Notification::class ) ->setMethods( [ 'remove_notification' ] ) ->getMock(); @@ -37,7 +36,7 @@ public function test_remove_notification_not_person() { * @covers WPSEO_Schema_Person_Upgrade_Notification::handle_notification */ public function test_remove_notification_user_id_set() { - $instance = $this->getMockBuilder( 'WPSEO_Schema_Person_Upgrade_Notification' ) + $instance = $this->getMockBuilder( WPSEO_Schema_Person_Upgrade_Notification::class ) ->setMethods( [ 'remove_notification' ] ) ->getMock(); @@ -55,7 +54,7 @@ public function test_remove_notification_user_id_set() { * @covers WPSEO_Schema_Person_Upgrade_Notification::handle_notification */ public function test_add_notification() { - $instance = $this->getMockBuilder( 'WPSEO_Schema_Person_Upgrade_Notification' ) + $instance = $this->getMockBuilder( WPSEO_Schema_Person_Upgrade_Notification::class ) ->setMethods( [ 'add_notification' ] ) ->getMock(); diff --git a/tests/WP/Admin/Services/test-class-file-size.php b/tests/WP/Admin/Services/File_Size_Service_Test.php similarity index 90% rename from tests/WP/Admin/Services/test-class-file-size.php rename to tests/WP/Admin/Services/File_Size_Service_Test.php index 1bd0183bf2a..b6920a920c3 100644 --- a/tests/WP/Admin/Services/test-class-file-size.php +++ b/tests/WP/Admin/Services/File_Size_Service_Test.php @@ -1,16 +1,15 @@ set_param( 'url', 'external.file' ); $instance = $this - ->getMockBuilder( 'WPSEO_File_Size_Service' ) + ->getMockBuilder( WPSEO_File_Size_Service::class ) ->setMethods( [ 'is_externally_hosted' ] ) ->getMock(); @@ -44,7 +43,7 @@ public function test_get_for_externally_hosted_file() { */ public function test_get_with_unknown_failure() { $instance = $this - ->getMockBuilder( 'WPSEO_File_Size_Service' ) + ->getMockBuilder( WPSEO_File_Size_Service::class ) ->setMethods( [ 'get_file_url', 'calculate_file_size' ] ) ->getMock(); @@ -71,7 +70,7 @@ public function test_get_with_unknown_failure() { */ public function test_get_on_success() { $instance = $this - ->getMockBuilder( 'WPSEO_File_Size_Service' ) + ->getMockBuilder( WPSEO_File_Size_Service::class ) ->setMethods( [ 'get_file_url', 'get_file_size' ] ) ->getMock(); @@ -102,7 +101,7 @@ public function test_get_file_url_for_externally_hosted_file() { $request->set_param( 'url', 'https://extern.al/external.file' ); $instance = $this - ->getMockBuilder( 'WPSEO_File_Size_Service' ) + ->getMockBuilder( WPSEO_File_Size_Service::class ) ->setMethods( [ 'is_externally_hosted' ] ) ->getMock(); @@ -128,7 +127,7 @@ public function test_get_file_url_for_local_file() { $request->set_param( 'url', 'local.file' ); $instance = $this - ->getMockBuilder( 'WPSEO_File_Size_Service' ) + ->getMockBuilder( WPSEO_File_Size_Service::class ) ->setMethods( [ 'is_externally_hosted', 'get_file_size' ] ) ->getMock(); diff --git a/tests/WP/Admin/Watchers/test-class-indexable-post-watcher.php b/tests/WP/Admin/Watchers/Indexable_Post_Watcher_Test.php similarity index 91% rename from tests/WP/Admin/Watchers/test-class-indexable-post-watcher.php rename to tests/WP/Admin/Watchers/Indexable_Post_Watcher_Test.php index 88f486dcd70..6e87ed0b1d7 100644 --- a/tests/WP/Admin/Watchers/test-class-indexable-post-watcher.php +++ b/tests/WP/Admin/Watchers/Indexable_Post_Watcher_Test.php @@ -1,10 +1,8 @@ factory()->post->create_and_get(); - wp_delete_post( $post->ID, true ); + \wp_delete_post( $post->ID, true ); $indexables = $this->get_indexables_for( $post ); @@ -73,7 +71,7 @@ public function test_delete_post_indexable_removed_after_creation() { $this->assertCount( 0, $indexables ); - wp_delete_post( $post->ID, true ); + \wp_delete_post( $post->ID, true ); $this->assertCount( 0, $indexables ); } @@ -99,8 +97,8 @@ public function test_create_post_with_hierarchy() { ] ); - $parent_indexable = current( $this->get_indexables_for( $parent ) ); - $child_indexable = current( $this->get_indexables_for( $child ) ); + $parent_indexable = \current( $this->get_indexables_for( $parent ) ); + $child_indexable = \current( $this->get_indexables_for( $child ) ); $parent_hierarchy = $this->get_hierarchy_for( $parent_indexable ); $child_hierarchy = $this->get_hierarchy_for( $child_indexable ); @@ -129,10 +127,10 @@ public function test_delete_post_with_hierarchy() { ] ); - $parent_indexable = current( $this->get_indexables_for( $parent ) ); - $child_indexable = current( $this->get_indexables_for( $child ) ); + $parent_indexable = \current( $this->get_indexables_for( $parent ) ); + $child_indexable = \current( $this->get_indexables_for( $child ) ); - wp_delete_post( $parent->ID, true ); + \wp_delete_post( $parent->ID, true ); $parent_hierarchy = $this->get_hierarchy_for( $parent_indexable ); $child_hierarchy = $this->get_hierarchy_for( $child_indexable ); diff --git a/tests/WP/Admin/Watchers/test-class-slug-change-watcher.php b/tests/WP/Admin/Watchers/Slug_Change_Watcher_Test.php similarity index 78% rename from tests/WP/Admin/Watchers/test-class-slug-change-watcher.php rename to tests/WP/Admin/Watchers/Slug_Change_Watcher_Test.php index e4f24c9cef6..62ef43d410a 100644 --- a/tests/WP/Admin/Watchers/test-class-slug-change-watcher.php +++ b/tests/WP/Admin/Watchers/Slug_Change_Watcher_Test.php @@ -1,16 +1,14 @@ getMockBuilder( 'WPSEO_Slug_Change_Watcher' ) + ->getMockBuilder( WPSEO_Slug_Change_Watcher::class ) ->setMethods( [ 'add_notification' ] ) ->getMock(); @@ -83,7 +81,7 @@ public function test_detect_post_trash() { $instance->register_hooks(); - wp_trash_post( self::$post_id ); + \wp_trash_post( self::$post_id ); } /** @@ -98,10 +96,10 @@ public function test_detect_post_trash_no_visible_post_status() { 'ID' => self::$post_id, 'post_status' => 'draft', ]; - wp_update_post( $post_args ); + \wp_update_post( $post_args ); $instance = $this - ->getMockBuilder( 'WPSEO_Slug_Change_Watcher' ) + ->getMockBuilder( WPSEO_Slug_Change_Watcher::class ) ->setMethods( [ 'add_notification' ] ) ->getMock(); @@ -111,7 +109,7 @@ public function test_detect_post_trash_no_visible_post_status() { $instance->register_hooks(); - wp_trash_post( self::$post_id ); + \wp_trash_post( self::$post_id ); } /** @@ -121,7 +119,7 @@ public function test_detect_post_trash_no_visible_post_status() { */ public function test_detect_post_delete() { $instance = $this - ->getMockBuilder( 'WPSEO_Slug_Change_Watcher' ) + ->getMockBuilder( WPSEO_Slug_Change_Watcher::class ) ->setMethods( [ 'add_notification' ] ) ->getMock(); @@ -131,7 +129,7 @@ public function test_detect_post_delete() { $instance->register_hooks(); - wp_delete_post( self::$post_id ); + \wp_delete_post( self::$post_id ); } /** @@ -141,7 +139,7 @@ public function test_detect_post_delete() { */ public function test_detect_post_delete_menu_item() { $instance = $this - ->getMockBuilder( 'WPSEO_Slug_Change_Watcher' ) + ->getMockBuilder( WPSEO_Slug_Change_Watcher::class ) ->setMethods( [ 'add_notification' ] ) ->getMock(); @@ -151,7 +149,7 @@ public function test_detect_post_delete_menu_item() { $instance->register_hooks(); - wp_delete_post( self::$nav_menu_item_id ); + \wp_delete_post( self::$nav_menu_item_id ); } /** @@ -165,10 +163,10 @@ public function test_detect_post_delete_trashed_post() { 'ID' => self::$post_id, 'post_status' => 'trash', ]; - wp_update_post( $post_args ); + \wp_update_post( $post_args ); $instance = $this - ->getMockBuilder( 'WPSEO_Slug_Change_Watcher' ) + ->getMockBuilder( WPSEO_Slug_Change_Watcher::class ) ->setMethods( [ 'add_notification' ] ) ->getMock(); @@ -178,7 +176,7 @@ public function test_detect_post_delete_trashed_post() { $instance->register_hooks(); - wp_delete_post( self::$post_id ); + \wp_delete_post( self::$post_id ); } /** @@ -187,10 +185,10 @@ public function test_detect_post_delete_trashed_post() { * @covers WPSEO_Slug_Change_Watcher::detect_post_delete */ public function test_detect_post_delete_revision() { - $revision_id = wp_save_post_revision( self::$post_id ); + $revision_id = \wp_save_post_revision( self::$post_id ); $instance = $this - ->getMockBuilder( 'WPSEO_Slug_Change_Watcher' ) + ->getMockBuilder( WPSEO_Slug_Change_Watcher::class ) ->setMethods( [ 'add_notification' ] ) ->getMock(); @@ -200,7 +198,7 @@ public function test_detect_post_delete_revision() { $instance->register_hooks(); - wp_delete_post( $revision_id ); + \wp_delete_post( $revision_id ); } /** @@ -215,10 +213,10 @@ public function test_detect_post_delete_when_not_visible() { 'ID' => self::$post_id, 'post_status' => 'pending', ]; - wp_update_post( $post_args ); + \wp_update_post( $post_args ); $instance = $this - ->getMockBuilder( 'WPSEO_Slug_Change_Watcher' ) + ->getMockBuilder( WPSEO_Slug_Change_Watcher::class ) ->setMethods( [ 'add_notification' ] ) ->getMock(); @@ -228,7 +226,7 @@ public function test_detect_post_delete_when_not_visible() { $instance->register_hooks(); - wp_delete_post( self::$post_id ); + \wp_delete_post( self::$post_id ); } /** @@ -238,7 +236,7 @@ public function test_detect_post_delete_when_not_visible() { */ public function test_detect_term_delete() { $instance = $this - ->getMockBuilder( 'WPSEO_Slug_Change_Watcher' ) + ->getMockBuilder( WPSEO_Slug_Change_Watcher::class ) ->setMethods( [ 'add_notification' ] ) ->getMock(); @@ -248,7 +246,7 @@ public function test_detect_term_delete() { $instance->register_hooks(); - wp_delete_term( self::$category_id, 'category' ); + \wp_delete_term( self::$category_id, 'category' ); } /** @@ -258,7 +256,7 @@ public function test_detect_term_delete() { */ public function test_detect_term_delete_when_not_viewable() { $instance = $this - ->getMockBuilder( 'WPSEO_Slug_Change_Watcher' ) + ->getMockBuilder( WPSEO_Slug_Change_Watcher::class ) ->setMethods( [ 'add_notification' ] ) ->getMock(); @@ -268,7 +266,7 @@ public function test_detect_term_delete_when_not_viewable() { $instance->register_hooks(); - wp_delete_term( self::$nav_menu_id, 'nav_menu' ); + \wp_delete_term( self::$nav_menu_id, 'nav_menu' ); } /** @@ -278,7 +276,7 @@ public function test_detect_term_delete_when_not_viewable() { */ public function test_detect_term_delete_when_not_exists() { $instance = $this - ->getMockBuilder( 'WPSEO_Slug_Change_Watcher' ) + ->getMockBuilder( WPSEO_Slug_Change_Watcher::class ) ->setMethods( [ 'add_notification' ] ) ->getMock(); @@ -288,6 +286,6 @@ public function test_detect_term_delete_when_not_exists() { $instance->register_hooks(); - wp_delete_term( 11111, 'category' ); + \wp_delete_term( 11111, 'category' ); } } diff --git a/tests/WP/Admin/test-class-yoast-form.php b/tests/WP/Admin/Yoast_Form_Test.php similarity index 93% rename from tests/WP/Admin/test-class-yoast-form.php rename to tests/WP/Admin/Yoast_Form_Test.php index fd7846930a6..fbb0cf4895c 100644 --- a/tests/WP/Admin/test-class-yoast-form.php +++ b/tests/WP/Admin/Yoast_Form_Test.php @@ -1,10 +1,8 @@ set_option( 'random' ); diff --git a/tests/WP/Capabilities/test-class-capability-manager-factory.php b/tests/WP/Capability/Manager_Factory_Test.php similarity index 76% rename from tests/WP/Capabilities/test-class-capability-manager-factory.php rename to tests/WP/Capability/Manager_Factory_Test.php index 2a06ce12000..bbd8ac86f66 100644 --- a/tests/WP/Capabilities/test-class-capability-manager-factory.php +++ b/tests/WP/Capability/Manager_Factory_Test.php @@ -1,16 +1,14 @@ filter_roles( 'capability', [ 'role' ] ); - remove_filter( 'capability_roles', [ $this, 'do_filter_roles' ] ); + \remove_filter( 'capability_roles', [ $this, 'do_filter_roles' ] ); $this->assertEquals( $this->do_filter_roles( [ 'role' ] ), $filtered ); } diff --git a/tests/WP/Capabilities/test-class-register-capabilities.php b/tests/WP/Capability/Register_Capabilities_Test.php similarity index 88% rename from tests/WP/Capabilities/test-class-register-capabilities.php rename to tests/WP/Capability/Register_Capabilities_Test.php index a224790ce98..380e25eff1b 100644 --- a/tests/WP/Capabilities/test-class-register-capabilities.php +++ b/tests/WP/Capability/Register_Capabilities_Test.php @@ -1,16 +1,16 @@ user->create_and_get( [ 'role' => 'administrator' ] ); - grant_super_admin( $user->ID ); + \grant_super_admin( $user->ID ); } else { $user = self::factory()->user->create_and_get( [ 'role' => $role ] ); diff --git a/tests/WP/Content_Type_Visibility/test-class-content-type-dismiss-new-route.php b/tests/WP/Content_Type_Visibility/Dismiss_New_Route_Test.php similarity index 97% rename from tests/WP/Content_Type_Visibility/test-class-content-type-dismiss-new-route.php rename to tests/WP/Content_Type_Visibility/Dismiss_New_Route_Test.php index e9953753471..8ad891349cc 100644 --- a/tests/WP/Content_Type_Visibility/test-class-content-type-dismiss-new-route.php +++ b/tests/WP/Content_Type_Visibility/Dismiss_New_Route_Test.php @@ -1,10 +1,11 @@ get_values(); $this->assertEquals( 'Readability', $result['contentTab'] ); - $this->assertTrue( array_key_exists( 'contentLocale', $result ) ); - $this->assertTrue( array_key_exists( 'translations', $result ) ); - $this->assertTrue( is_array( $result['translations'] ) ); + $this->assertTrue( \array_key_exists( 'contentLocale', $result ) ); + $this->assertTrue( \array_key_exists( 'translations', $result ) ); + $this->assertTrue( \is_array( $result['translations'] ) ); } /** @@ -46,11 +46,11 @@ public function test_getting_the_values() { * @covers WPSEO_Metabox_Formatter::get_translations */ public function test_with_fake_language_file() { - $file_name = WPSEO_PATH . 'languages/wordpress-seo-' . get_user_locale() . '.json'; + $file_name = \WPSEO_PATH . 'languages/wordpress-seo-' . \get_user_locale() . '.json'; // Make sure the folder exists. - wp_mkdir_p( WPSEO_PATH . 'languages' ); - file_put_contents( + \wp_mkdir_p( \WPSEO_PATH . 'languages' ); + \file_put_contents( $file_name, WPSEO_Utils::format_json_encode( [ 'key' => 'value' ] ) ); @@ -65,11 +65,11 @@ public function test_with_fake_language_file() { $result = $class_instance->get_values(); - $this->assertTrue( array_key_exists( 'translations', $result ) ); - $this->assertTrue( is_array( $result['translations'] ) ); + $this->assertTrue( \array_key_exists( 'translations', $result ) ); + $this->assertTrue( \is_array( $result['translations'] ) ); $this->assertEquals( [ 'key' => 'value' ], $result['translations'] ); - unlink( $file_name ); + \unlink( $file_name ); $result = $class_instance->get_values(); @@ -83,7 +83,7 @@ public function test_with_fake_language_file() { * @covers Yoast\WP\SEO\Helpers\Language_Helper::is_word_form_recognition_active */ public function test_word_form_recognition_is_active() { - add_filter( + \add_filter( 'locale', static function() { return 'en_US'; @@ -111,7 +111,7 @@ static function() { * @covers Yoast\WP\SEO\Helpers\Language_Helper::is_word_form_recognition_active */ public function test_word_form_recognition_is_not_active() { - add_filter( + \add_filter( 'locale', static function() { return 'af_ZA'; diff --git a/tests/WP/Formatter/test-post-metabox-formatter.php b/tests/WP/Formatter/Post_Metabox_Formatter_Test.php similarity index 85% rename from tests/WP/Formatter/test-post-metabox-formatter.php rename to tests/WP/Formatter/Post_Metabox_Formatter_Test.php index 690d139c24d..b7028ceab7c 100644 --- a/tests/WP/Formatter/test-post-metabox-formatter.php +++ b/tests/WP/Formatter/Post_Metabox_Formatter_Test.php @@ -1,16 +1,15 @@ get_values(); - $this->assertEquals( $result['search_url'], admin_url( 'edit.php?seo_kw_filter={keyword}' ) ); - $this->assertEquals( $result['post_edit_url'], admin_url( 'post.php?post={id}&action=edit' ) ); - $this->assertEquals( $result['base_url'], YoastSEO()->helpers->url->home() ); + $this->assertEquals( $result['search_url'], \admin_url( 'edit.php?seo_kw_filter={keyword}' ) ); + $this->assertEquals( $result['post_edit_url'], \admin_url( 'post.php?post={id}&action=edit' ) ); + $this->assertEquals( $result['base_url'], \YoastSEO()->helpers->url->home() ); } /** @@ -79,7 +78,7 @@ public function test_metabox_metadescription_date() { $instance = new WPSEO_Post_Metabox_Formatter( $this->post, [], '' ); $result = $instance->get_values(); - $this->assertEquals( $result['metaDescriptionDate'], date_i18n( 'M j, Y', mysql2date( 'U', $this->post->post_date ) ) ); + $this->assertEquals( $result['metaDescriptionDate'], \date_i18n( 'M j, Y', \mysql2date( 'U', $this->post->post_date ) ) ); $this->assertEquals( $result['title_template'], 'This is the title' ); $this->assertEquals( $result['metadesc_template'], 'This is the metadescription' ); } @@ -97,7 +96,7 @@ public function test_post_on_add_page() { $instance = new WPSEO_Post_Metabox_Formatter( $this->post, [], '' ); $result = $instance->get_values(); - $this->assertEquals( $result['base_url'], YoastSEO()->helpers->url->home() ); + $this->assertEquals( $result['base_url'], \YoastSEO()->helpers->url->home() ); unset( $GLOBALS['pagenow'] ); } @@ -138,6 +137,6 @@ public function test_with_unreplaceble_permalink_structure() { $instance = new WPSEO_Post_Metabox_Formatter( $this->post, [], '%isnotreplaced%/' ); $result = $instance->get_values(); - $this->assertEquals( $result['base_url'], YoastSEO()->helpers->url->home() ); + $this->assertEquals( $result['base_url'], \YoastSEO()->helpers->url->home() ); } } diff --git a/tests/WP/Formatter/test-term-metabox-formatter.php b/tests/WP/Formatter/Term_Metabox_Formatter_Test.php similarity index 81% rename from tests/WP/Formatter/test-term-metabox-formatter.php rename to tests/WP/Formatter/Term_Metabox_Formatter_Test.php index 6f36206d2f2..d320ebdf541 100644 --- a/tests/WP/Formatter/test-term-metabox-formatter.php +++ b/tests/WP/Formatter/Term_Metabox_Formatter_Test.php @@ -1,16 +1,15 @@ term = $this->factory->term->create_and_get(); - $this->taxonomy = get_taxonomy( $this->term->taxonomy ); + $this->taxonomy = \get_taxonomy( $this->term->taxonomy ); } /** @@ -46,9 +45,9 @@ public function test_no_taxonomy_no_term_and_no_options() { $instance = new WPSEO_Term_Metabox_Formatter( null, null, [] ); $result = $instance->get_values(); - $this->assertFalse( array_key_exists( 'search_url', $result ) ); - $this->assertFalse( array_key_exists( 'post_edit_url', $result ) ); - $this->assertFalse( array_key_exists( 'base_url', $result ) ); + $this->assertFalse( \array_key_exists( 'search_url', $result ) ); + $this->assertFalse( \array_key_exists( 'post_edit_url', $result ) ); + $this->assertFalse( \array_key_exists( 'base_url', $result ) ); } /** @@ -71,10 +70,10 @@ public function test_with_taxonomy_and_term_and_without_options() { $result = $instance->get_values(); - $this->assertEquals( $result['search_url'], admin_url( 'edit-tags.php?taxonomy=' . $this->term->taxonomy . '&seo_kw_filter={keyword}' ) ); - $this->assertEquals( $result['post_edit_url'], admin_url( 'term.php?action=edit&taxonomy=' . $this->term->taxonomy . '&tag_ID={id}' ) ); + $this->assertEquals( $result['search_url'], \admin_url( 'edit-tags.php?taxonomy=' . $this->term->taxonomy . '&seo_kw_filter={keyword}' ) ); + $this->assertEquals( $result['post_edit_url'], \admin_url( 'term.php?action=edit&taxonomy=' . $this->term->taxonomy . '&tag_ID={id}' ) ); - $this->assertEquals( trailingslashit( home_url( 'tag' ) ), $result['base_url'] ); + $this->assertEquals( \trailingslashit( \home_url( 'tag' ) ), $result['base_url'] ); $this->assertEquals( [ '' => [] ], $result['keyword_usage'] ); $this->assertEquals( '%%term_title%% Archives %%page%% %%sep%% %%sitename%%', $result['title_template'] ); $this->assertEquals( '', $result['metadesc_template'] ); diff --git a/tests/WP/test-class-wpseo-breadcrumbs.php b/tests/WP/Frontend/Breadcrumbs_Test.php similarity index 88% rename from tests/WP/test-class-wpseo-breadcrumbs.php rename to tests/WP/Frontend/Breadcrumbs_Test.php index 802345a6510..20958485b96 100644 --- a/tests/WP/test-class-wpseo-breadcrumbs.php +++ b/tests/WP/Frontend/Breadcrumbs_Test.php @@ -1,16 +1,14 @@ This is a post. It has several images:

diff --git a/tests/WP/Frontend/test-front-end-integration.php b/tests/WP/Frontend/Front_End_Integration_Test.php similarity index 96% rename from tests/WP/Frontend/test-front-end-integration.php rename to tests/WP/Frontend/Front_End_Integration_Test.php index 4210ebbed98..30a70e73f7c 100644 --- a/tests/WP/Frontend/test-front-end-integration.php +++ b/tests/WP/Frontend/Front_End_Integration_Test.php @@ -1,10 +1,9 @@ attachment->create(); - update_post_meta( + \update_post_meta( $attachment, '_wp_attachment_metadata', [ @@ -51,7 +49,7 @@ public function test_get_full_image() { */ public function test_get_medium_image() { $attachment = self::factory()->attachment->create(); - update_post_meta( + \update_post_meta( $attachment, '_wp_attachment_metadata', [ @@ -187,7 +185,7 @@ public function test_absolute_path( $input, $expected, $message = '' ) { * @return array Data. */ public function data_get_absolute_path() { - $uploads = wp_get_upload_dir(); + $uploads = \wp_get_upload_dir(); return [ [ diff --git a/tests/WP/test-wpseo-functions.php b/tests/WP/Functions_Test.php similarity index 92% rename from tests/WP/test-wpseo-functions.php rename to tests/WP/Functions_Test.php index c411c335287..182b6136232 100644 --- a/tests/WP/test-wpseo-functions.php +++ b/tests/WP/Functions_Test.php @@ -1,16 +1,11 @@ 'Post_Content', 'post_excerpt' => 'Post_Excerpt', 'post_author' => $user_id, - 'post_date' => date( 'Y-m-d H:i:s', strtotime( '2000-01-01 2:30:00' ) ), + 'post_date' => \date( 'Y-m-d H:i:s', \strtotime( '2000-01-01 2:30:00' ) ), ] ); // Get post. - $post = get_post( $post_id ); + $post = \get_post( $post_id ); $input = '%%title%% %%excerpt%% %%date%% %%name%%'; - $expected = 'Post_Title Post_Excerpt ' . mysql2date( get_option( 'date_format' ), $post->post_date, true ) . ' User_Nicename'; - $output = wpseo_replace_vars( $input, (array) $post ); + $expected = 'Post_Title Post_Excerpt ' . \mysql2date( \get_option( 'date_format' ), $post->post_date, true ) . ' User_Nicename'; + $output = \wpseo_replace_vars( $input, (array) $post ); $this->assertSame( $expected, $output ); /* @@ -71,11 +66,11 @@ public function test_wpseo_replace_vars() { * @return void */ public function test_wpseo_replace_vars_excerpt( $post_data, $locale, $expected, $required_php_version = '' ) { - if ( $required_php_version !== '' && version_compare( PHP_VERSION, $required_php_version, '<' ) ) { + if ( $required_php_version !== '' && \version_compare( \PHP_VERSION, $required_php_version, '<' ) ) { $this->markTestSkipped( 'This test requires PHP ' . $required_php_version . ' or higher' ); } - add_filter( + \add_filter( 'locale', static function () use ( $locale ) { return $locale; @@ -84,13 +79,13 @@ static function () use ( $locale ) { $post = null; // Create post. - if ( is_array( $post_data ) ) { + if ( \is_array( $post_data ) ) { $post_id = $this->factory->post->create( $post_data ); - $post = get_post( $post_id ); + $post = \get_post( $post_id ); } $input = 'The replaced excerpt: %%excerpt%%'; - $output = wpseo_replace_vars( $input, (array) $post ); + $output = \wpseo_replace_vars( $input, (array) $post ); $this->assertSame( $expected, $output ); } @@ -217,7 +212,7 @@ public function provide_excerpt_replace_var_data() { yield 'Trims leading and trailing newlines when generating an excerpt' => [ 'post_data' => [ - 'post_content' => PHP_EOL . 'excerpt is generated from post content' . PHP_EOL, + 'post_content' => \PHP_EOL . 'excerpt is generated from post content' . \PHP_EOL, 'post_excerpt' => '', ], 'locale' => 'ja', @@ -226,7 +221,7 @@ public function provide_excerpt_replace_var_data() { yield 'Trims a combination of leading and trailing whitespace characters when generating an excerpt' => [ 'post_data' => [ - 'post_content' => "\n\r \t excerpt is generated from post content \n\r \n \r \t " . PHP_EOL, + 'post_content' => "\n\r \t excerpt is generated from post content \n\r \n \r \t " . \PHP_EOL, 'post_excerpt' => '', ], 'locale' => 'en', @@ -236,7 +231,7 @@ public function provide_excerpt_replace_var_data() { yield 'Doesn\'t trim unicode whitespaces characters when generating an excerpt' => [ 'post_data' => [ // phpcs:ignore PHPCompatibility.TextStrings.NewUnicodeEscapeSequence -- This test is only ran on PHP 7 and up. - 'post_content' => "excerpt is generated from post content \u{2002} " . PHP_EOL, + 'post_content' => "excerpt is generated from post content \u{2002} " . \PHP_EOL, 'post_excerpt' => '', ], 'locale' => 'en', @@ -264,7 +259,7 @@ public function provide_excerpt_replace_var_data() { * @return void */ public function test_wpseo_get_capabilities() { - $capabilities = wpseo_get_capabilities(); + $capabilities = \wpseo_get_capabilities(); $this->assertIsArray( $capabilities ); } diff --git a/tests/WP/Helpers/test-first-time-configuration-notice-helper.php b/tests/WP/Helpers/First_Time_Configuration_Notice_Helper_Test.php similarity index 97% rename from tests/WP/Helpers/test-first-time-configuration-notice-helper.php rename to tests/WP/Helpers/First_Time_Configuration_Notice_Helper_Test.php index 550dbaa18ea..2666f7b9f5f 100644 --- a/tests/WP/Helpers/test-first-time-configuration-notice-helper.php +++ b/tests/WP/Helpers/First_Time_Configuration_Notice_Helper_Test.php @@ -1,17 +1,14 @@ andReturn( $is_initial_indexing ); $user = self::factory()->user->create_and_get( [ 'role' => $user_role ] ); - wp_set_current_user( $user->ID ); + \wp_set_current_user( $user->ID ); $this->options_helper->set( 'first_time_install', $first_time_install ); diff --git a/tests/WP/Inc/test-class-wpseo-admin-bar-menu.php b/tests/WP/Inc/Admin_Bar_Menu_Test.php similarity index 80% rename from tests/WP/Inc/test-class-wpseo-admin-bar-menu.php rename to tests/WP/Inc/Admin_Bar_Menu_Test.php index f5724c14f68..0dcc376bf7c 100644 --- a/tests/WP/Inc/test-class-wpseo-admin-bar-menu.php +++ b/tests/WP/Inc/Admin_Bar_Menu_Test.php @@ -1,17 +1,21 @@ user->create( [ 'role' => 'editor' ] ); - get_userdata( self::$wpseo_manager )->add_cap( 'wpseo_manage_options' ); + \get_userdata( self::$wpseo_manager )->add_cap( 'wpseo_manage_options' ); self::$network_administrator = $factory->user->create( [ 'role' => 'administrator' ] ); - grant_super_admin( self::$network_administrator ); + \grant_super_admin( self::$network_administrator ); } /** @@ -67,7 +71,7 @@ public static function wpSetUpBeforeClass( $factory ) { * @return void */ public static function wpTearDownAfterClass() { - revoke_super_admin( self::$network_administrator ); + \revoke_super_admin( self::$network_administrator ); self::delete_user( self::$network_administrator ); self::delete_user( self::$wpseo_manager ); } @@ -79,7 +83,7 @@ public static function wpTearDownAfterClass() { */ public function test_add_menu_lacking_capabilities() { $admin_bar_menu = $this - ->getMockBuilder( 'WPSEO_Admin_Bar_Menu' ) + ->getMockBuilder( WPSEO_Admin_Bar_Menu::class ) ->setConstructorArgs( [ $this->get_asset_manager() ] ) ->setMethods( $this->mock_wpseo_admin_bar_menu_methods ) ->getMock(); @@ -121,12 +125,12 @@ public function test_add_menu_lacking_capabilities() { * @covers WPSEO_Admin_Bar_Menu::add_menu */ public function test_add_menu() { - wp_set_current_user( self::$wpseo_manager ); + \wp_set_current_user( self::$wpseo_manager ); $wp_admin_bar = new WP_Admin_Bar(); $admin_bar_menu = $this - ->getMockBuilder( 'WPSEO_Admin_Bar_Menu' ) + ->getMockBuilder( WPSEO_Admin_Bar_Menu::class ) ->setConstructorArgs( [ $this->get_asset_manager() ] ) ->setMethods( $this->mock_wpseo_admin_bar_menu_methods ) ->getMock(); @@ -174,7 +178,7 @@ public function test_add_menu() { * @covers WPSEO_Admin_Bar_Menu::enqueue_assets */ public function test_enqueue_assets_without_admin_bar() { - add_filter( 'show_admin_bar', '__return_false' ); + \add_filter( 'show_admin_bar', '__return_false' ); $asset_manager = $this->get_asset_manager( [ 'register_assets', 'enqueue_style' ] ); @@ -196,8 +200,8 @@ public function test_enqueue_assets_without_admin_bar() { * @covers WPSEO_Admin_Bar_Menu::enqueue_assets */ public function test_enqueue_assets() { - add_filter( 'show_admin_bar', '__return_true' ); - wp_set_current_user( self::$wpseo_manager ); + \add_filter( 'show_admin_bar', '__return_true' ); + \wp_set_current_user( self::$wpseo_manager ); $asset_manager = $this->get_asset_manager( [ 'register_assets', 'enqueue_style' ] ); @@ -220,7 +224,7 @@ public function test_enqueue_assets() { * @covers WPSEO_Admin_Bar_Menu::register_hooks */ public function test_register_hooks() { - $admin_bar_menu = $this->getMockBuilder( 'WPSEO_Admin_Bar_Menu' ) + $admin_bar_menu = $this->getMockBuilder( WPSEO_Admin_Bar_Menu::class ) ->setConstructorArgs( [ $this->get_asset_manager() ] ) ->setMethods( [ 'meets_requirements' ] ) ->getMock(); @@ -231,9 +235,9 @@ public function test_register_hooks() { ->will( $this->returnValue( true ) ); $admin_bar_menu->register_hooks(); - $this->assertIsInt( has_action( 'admin_bar_menu', [ $admin_bar_menu, 'add_menu' ], 95 ) ); - $this->assertIsInt( has_action( 'wp_enqueue_scripts', [ $admin_bar_menu, 'enqueue_assets' ] ) ); - $this->assertIsInt( has_action( 'admin_enqueue_scripts', [ $admin_bar_menu, 'enqueue_assets' ] ) ); + $this->assertIsInt( \has_action( 'admin_bar_menu', [ $admin_bar_menu, 'add_menu' ], 95 ) ); + $this->assertIsInt( \has_action( 'wp_enqueue_scripts', [ $admin_bar_menu, 'enqueue_assets' ] ) ); + $this->assertIsInt( \has_action( 'admin_enqueue_scripts', [ $admin_bar_menu, 'enqueue_assets' ] ) ); } /** @@ -246,15 +250,15 @@ public function test_meets_requirements() { WPSEO_Options::get_instance(); - add_filter( 'option_wpseo', [ $this, 'filter_enable_admin_bar_menu_false' ], 9999 ); - add_filter( 'default_option_wpseo', [ $this, 'filter_enable_admin_bar_menu_false' ], 9999 ); + \add_filter( 'option_wpseo', [ $this, 'filter_enable_admin_bar_menu_false' ], 9999 ); + \add_filter( 'default_option_wpseo', [ $this, 'filter_enable_admin_bar_menu_false' ], 9999 ); WPSEO_Options::clear_cache(); $first_result = $admin_bar_menu->meets_requirements(); $this->assertFalse( $first_result ); - add_filter( 'option_wpseo', [ $this, 'filter_enable_admin_bar_menu_true' ], 10000 ); - add_filter( 'default_option_wpseo', [ $this, 'filter_enable_admin_bar_menu_true' ], 10000 ); + \add_filter( 'option_wpseo', [ $this, 'filter_enable_admin_bar_menu_true' ], 10000 ); + \add_filter( 'default_option_wpseo', [ $this, 'filter_enable_admin_bar_menu_true' ], 10000 ); WPSEO_Options::clear_cache(); $second_result = $admin_bar_menu->meets_requirements(); @@ -305,7 +309,7 @@ public function test_get_post_focus_keyword_with_valid_object_but_no_id_property * @covers WPSEO_Admin_Bar_Menu::get_post_focus_keyword */ public function test_get_post_focus_keyword_with_page_analysis_filter_disabled() { - add_filter( 'wpseo_use_page_analysis', '__return_false' ); + \add_filter( 'wpseo_use_page_analysis', '__return_false' ); $post = self::factory()->post->create_and_get(); $instance = new Admin_Bar_Menu_Double(); @@ -348,12 +352,12 @@ public function filter_enable_admin_bar_menu_false( $result ) { */ protected function get_asset_manager( array $mock_methods = [] ) { if ( empty( $mock_methods ) ) { - return new WPSEO_Admin_Asset_Manager( new WPSEO_Admin_Asset_SEO_Location( WP_PLUGIN_DIR . '/wordpress-seo/wp-seo.php' ) ); + return new WPSEO_Admin_Asset_Manager( new WPSEO_Admin_Asset_SEO_Location( \WP_PLUGIN_DIR . '/wordpress-seo/wp-seo.php' ) ); } return $this - ->getMockBuilder( 'WPSEO_Admin_Asset_Manager' ) - ->setConstructorArgs( [ new WPSEO_Admin_Asset_SEO_Location( WP_PLUGIN_DIR . '/wordpress-seo/wp-seo.php' ) ] ) + ->getMockBuilder( WPSEO_Admin_Asset_Manager::class ) + ->setConstructorArgs( [ new WPSEO_Admin_Asset_SEO_Location( \WP_PLUGIN_DIR . '/wordpress-seo/wp-seo.php' ) ] ) ->setMethods( $mock_methods ) ->getMock(); } diff --git a/tests/WP/test-class-wpseo-meta.php b/tests/WP/Inc/Meta_Test.php similarity index 86% rename from tests/WP/test-class-wpseo-meta.php rename to tests/WP/Inc/Meta_Test.php index 6d3501ccf10..e4845ce4177 100644 --- a/tests/WP/test-class-wpseo-meta.php +++ b/tests/WP/Inc/Meta_Test.php @@ -1,10 +1,8 @@ factory->post->create(); - $this->go_to( get_permalink( $post_id ) ); + $this->go_to( \get_permalink( $post_id ) ); WPSEO_Meta::set_value( 'test_set_value_key', 'test_set_value_value', $post_id ); - $this->assertEquals( 'test_set_value_value', get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'test_set_value_key', true ) ); + $this->assertEquals( 'test_set_value_value', \get_post_meta( $post_id, WPSEO_Meta::$meta_prefix . 'test_set_value_key', true ) ); } /** @@ -37,12 +35,12 @@ public function test_get_value() { // Create and go to post. $post_id = $this->factory->post->create(); - $this->go_to( get_permalink( $post_id ) ); + $this->go_to( \get_permalink( $post_id ) ); $key = 'test_get_value_key'; $this->register_meta_key( $key ); - update_post_meta( $post_id, WPSEO_Meta::$meta_prefix . $key, 'test_get_value_value' ); + \update_post_meta( $post_id, WPSEO_Meta::$meta_prefix . $key, 'test_get_value_value' ); $this->assertEquals( 'test_get_value_value', WPSEO_Meta::get_value( $key ) ); } @@ -64,12 +62,12 @@ public function test_get_value_non_registered_field() { // Create and go to post. $post_id = $this->factory->post->create(); - $this->go_to( get_permalink( $post_id ) ); + $this->go_to( \get_permalink( $post_id ) ); $key = 'non_registered_key'; // The field exists on the post - because it will be saved. - update_post_meta( $post_id, WPSEO_Meta::$meta_prefix . $key, 'some_value' ); + \update_post_meta( $post_id, WPSEO_Meta::$meta_prefix . $key, 'some_value' ); // As the field is not registered, we should ignore the value in the database. $this->assertEquals( 'some_value', WPSEO_Meta::get_value( $key ) ); @@ -88,12 +86,12 @@ public function test_get_value_unregistered_field_serialized() { // Create and go to post. $post_id = $this->factory->post->create(); - $this->go_to( get_permalink( $post_id ) ); + $this->go_to( \get_permalink( $post_id ) ); $key = 'non_registered_key_array'; // The field exists on the post - because it will be saved. - update_post_meta( $post_id, WPSEO_Meta::$meta_prefix . $key, [ 'some_value' ] ); + \update_post_meta( $post_id, WPSEO_Meta::$meta_prefix . $key, [ 'some_value' ] ); // As the field is not registered, we should ignore the value in the database. $this->assertEquals( '', WPSEO_Meta::get_value( $key ) ); @@ -108,7 +106,7 @@ public function test_get_value_non_existing_key() { // Create and go to post. $post_id = $this->factory->post->create(); - $this->go_to( get_permalink( $post_id ) ); + $this->go_to( \get_permalink( $post_id ) ); // The post meta is never saved, so it is totally unknown. $key = 'non_existing_key_2'; @@ -122,7 +120,7 @@ public function test_get_value_non_existing_key() { */ public function test_set_value_slashed() { $post_id = $this->factory->post->create(); - $this->go_to( get_permalink( $post_id ) ); + $this->go_to( \get_permalink( $post_id ) ); $key = 'test_set_value_key_slashed'; $this->register_meta_key( $key ); @@ -142,7 +140,7 @@ public function test_set_value_slashed() { */ public function test_get_and_set_value_slashed_array() { $post_id = $this->factory->post->create(); - $this->go_to( get_permalink( $post_id ) ); + $this->go_to( \get_permalink( $post_id ) ); $key = 'test_set_value_key_slashed_array'; $this->register_meta_key( $key, true ); @@ -162,13 +160,13 @@ public function test_get_and_set_value_slashed_array() { */ public function test_get_and_set_value_serialized_and_slashed_array() { $post_id = $this->factory->post->create(); - $this->go_to( get_permalink( $post_id ) ); + $this->go_to( \get_permalink( $post_id ) ); $key = 'test_set_value_key_slashed_array'; $this->register_meta_key( $key, true ); $array = [ 'ke\\y' => '""slashed data" \\"' ]; - $value = serialize( $array ); + $value = \serialize( $array ); WPSEO_Meta::set_value( $key, $value, $post_id ); $this->assertEquals( $value, WPSEO_Meta::get_value( $key, $post_id ) ); @@ -190,10 +188,10 @@ public function test_remove_meta_if_default() { // Set post meta to default value. $default_value = WPSEO_Meta::$defaults[ $key ]; - update_post_meta( $post_id, $key, $default_value ); + \update_post_meta( $post_id, $key, $default_value ); // Default post meta should not be saved. - $meta_value = get_post_meta( $post_id, $key, true ); + $meta_value = \get_post_meta( $post_id, $key, true ); $this->assertEquals( '', $meta_value ); } @@ -205,17 +203,17 @@ public function test_remove_meta_if_default() { public function test_dont_save_meta_if_default() { // Create and go to post. $post_id = $this->factory->post->create(); - $this->go_to( get_permalink( $post_id ) ); + $this->go_to( \get_permalink( $post_id ) ); // Generate key. $key = WPSEO_Meta::$meta_prefix . 'meta-robots-noindex'; // Add default value to post_meta. $default_value = WPSEO_Meta::$defaults[ $key ]; - add_post_meta( $post_id, $key, $default_value ); + \add_post_meta( $post_id, $key, $default_value ); // Default post meta should not be saved. - $meta_value = get_post_meta( $post_id, $key ); + $meta_value = \get_post_meta( $post_id, $key ); $this->assertEquals( [], $meta_value ); } diff --git a/tests/WP/Inc/test-class-myyoast-api-request.php b/tests/WP/Inc/MyYoast_Api_Request_Test.php similarity index 90% rename from tests/WP/Inc/test-class-myyoast-api-request.php rename to tests/WP/Inc/MyYoast_Api_Request_Test.php index 71f684ef82c..37a61656f85 100644 --- a/tests/WP/Inc/test-class-myyoast-api-request.php +++ b/tests/WP/Inc/MyYoast_Api_Request_Test.php @@ -1,10 +1,11 @@ getMockBuilder( 'WPSEO_MyYoast_Api_Request' ) + ->getMockBuilder( WPSEO_MyYoast_Api_Request::class ) ->setMethods( [ 'do_request', 'decode_response' ] ) ->setConstructorArgs( [ 'endpoint' ] ) ->getMock(); @@ -50,7 +51,7 @@ public function test_fire() { */ public function test_fire_with_bad_request_exception_being_thrown() { $instance = $this - ->getMockBuilder( 'WPSEO_MyYoast_Api_Request' ) + ->getMockBuilder( WPSEO_MyYoast_Api_Request::class ) ->setMethods( [ 'do_request', 'decode_response' ] ) ->setConstructorArgs( [ 'endpoint' ] ) ->getMock(); @@ -77,7 +78,7 @@ public function test_fire_with_bad_request_exception_being_thrown() { */ public function test_decode_response() { $instance = $this - ->getMockBuilder( 'WPSEO_MyYoast_Api_Request' ) + ->getMockBuilder( WPSEO_MyYoast_Api_Request::class ) ->setMethods( [ 'do_request' ] ) ->setConstructorArgs( [ 'endpoint' ] ) ->getMock(); @@ -104,7 +105,7 @@ public function test_decode_response() { */ public function test_decode_response_wrong_output() { $instance = $this - ->getMockBuilder( 'WPSEO_MyYoast_Api_Request' ) + ->getMockBuilder( WPSEO_MyYoast_Api_Request::class ) ->setMethods( [ 'do_request' ] ) ->setConstructorArgs( [ 'endpoint' ] ) ->getMock(); @@ -214,12 +215,12 @@ public function test_exception_arguments() { $this->expectException( WPSEO_MyYoast_Bad_Request_Exception::class ); $this->expectExceptionMessage( 'Error' ); - add_filter( 'pre_http_request', [ $this, 'return_error_object' ] ); + \add_filter( 'pre_http_request', [ $this, 'return_error_object' ] ); $instance = new MyYoast_Api_Request_Double( 'some_url', [] ); $instance->do_request( 'some_url', [] ); - remove_filter( 'pre_http_request', [ $this, 'return_error_object' ] ); + \remove_filter( 'pre_http_request', [ $this, 'return_error_object' ] ); } /** diff --git a/tests/WP/Inc/Options/test-class-wpseo-option.php b/tests/WP/Inc/Options/Option_Test.php similarity index 70% rename from tests/WP/Inc/Options/test-class-wpseo-option.php rename to tests/WP/Inc/Options/Option_Test.php index 5a889805149..4f21cd755c1 100644 --- a/tests/WP/Inc/Options/test-class-wpseo-option.php +++ b/tests/WP/Inc/Options/Option_Test.php @@ -1,16 +1,15 @@ assertEqualSets( $expected, array_intersect_key( $options, $expected ) ); + $expected = \array_fill_keys( $option_vars, true ); + $this->assertEqualSets( $expected, \array_intersect_key( $options, $expected ) ); foreach ( $option_vars as $option_var ) { // Ensure the variable is disabled via the network. @@ -47,9 +46,9 @@ public function test_prevent_disabled_options_update() { } // Unhook filters so that we can get the actual unaltered option value. - remove_all_filters( 'option_wpseo' ); + \remove_all_filters( 'option_wpseo' ); $options = WPSEO_Options::get_option( 'wpseo' ); - $expected = array_fill_keys( $option_vars, true ); - $this->assertEqualSets( $expected, array_intersect_key( $options, $expected ) ); + $expected = \array_fill_keys( $option_vars, true ); + $this->assertEqualSets( $expected, \array_intersect_key( $options, $expected ) ); } } diff --git a/tests/WP/Inc/Options/test-class-wpseo-option-titles.php b/tests/WP/Inc/Options/Option_Titles_Test.php similarity index 55% rename from tests/WP/Inc/Options/test-class-wpseo-option-titles.php rename to tests/WP/Inc/Options/Option_Titles_Test.php index e4f98aa92c8..19786632159 100644 --- a/tests/WP/Inc/Options/test-class-wpseo-option-titles.php +++ b/tests/WP/Inc/Options/Option_Titles_Test.php @@ -1,16 +1,14 @@ true ] ); + \register_post_type( 'custom-post-type', [ 'public' => true ] ); $this->assertArrayHasKey( 'title-custom-post-type', $wpseo_option_titles->get_defaults() ); - register_taxonomy( 'custom-taxonomy', 'post' ); + \register_taxonomy( 'custom-taxonomy', 'post' ); $this->assertArrayHasKey( 'title-tax-custom-taxonomy', $wpseo_option_titles->get_defaults() ); - unregister_taxonomy( 'custom-taxonomy' ); - unregister_post_type( 'custom-post-type' ); + \unregister_taxonomy( 'custom-taxonomy' ); + \unregister_post_type( 'custom-post-type' ); } } diff --git a/tests/WP/Inc/Options/test-class-wpseo-option-wpseo.php b/tests/WP/Inc/Options/Option_WPSEO_Test.php similarity index 70% rename from tests/WP/Inc/Options/test-class-wpseo-option-wpseo.php rename to tests/WP/Inc/Options/Option_WPSEO_Test.php index 023498b714e..2196a689194 100644 --- a/tests/WP/Inc/Options/test-class-wpseo-option-wpseo.php +++ b/tests/WP/Inc/Options/Option_WPSEO_Test.php @@ -1,16 +1,15 @@ skipWithoutMultisite(); $options = WPSEO_Options::get_option( 'wpseo' ); - $expected = array_fill_keys( $this->feature_vars, true ); + $expected = \array_fill_keys( $this->feature_vars, true ); $expected['zapier_integration_active'] = false; $expected['ryte_indexability'] = false; - $this->assertEqualSets( $expected, array_intersect_key( $options, $expected ) ); + $this->assertEqualSets( $expected, \array_intersect_key( $options, $expected ) ); // Ensure the variables are disabled via the network. foreach ( $this->feature_vars as $feature_var ) { @@ -53,12 +52,12 @@ public function test_verify_features_against_network() { // Test method directly. $options = WPSEO_Options::get_option_instance( 'wpseo' )->verify_features_against_network( $options ); - $expected = array_fill_keys( $this->feature_vars, false ); - $this->assertEqualSets( $expected, array_intersect_key( $options, $expected ) ); + $expected = \array_fill_keys( $this->feature_vars, false ); + $this->assertEqualSets( $expected, \array_intersect_key( $options, $expected ) ); // Test method integration with filters. $options = WPSEO_Options::get_option( 'wpseo' ); - $expected = array_fill_keys( $this->feature_vars, false ); - $this->assertEqualSets( $expected, array_intersect_key( $options, $expected ) ); + $expected = \array_fill_keys( $this->feature_vars, false ); + $this->assertEqualSets( $expected, \array_intersect_key( $options, $expected ) ); } } diff --git a/tests/WP/Inc/Options/test-class-wpseo-options.php b/tests/WP/Inc/Options/Options_Test.php similarity index 92% rename from tests/WP/Inc/Options/test-class-wpseo-options.php rename to tests/WP/Inc/Options/Options_Test.php index 19a1eb563b5..76b2fd0c312 100644 --- a/tests/WP/Inc/Options/test-class-wpseo-options.php +++ b/tests/WP/Inc/Options/Options_Test.php @@ -1,16 +1,15 @@ assertTrue( $result ); @@ -152,7 +151,7 @@ public function test_set_works() { $option_before = WPSEO_Options::get_option( 'wpseo' ); $option_before['keyword_analysis_active'] = true; $option_before['show_onboarding_notice'] = false; - update_option( 'wpseo', $option_before ); + \update_option( 'wpseo', $option_before ); // Turn them around and see if they still return the correct value. WPSEO_Options::set( 'keyword_analysis_active', false ); @@ -174,16 +173,16 @@ public function test_make_sure_keys_are_unique_over_options() { $keys = []; // Make sure the backfilling is not being done when determining "real" unique option names. - remove_all_actions( 'option_wpseo' ); - remove_all_actions( 'option_wpseo_titles' ); + \remove_all_actions( 'option_wpseo' ); + \remove_all_actions( 'option_wpseo_titles' ); - foreach ( array_keys( WPSEO_Options::$options ) as $option_name ) { - $option_keys = array_keys( WPSEO_Options::get_option( $option_name ) ); - $intersected = array_intersect( $option_keys, $keys ); + foreach ( \array_keys( WPSEO_Options::$options ) as $option_name ) { + $option_keys = \array_keys( WPSEO_Options::get_option( $option_name ) ); + $intersected = \array_intersect( $option_keys, $keys ); $this->assertEquals( [], $intersected, 'Option keys must be unique (' . $option_name . ').' ); - $keys = array_merge( $keys, $option_keys ); + $keys = \array_merge( $keys, $option_keys ); } } diff --git a/tests/WP/Inc/Options/test-class-wpseo-taxonomy-meta.php b/tests/WP/Inc/Options/Taxonomy_Meta_Test.php similarity index 97% rename from tests/WP/Inc/Options/test-class-wpseo-taxonomy-meta.php rename to tests/WP/Inc/Options/Taxonomy_Meta_Test.php index 2def2743b60..84316458fc0 100644 --- a/tests/WP/Inc/Options/test-class-wpseo-taxonomy-meta.php +++ b/tests/WP/Inc/Options/Taxonomy_Meta_Test.php @@ -1,16 +1,15 @@ true ] ); + \register_post_type( 'custom-post-type', [ 'public' => true ] ); $this->assertContains( 'custom-post-type', WPSEO_Post_Type::get_accessible_post_types() ); } @@ -52,7 +51,7 @@ public function test_get_accessible_post_types_with_a_custom_post_type() { * @covers WPSEO_Post_Type::get_accessible_post_types */ public function test_get_accessible_post_types_with_a_custom_post_type_that_is_noy_publicly_queryable() { - register_post_type( + \register_post_type( 'hidden-post-type', [ 'public' => true, @@ -69,7 +68,7 @@ public function test_get_accessible_post_types_with_a_custom_post_type_that_is_n * @covers WPSEO_Post_Type::get_accessible_post_types */ public function test_get_accessible_post_types_with_a_custom_private_post_type() { - register_post_type( 'custom-post-type', [ 'public' => false ] ); + \register_post_type( 'custom-post-type', [ 'public' => false ] ); $this->assertNotContains( 'custom-post-type', WPSEO_Post_Type::get_accessible_post_types() ); } @@ -80,7 +79,7 @@ public function test_get_accessible_post_types_with_a_custom_private_post_type() * @covers WPSEO_Post_Type::get_accessible_post_types */ public function test_get_accessible_post_types_with_a_non_indexable_post_type() { - $custom_post_type = register_post_type( 'custom-post-type', [ 'public' => true ] ); + $custom_post_type = \register_post_type( 'custom-post-type', [ 'public' => true ] ); WPSEO_Options::set( 'noindex-' . $custom_post_type->name, true ); @@ -94,7 +93,7 @@ public function test_get_accessible_post_types_with_a_non_indexable_post_type() * @covers WPSEO_Post_Type::get_accessible_post_types */ public function test_get_accessible_post_types_with_an_indexable_post_type() { - $custom_post_type = register_post_type( 'custom-post-type', [ 'public' => true ] ); + $custom_post_type = \register_post_type( 'custom-post-type', [ 'public' => true ] ); WPSEO_Options::set( 'noindex-' . $custom_post_type->name, false ); @@ -109,9 +108,9 @@ public function test_get_accessible_post_types_with_an_indexable_post_type() { public function test_get_accessible_post_types_with_a_filter_hook() { $this->assertContains( 'attachment', WPSEO_Post_Type::get_accessible_post_types() ); - add_filter( 'wpseo_accessible_post_types', [ $this, 'filter_attachment' ] ); + \add_filter( 'wpseo_accessible_post_types', [ $this, 'filter_attachment' ] ); $this->assertNotContains( 'attachment', WPSEO_Post_Type::get_accessible_post_types() ); - remove_filter( 'wpseo_accessible_post_types', [ $this, 'filter_attachment' ] ); + \remove_filter( 'wpseo_accessible_post_types', [ $this, 'filter_attachment' ] ); } /** @@ -120,11 +119,11 @@ public function test_get_accessible_post_types_with_a_filter_hook() { * @covers WPSEO_Post_Type::get_accessible_post_types */ public function test_get_accessible_post_types_with_a_filter_hook_that_returns_wrong_type() { - add_filter( 'wpseo_accessible_post_types', '__return_true' ); + \add_filter( 'wpseo_accessible_post_types', '__return_true' ); $this->assertEquals( [], WPSEO_Post_Type::get_accessible_post_types() ); - remove_filter( 'wpseo_accessible_post_types', '__return_true' ); + \remove_filter( 'wpseo_accessible_post_types', '__return_true' ); } /** @@ -133,7 +132,7 @@ public function test_get_accessible_post_types_with_a_filter_hook_that_returns_w * @covers WPSEO_Post_Type::is_post_type_indexable */ public function test_is_post_type_indexable_with_indexable_post_type() { - $custom_post_type = register_post_type( 'custom-post-type', [ 'public' => true ] ); + $custom_post_type = \register_post_type( 'custom-post-type', [ 'public' => true ] ); WPSEO_Options::set( 'noindex-' . $custom_post_type->name, false ); @@ -146,7 +145,7 @@ public function test_is_post_type_indexable_with_indexable_post_type() { * @covers WPSEO_Post_Type::is_post_type_indexable */ public function test_is_post_type_indexable_with_non_indexable_post_type() { - $custom_post_type = register_post_type( 'custom-post-type', [ 'public' => true ] ); + $custom_post_type = \register_post_type( 'custom-post-type', [ 'public' => true ] ); WPSEO_Options::set( 'noindex-' . $custom_post_type->name, true ); @@ -192,7 +191,7 @@ public function test_rest_enabled_post_types() { $this->assertTrue( WPSEO_Post_Type::is_rest_enabled( 'post' ) ); $this->assertFalse( WPSEO_Post_Type::is_rest_enabled( 'invalid_post_type' ) ); - register_post_type( + \register_post_type( 'custom-post-type-api', [ 'public' => true, @@ -201,7 +200,7 @@ public function test_rest_enabled_post_types() { ); $this->assertTrue( WPSEO_Post_Type::is_rest_enabled( 'custom-post-type-api' ) ); - register_post_type( 'custom-post-type', [ 'public' => true ] ); + \register_post_type( 'custom-post-type', [ 'public' => true ] ); $this->assertFalse( WPSEO_Post_Type::is_rest_enabled( 'custom-post-type' ) ); } } diff --git a/tests/WP/Inc/test-class-wpseo-primary-term.php b/tests/WP/Inc/Primary_Term_Test.php similarity index 84% rename from tests/WP/Inc/test-class-wpseo-primary-term.php rename to tests/WP/Inc/Primary_Term_Test.php index b1f1b1057ab..858d9293859 100644 --- a/tests/WP/Inc/test-class-wpseo-primary-term.php +++ b/tests/WP/Inc/Primary_Term_Test.php @@ -1,17 +1,15 @@ factory->post->create( [ 'post_category' => [ $term_first->term_id, $term_second->term_id ] ] ); @@ -99,6 +97,6 @@ public function test_set_primary_term_UPDATES_post_meta() { $class_instance->set_primary_term( $this->primary_term_id ); - $this->assertEquals( [ $this->primary_term_id ], get_post_meta( $this->post_id, '_yoast_wpseo_primary_' . $this->taxonomy_name ) ); + $this->assertEquals( [ $this->primary_term_id ], \get_post_meta( $this->post_id, '_yoast_wpseo_primary_' . $this->taxonomy_name ) ); } } diff --git a/tests/WP/test-class-wpseo-rank.php b/tests/WP/Inc/Rank_Test.php similarity index 97% rename from tests/WP/test-class-wpseo-rank.php rename to tests/WP/Inc/Rank_Test.php index 1649d8e073d..9ae0eaf123c 100644 --- a/tests/WP/test-class-wpseo-rank.php +++ b/tests/WP/Inc/Rank_Test.php @@ -1,16 +1,14 @@ assertInstanceOf( 'WPSEO_Rank', $rank ); + $this->assertInstanceOf( WPSEO_Rank::class, $rank ); } } @@ -325,7 +323,7 @@ public function test_get_all_readability_ranks() { $ranks = WPSEO_Rank::get_all_readability_ranks(); foreach ( $ranks as $rank ) { - $this->assertInstanceOf( 'WPSEO_Rank', $rank ); + $this->assertInstanceOf( WPSEO_Rank::class, $rank ); } } @@ -338,7 +336,7 @@ public function test_get_all_inclusive_language_ranks() { $ranks = WPSEO_Rank::get_all_inclusive_language_ranks(); foreach ( $ranks as $rank ) { - $this->assertInstanceOf( 'WPSEO_Rank', $rank ); + $this->assertInstanceOf( WPSEO_Rank::class, $rank ); } } } diff --git a/tests/WP/test-class-rewrite.php b/tests/WP/Inc/Rewrite_Test.php similarity index 82% rename from tests/WP/test-class-rewrite.php rename to tests/WP/Inc/Rewrite_Test.php index 43867db0d8f..aa0d887ac74 100644 --- a/tests/WP/test-class-rewrite.php +++ b/tests/WP/Inc/Rewrite_Test.php @@ -1,16 +1,15 @@ schedule_flush(); - $this->assertIsInt( has_action( 'shutdown', 'flush_rewrite_rules' ) ); + $this->assertIsInt( \has_action( 'shutdown', 'flush_rewrite_rules' ) ); } /** @@ -52,7 +51,7 @@ public function test_schedule_flush() { public function test_no_category_base() { $input = 'http://yoast.com/cat/link/'; - $category_base = get_option( 'category_base' ); + $category_base = \get_option( 'category_base' ); if ( empty( $category_base ) ) { $category_base = 'category'; @@ -62,13 +61,13 @@ public function test_no_category_base() { * Remove initial slash, if there is one (we remove the trailing slash in * the regex replacement and don't want to end up short a slash). */ - if ( substr( $category_base, 0, 1 ) === '/' ) { - $category_base = substr( $category_base, 1 ); + if ( \substr( $category_base, 0, 1 ) === '/' ) { + $category_base = \substr( $category_base, 1 ); } $category_base .= '/'; - $expected = preg_replace( '`' . preg_quote( $category_base, '`' ) . '`u', '', $input, 1 ); + $expected = \preg_replace( '`' . \preg_quote( $category_base, '`' ) . '`u', '', $input, 1 ); $this->assertEquals( $expected, self::$class_instance->no_category_base( $input, null, 'category' ) ); // Passing null as 2nd parameter as it is not used. } @@ -92,7 +91,7 @@ public function test_query_vars() { public function test_request_with_empty_query_vars() { $instance = $this - ->getMockBuilder( 'WPSEO_Rewrite' ) + ->getMockBuilder( WPSEO_Rewrite::class ) ->setMethods( [ 'redirect' ] ) ->getMock(); $instance @@ -112,7 +111,7 @@ public function test_request_with_empty_query_vars() { public function test_request_with_query_vars() { $instance = $this - ->getMockBuilder( 'WPSEO_Rewrite' ) + ->getMockBuilder( WPSEO_Rewrite::class ) ->setMethods( [ 'redirect' ] ) ->getMock(); $instance @@ -132,9 +131,9 @@ public function test_category_rewrite_rules() { $c = self::$class_instance; - $permalink_structure = get_option( 'permalink_structure' ); + $permalink_structure = \get_option( 'permalink_structure' ); - if ( ! ( is_multisite() && strpos( $permalink_structure, '/blog/' ) === 0 ) ) { + if ( ! ( \is_multisite() && \strpos( $permalink_structure, '/blog/' ) === 0 ) ) { $expected = [ '(uncategorized)/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$' => 'index.php?category_name=$matches[1]&feed=$matches[2]', '(uncategorized)/page/?([0-9]{1,})/?$' => 'index.php?category_name=$matches[1]&paged=$matches[2]', @@ -150,7 +149,7 @@ public function test_category_rewrite_rules() { } global $wp_rewrite; - $old_base = trim( str_replace( '%category%', '(.+)', $wp_rewrite->get_category_permastruct() ), '/' ); + $old_base = \trim( \str_replace( '%category%', '(.+)', $wp_rewrite->get_category_permastruct() ), '/' ); $expected[ $old_base . '$' ] = 'index.php?wpseo_category_redirect=$matches[1]'; diff --git a/tests/WP/test-class-wpseo-statistics.php b/tests/WP/Inc/Statistics_Test.php similarity index 70% rename from tests/WP/test-class-wpseo-statistics.php rename to tests/WP/Inc/Statistics_Test.php index 08d9d4a6c04..45550142ee8 100644 --- a/tests/WP/test-class-wpseo-statistics.php +++ b/tests/WP/Inc/Statistics_Test.php @@ -1,16 +1,15 @@ factory->post->create_many( 2, $this->default_post_args ); - add_post_meta( $posts[1], '_yoast_wpseo_focuskw', 'focus keyword' ); + \add_post_meta( $posts[1], '_yoast_wpseo_focuskw', 'focus keyword' ); $this->assertEquals( 1, $this->instance->get_post_count( new WPSEO_Rank( WPSEO_Rank::NO_FOCUS ) ) ); } @@ -71,10 +70,10 @@ public function test_filled_statistics_no_focus() { public function test_filled_statistics_bad() { $posts = $this->factory->post->create_many( 4, $this->default_post_args ); - add_post_meta( $posts[0], '_yoast_wpseo_linkdex', 0 ); // Not bad. - add_post_meta( $posts[1], '_yoast_wpseo_linkdex', 1 ); // Bad. - add_post_meta( $posts[2], '_yoast_wpseo_linkdex', 40 ); // Bad. - add_post_meta( $posts[3], '_yoast_wpseo_linkdex', 41 ); // Not bad. + \add_post_meta( $posts[0], '_yoast_wpseo_linkdex', 0 ); // Not bad. + \add_post_meta( $posts[1], '_yoast_wpseo_linkdex', 1 ); // Bad. + \add_post_meta( $posts[2], '_yoast_wpseo_linkdex', 40 ); // Bad. + \add_post_meta( $posts[3], '_yoast_wpseo_linkdex', 41 ); // Not bad. $this->assertEquals( 2, $this->instance->get_post_count( new WPSEO_Rank( WPSEO_Rank::BAD ) ) ); } @@ -87,10 +86,10 @@ public function test_filled_statistics_bad() { public function test_filled_statistics_ok() { $posts = $this->factory->post->create_many( 4, $this->default_post_args ); - add_post_meta( $posts[0], '_yoast_wpseo_linkdex', 40 ); // Not OK. - add_post_meta( $posts[1], '_yoast_wpseo_linkdex', 41 ); // OK. - add_post_meta( $posts[2], '_yoast_wpseo_linkdex', 70 ); // OK. - add_post_meta( $posts[3], '_yoast_wpseo_linkdex', 71 ); // Not OK. + \add_post_meta( $posts[0], '_yoast_wpseo_linkdex', 40 ); // Not OK. + \add_post_meta( $posts[1], '_yoast_wpseo_linkdex', 41 ); // OK. + \add_post_meta( $posts[2], '_yoast_wpseo_linkdex', 70 ); // OK. + \add_post_meta( $posts[3], '_yoast_wpseo_linkdex', 71 ); // Not OK. $this->assertEquals( 2, $this->instance->get_post_count( new WPSEO_Rank( WPSEO_Rank::OK ) ) ); } @@ -103,10 +102,10 @@ public function test_filled_statistics_ok() { public function test_filled_statistics_good() { $posts = $this->factory->post->create_many( 4, $this->default_post_args ); - add_post_meta( $posts[0], '_yoast_wpseo_linkdex', 70 ); // Not good. - add_post_meta( $posts[1], '_yoast_wpseo_linkdex', 71 ); // Good. - add_post_meta( $posts[2], '_yoast_wpseo_linkdex', 100 ); // Good. - add_post_meta( $posts[3], '_yoast_wpseo_linkdex', 101 ); // Not good. + \add_post_meta( $posts[0], '_yoast_wpseo_linkdex', 70 ); // Not good. + \add_post_meta( $posts[1], '_yoast_wpseo_linkdex', 71 ); // Good. + \add_post_meta( $posts[2], '_yoast_wpseo_linkdex', 100 ); // Good. + \add_post_meta( $posts[3], '_yoast_wpseo_linkdex', 101 ); // Not good. $this->assertEquals( 2, $this->instance->get_post_count( new WPSEO_Rank( WPSEO_Rank::GOOD ) ) ); } @@ -119,16 +118,16 @@ public function test_filled_statistics_good() { public function test_all_statistics_published_posts() { $posts = $this->factory->post->create_many( 4, $this->default_post_args ); - add_post_meta( $posts[0], '_yoast_wpseo_linkdex', 0 ); // No-focus. - add_post_meta( $posts[0], '_yoast_wpseo_linkdex', 1 ); // Bad. + \add_post_meta( $posts[0], '_yoast_wpseo_linkdex', 0 ); // No-focus. + \add_post_meta( $posts[0], '_yoast_wpseo_linkdex', 1 ); // Bad. - add_post_meta( $posts[1], '_yoast_wpseo_linkdex', 41 ); // OK. - add_post_meta( $posts[1], '_yoast_wpseo_focuskw', 'focus keyword' ); + \add_post_meta( $posts[1], '_yoast_wpseo_linkdex', 41 ); // OK. + \add_post_meta( $posts[1], '_yoast_wpseo_focuskw', 'focus keyword' ); - add_post_meta( $posts[2], '_yoast_wpseo_linkdex', 71 ); // Good. - add_post_meta( $posts[2], '_yoast_wpseo_focuskw', 'focus keyword' ); + \add_post_meta( $posts[2], '_yoast_wpseo_linkdex', 71 ); // Good. + \add_post_meta( $posts[2], '_yoast_wpseo_focuskw', 'focus keyword' ); - add_post_meta( $posts[3], '_yoast_wpseo_focuskw', 'focus keyword' ); + \add_post_meta( $posts[3], '_yoast_wpseo_focuskw', 'focus keyword' ); $this->assertEquals( 1, $this->instance->get_post_count( new WPSEO_Rank( WPSEO_Rank::BAD ) ) ); $this->assertEquals( 1, $this->instance->get_post_count( new WPSEO_Rank( WPSEO_Rank::OK ) ) ); @@ -144,10 +143,10 @@ public function test_all_statistics_published_posts() { public function test_only_published_posts() { $posts = $this->factory->post->create_many( 4, [ 'post_status' => 'draft' ] ); - add_post_meta( $posts[0], '_yoast_wpseo_linkdex', 0 ); // No-focus. - add_post_meta( $posts[0], '_yoast_wpseo_linkdex', 1 ); // Bad. - add_post_meta( $posts[1], '_yoast_wpseo_linkdex', 41 ); // OK. - add_post_meta( $posts[2], '_yoast_wpseo_linkdex', 71 ); // Good. + \add_post_meta( $posts[0], '_yoast_wpseo_linkdex', 0 ); // No-focus. + \add_post_meta( $posts[0], '_yoast_wpseo_linkdex', 1 ); // Bad. + \add_post_meta( $posts[1], '_yoast_wpseo_linkdex', 41 ); // OK. + \add_post_meta( $posts[2], '_yoast_wpseo_linkdex', 71 ); // Good. $this->assertEquals( 0, $this->instance->get_post_count( new WPSEO_Rank( WPSEO_Rank::BAD ) ) ); $this->assertEquals( 0, $this->instance->get_post_count( new WPSEO_Rank( WPSEO_Rank::OK ) ) ); @@ -164,7 +163,7 @@ public function test_no_index_statistics() { $posts = $this->factory->post->create_many( 7, $this->default_post_args ); foreach ( $posts as $post_id ) { - add_post_meta( $post_id, '_yoast_wpseo_meta-robots-noindex', '1' ); + \add_post_meta( $post_id, '_yoast_wpseo_meta-robots-noindex', '1' ); } $this->assertEquals( 7, $this->instance->get_post_count( new WPSEO_Rank( WPSEO_Rank::NO_INDEX ) ) ); diff --git a/tests/WP/Inc/test-class-wpseo-upgrade-history.php b/tests/WP/Inc/Upgrade_History_Test.php similarity index 90% rename from tests/WP/Inc/test-class-wpseo-upgrade-history.php rename to tests/WP/Inc/Upgrade_History_Test.php index 601b93e1a5b..fce82b8c92b 100644 --- a/tests/WP/Inc/test-class-wpseo-upgrade-history.php +++ b/tests/WP/Inc/Upgrade_History_Test.php @@ -1,10 +1,8 @@ get_instance(); $upgrade_history->add( '1.0.0', '2.0.0', [ 'mock_option_name' ] ); - delete_option( 'mock_option_name' ); + \delete_option( 'mock_option_name' ); $history = $upgrade_history->get(); - $entry = current( $history ); + $entry = \current( $history ); $this->assertArrayHasKey( 'old_version', $entry ); $this->assertArrayHasKey( 'new_version', $entry ); @@ -111,7 +109,7 @@ public function test_add_no_options() { $upgrade_history->add( '1.0.0', '2.0.0', [] ); $history = $upgrade_history->get(); - $entry = current( $history ); + $entry = \current( $history ); $this->assertIsArray( $entry, 'There should be an entry added.' ); $this->assertArrayHasKey( 'options', $entry ); @@ -130,7 +128,7 @@ public function test_add_empty_option() { $upgrade_history->add( '1.0.0', '2.0.0', [ 'option_does_not_exist' ] ); $history = $upgrade_history->get(); - $entry = current( $history ); + $entry = \current( $history ); $this->assertIsArray( $entry, 'There should be an entry added.' ); $this->assertArrayHasKey( 'options', $entry ); diff --git a/tests/WP/Inc/test-class-wpseo-upgrade.php b/tests/WP/Inc/Upgrade_Test.php similarity index 79% rename from tests/WP/Inc/test-class-wpseo-upgrade.php rename to tests/WP/Inc/Upgrade_Test.php index 1bc2333435a..8654ca539d3 100644 --- a/tests/WP/Inc/test-class-wpseo-upgrade.php +++ b/tests/WP/Inc/Upgrade_Test.php @@ -1,10 +1,9 @@ get_instance(); - update_option( 'some_option', $content ); + \update_option( 'some_option', $content ); $this->assertEquals( $content, $instance->get_option_from_database( 'some_option' ) ); } @@ -59,14 +58,14 @@ public function test_get_option_from_database_no_filters_applied() { $instance = $this->get_instance(); - update_option( 'some_option', $content ); + \update_option( 'some_option', $content ); - add_filter( 'pre_option_some_option', [ $this, 'return_override' ] ); + \add_filter( 'pre_option_some_option', [ $this, 'return_override' ] ); - $this->assertEquals( $this->return_override(), get_option( 'some_option' ) ); + $this->assertEquals( $this->return_override(), \get_option( 'some_option' ) ); $this->assertEquals( $content, $instance->get_option_from_database( 'some_option' ) ); - remove_filter( 'pre_option_some_option', [ $this, 'return_override' ] ); + \remove_filter( 'pre_option_some_option', [ $this, 'return_override' ] ); } /** @@ -90,20 +89,20 @@ public function test_cleanup_option_data() { $original = [ 'invalid_key' => true, - 'version' => WPSEO_VERSION, + 'version' => \WPSEO_VERSION, ]; // Set option with invalid keys in the database. $this->set_option_in_database( 'wpseo', $original ); // The key should be present on the option. - $this->assertArrayHasKey( 'invalid_key', get_option( 'wpseo' ) ); + $this->assertArrayHasKey( 'invalid_key', \get_option( 'wpseo' ) ); // Cleaning up the option. $instance->cleanup_option_data( 'wpseo' ); // Make sure the key has been removed. - $this->assertArrayNotHasKey( 'invalid_key', get_option( 'wpseo' ) ); + $this->assertArrayNotHasKey( 'invalid_key', \get_option( 'wpseo' ) ); } /** @@ -116,7 +115,7 @@ public function test_cleanup_option_data_no_data() { $instance->cleanup_option_data( 'random_option' ); - $this->assertNull( get_option( 'random_option', null ) ); + $this->assertNull( \get_option( 'random_option', null ) ); } /** @@ -169,19 +168,19 @@ public function test_save_option_setting_not_set() { public function test_finish_up() { $instance = $this->get_instance(); - delete_option( 'wpseo' ); - delete_option( 'wpseo_titles' ); - delete_option( 'wpseo_social' ); + \delete_option( 'wpseo' ); + \delete_option( 'wpseo_titles' ); + \delete_option( 'wpseo_social' ); $instance->finish_up(); - $this->assertEquals( WPSEO_VERSION, WPSEO_Options::get( 'version' ) ); - $this->assertTrue( has_action( 'shutdown', 'flush_rewrite_rules' ) > 0 ); + $this->assertEquals( \WPSEO_VERSION, WPSEO_Options::get( 'version' ) ); + $this->assertTrue( \has_action( 'shutdown', 'flush_rewrite_rules' ) > 0 ); // Ensure options exist. - $this->assertNotEmpty( get_option( 'wpseo' ) ); - $this->assertNotEmpty( get_option( 'wpseo_titles' ) ); - $this->assertNotEmpty( get_option( 'wpseo_social' ) ); + $this->assertNotEmpty( \get_option( 'wpseo' ) ); + $this->assertNotEmpty( \get_option( 'wpseo_titles' ) ); + $this->assertNotEmpty( \get_option( 'wpseo_social' ) ); } /** @@ -209,7 +208,7 @@ private function set_option_in_database( $option_name, $option_value ) { [ 'option_name' => $option_name, // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize -- Reason: There's no security risk, because users don't interact with tests. - 'option_value' => serialize( $option_value ), + 'option_value' => \serialize( $option_value ), ], [ 'option_name' => $option_name ] ); diff --git a/tests/WP/test-class-wpseo-utils.php b/tests/WP/Inc/Utils_Test.php similarity index 96% rename from tests/WP/test-class-wpseo-utils.php rename to tests/WP/Inc/Utils_Test.php index 41c66cac75a..fc8f0d0072e 100644 --- a/tests/WP/test-class-wpseo-utils.php +++ b/tests/WP/Inc/Utils_Test.php @@ -1,16 +1,14 @@ assertEquals( $expected, WPSEO_Utils::retrieve_enabled_features() ); } @@ -169,7 +167,7 @@ public function test_retrieve_enabled_features_with_filter() { public function filter_wpseo_enable_feature( $enabled_features ) { $second_array = [ 'OTHER_FEATURE', 'ANOTHER_FEATURE' ]; - return array_merge( $enabled_features, $second_array ); + return \array_merge( $enabled_features, $second_array ); } /** diff --git a/tests/WP/Notifications/test-class-yoast-notification-center.php b/tests/WP/Notifications/Yoast_Notification_Center_Test.php similarity index 89% rename from tests/WP/Notifications/test-class-yoast-notification-center.php rename to tests/WP/Notifications/Yoast_Notification_Center_Test.php index 2f67a244a21..43190383426 100644 --- a/tests/WP/Notifications/test-class-yoast-notification-center.php +++ b/tests/WP/Notifications/Yoast_Notification_Center_Test.php @@ -1,12 +1,12 @@ user_id ); $user->add_cap( 'wpseo_manage_options' ); - wp_set_current_user( $this->user_id ); + \wp_set_current_user( $this->user_id ); } /** @@ -126,7 +126,7 @@ public function test_is_notification_dismissed() { $notification_dismissal_key = 'notification_dismissal'; $notification = new Yoast_Notification( 'dismiss', [ 'dismissal_key' => $notification_dismissal_key ] ); - update_user_meta( $this->user_id, $notification_dismissal_key, '1' ); + \update_user_meta( $this->user_id, $notification_dismissal_key, '1' ); $subject = $this->get_notification_center(); $this->assertTrue( $subject->is_notification_dismissed( $notification ) ); @@ -142,7 +142,7 @@ public function test_clear_dismissal() { $subject = $this->get_notification_center(); - update_user_meta( $this->user_id, $notification->get_dismissal_key(), '1' ); + \update_user_meta( $this->user_id, $notification->get_dismissal_key(), '1' ); $this->assertTrue( $subject->is_notification_dismissed( $notification ) ); @@ -161,7 +161,7 @@ public function test_clear_dismissal_as_string() { $subject = $this->get_notification_center(); - update_user_meta( $this->user_id, $notification->get_dismissal_key(), '1' ); + \update_user_meta( $this->user_id, $notification->get_dismissal_key(), '1' ); $this->assertTrue( $subject->is_notification_dismissed( $notification ) ); @@ -200,7 +200,7 @@ public function test_update_storage() { $subject->update_storage(); - $stored_notifications = get_user_option( Yoast_Notification_Center::STORAGE_KEY, $this->user_id ); + $stored_notifications = \get_user_option( Yoast_Notification_Center::STORAGE_KEY, $this->user_id ); $test = [ $notification->to_array() ]; @@ -221,7 +221,7 @@ public function test_update_storage_non_persistent() { $subject->update_storage(); - $stored_notifications = get_option( Yoast_Notification_Center::STORAGE_KEY ); + $stored_notifications = \get_option( Yoast_Notification_Center::STORAGE_KEY ); $this->assertFalse( $stored_notifications ); } @@ -356,7 +356,7 @@ public function test_display_notifications() { $options = []; $notification = $this - ->getMockBuilder( 'Yoast_Notification' ) + ->getMockBuilder( Yoast_Notification::class ) ->setConstructorArgs( [ $message, $options ] ) ->setMethods( [ 'display_for_current_user', '__toString' ] ) ->getMock(); @@ -388,7 +388,7 @@ public function test_display_notifications_not_for_current_user() { $options = []; $notification = $this - ->getMockBuilder( 'Yoast_Notification' ) + ->getMockBuilder( Yoast_Notification::class ) ->setConstructorArgs( [ $message, $options ] ) ->setMethods( [ 'display_for_current_user', '__toString' ] ) ->getMock(); @@ -428,7 +428,7 @@ public function test_display_dismissed_notification() { $notification = new Yoast_Notification( $message, $options ); // Dismiss the key for the current user. - update_user_meta( $this->user_id, $notification_dismissal_key, '1' ); + \update_user_meta( $this->user_id, $notification_dismissal_key, '1' ); // Add the notification. $subject = $this->get_notification_center(); @@ -466,7 +466,7 @@ public function test_update_nonce_on_re_add_notification() { $this->assertIsArray( $notifications ); - $notification = array_shift( $notifications ); + $notification = \array_shift( $notifications ); $this->assertNotEquals( $notification->get_nonce(), $old_nonce ); } @@ -501,7 +501,7 @@ public function test_resolved_notifications() { $count = $notification_center->get_resolved_notification_count(); // Apply max for static test problems. - $this->assertEquals( 0, max( 0, $count ) ); + $this->assertEquals( 0, \max( 0, $count ) ); } /** @@ -513,7 +513,7 @@ public function test_maybe_dismiss_notification() { $a = new Yoast_Notification( 'a' ); $this->assertFalse( Yoast_Notification_Center::maybe_dismiss_notification( $a ) ); - $b = new Yoast_Notification( 'b', [ 'id' => uniqid( 'id', true ) ] ); + $b = new Yoast_Notification( 'b', [ 'id' => \uniqid( 'id', true ) ] ); $this->assertFalse( Yoast_Notification_Center::maybe_dismiss_notification( $b ) ); } @@ -552,11 +552,11 @@ public function test_dismiss_notification_is_per_site() { // Dismiss notification for the current site. Yoast_Notification_Center::dismiss_notification( $notification ); - $site1_dismissed = (bool) get_user_option( $dismissal_key, $this->user_id ); + $site1_dismissed = (bool) \get_user_option( $dismissal_key, $this->user_id ); - switch_to_blog( $site2 ); - $site2_dismissed = (bool) get_user_option( $dismissal_key, $this->user_id ); - restore_current_blog(); + \switch_to_blog( $site2 ); + $site2_dismissed = (bool) \get_user_option( $dismissal_key, $this->user_id ); + \restore_current_blog(); $this->assertTrue( $site1_dismissed ); $this->assertFalse( $site2_dismissed ); @@ -578,19 +578,19 @@ public function test_restore_notification_is_per_site() { $dismissal_key = $notification->get_dismissal_key(); // Dismiss notification for both sites. - update_user_option( $this->user_id, $dismissal_key, 'seen' ); - switch_to_blog( $site2 ); - update_user_option( $this->user_id, $dismissal_key, 'seen' ); - restore_current_blog(); + \update_user_option( $this->user_id, $dismissal_key, 'seen' ); + \switch_to_blog( $site2 ); + \update_user_option( $this->user_id, $dismissal_key, 'seen' ); + \restore_current_blog(); // Restore notification for the current site. Yoast_Notification_Center::restore_notification( $notification ); - $site1_dismissed = (bool) get_user_option( $dismissal_key, $this->user_id ); + $site1_dismissed = (bool) \get_user_option( $dismissal_key, $this->user_id ); - switch_to_blog( $site2 ); - $site2_dismissed = (bool) get_user_option( $dismissal_key, $this->user_id ); - restore_current_blog(); + \switch_to_blog( $site2 ); + $site2_dismissed = (bool) \get_user_option( $dismissal_key, $this->user_id ); + \restore_current_blog(); $this->assertFalse( $site1_dismissed ); $this->assertTrue( $site2_dismissed ); @@ -612,13 +612,13 @@ public function test_is_notification_dismissed_is_per_site() { $dismissal_key = $notification->get_dismissal_key(); // Dismiss notification for the current site. - update_user_option( $this->user_id, $dismissal_key, 'seen' ); + \update_user_option( $this->user_id, $dismissal_key, 'seen' ); $site1_dismissed = Yoast_Notification_Center::is_notification_dismissed( $notification ); - switch_to_blog( $site2 ); + \switch_to_blog( $site2 ); $site2_dismissed = Yoast_Notification_Center::is_notification_dismissed( $notification ); - restore_current_blog(); + \restore_current_blog(); $this->assertTrue( $site1_dismissed ); $this->assertFalse( $site2_dismissed ); @@ -635,15 +635,15 @@ public function test_is_notification_dismissed_falls_back_to_user_meta() { $dismissal_key = $notification->get_dismissal_key(); // Dismiss notification in the old incorrect way. - update_user_meta( $this->user_id, $dismissal_key, 'seen' ); + \update_user_meta( $this->user_id, $dismissal_key, 'seen' ); $dismissed = Yoast_Notification_Center::is_notification_dismissed( $notification ); $this->assertTrue( $dismissed ); // Ensure the old user metadata has been migrated on-the-fly. - $this->assertSame( 'seen', get_user_option( $dismissal_key, $this->user_id ) ); - $this->assertEmpty( get_user_meta( $this->user_id, $dismissal_key, true ) ); + $this->assertSame( 'seen', \get_user_option( $dismissal_key, $this->user_id ) ); + $this->assertEmpty( \get_user_meta( $this->user_id, $dismissal_key, true ) ); } /** @@ -657,8 +657,8 @@ public function test_restore_notification_clears_user_meta() { $dismissal_key = $notification->get_dismissal_key(); // Set notification dismissed in both user option and old user meta way. - update_user_option( $this->user_id, $dismissal_key, 'seen' ); - update_user_meta( $this->user_id, $dismissal_key, 'seen' ); + \update_user_option( $this->user_id, $dismissal_key, 'seen' ); + \update_user_meta( $this->user_id, $dismissal_key, 'seen' ); $this->assertTrue( Yoast_Notification_Center::restore_notification( $notification ) ); } @@ -684,7 +684,7 @@ public function test_retrieve_notifications_from_storage_strips_nonces() { $expected[ $sample_notification->get_id() ] = null; } - update_user_option( get_current_user_id(), Yoast_Notification_Center::STORAGE_KEY, $storage_data ); + \update_user_option( \get_current_user_id(), Yoast_Notification_Center::STORAGE_KEY, $storage_data ); $notification_center->setup_current_notifications(); @@ -693,7 +693,7 @@ public function test_retrieve_notifications_from_storage_strips_nonces() { $stored_notifications[ $index ] = $stored_notification->to_array(); } - $this->assertSame( $expected, wp_list_pluck( wp_list_pluck( $stored_notifications, 'options' ), 'nonce', 'id' ) ); + $this->assertSame( $expected, \wp_list_pluck( \wp_list_pluck( $stored_notifications, 'options' ), 'nonce', 'id' ) ); } /** @@ -704,10 +704,10 @@ public function test_retrieve_notifications_from_storage_strips_nonces() { public function test_update_storage_strips_nonces() { $notification_center = Yoast_Notification_Center::get(); - add_filter( 'yoast_notifications_before_storage', [ $this, 'get_sample_notifications' ] ); + \add_filter( 'yoast_notifications_before_storage', [ $this, 'get_sample_notifications' ] ); $notification_center->update_storage(); - $stored_notifications = get_user_option( Yoast_Notification_Center::STORAGE_KEY, get_current_user_id() ); + $stored_notifications = \get_user_option( Yoast_Notification_Center::STORAGE_KEY, \get_current_user_id() ); $expected = []; $sample_notifications = $this->get_sample_notifications(); @@ -715,7 +715,7 @@ public function test_update_storage_strips_nonces() { $expected[ $sample_notification->get_id() ] = null; } - $this->assertSame( $expected, wp_list_pluck( wp_list_pluck( $stored_notifications, 'options' ), 'nonce', 'id' ) ); + $this->assertSame( $expected, \wp_list_pluck( \wp_list_pluck( $stored_notifications, 'options' ), 'nonce', 'id' ) ); } /** @@ -725,7 +725,7 @@ public function test_update_storage_strips_nonces() { */ public function test_remove_notification_by_id_when_no_notification_is_found() { $notification_center = $this - ->getMockBuilder( 'Yoast_Notification_Center' ) + ->getMockBuilder( Yoast_Notification_Center::class ) ->disableOriginalConstructor() ->setMethods( [ 'remove_notification' ] ) ->getMock(); @@ -744,7 +744,7 @@ public function test_remove_notification_by_id_when_no_notification_is_found() { */ public function test_remove_notification_by_id_when_notification_is_found() { $notification_center = $this - ->getMockBuilder( 'Yoast_Notification_Center' ) + ->getMockBuilder( Yoast_Notification_Center::class ) ->disableOriginalConstructor() ->setMethods( [ 'remove_notification', 'get_notification_by_id' ] ) ->getMock(); diff --git a/tests/WP/Notifications/test-class-yoast-notification.php b/tests/WP/Notifications/Yoast_Notification_Test.php similarity index 95% rename from tests/WP/Notifications/test-class-yoast-notification.php rename to tests/WP/Notifications/Yoast_Notification_Test.php index 769778edae7..609532ea539 100644 --- a/tests/WP/Notifications/test-class-yoast-notification.php +++ b/tests/WP/Notifications/Yoast_Notification_Test.php @@ -1,11 +1,10 @@ factory->user->create_and_get(); $user->add_cap( 'wpseo_manage_options' ); - wp_set_current_user( $user->ID ); + \wp_set_current_user( $user->ID ); } /** @@ -54,7 +53,7 @@ public function test_not_persistent() { public function test_set_defaults() { $subject = new Yoast_Notification( 'message', [] ); $test = $subject->to_array(); - $user = wp_get_current_user(); + $user = \wp_get_current_user(); $this->assertEquals( [ @@ -100,7 +99,7 @@ public function test_nonce() { public function test_nonce_not_set() { $subject = new Yoast_Notification( 'message', [ 'id' => 'id' ] ); $nonce = $subject->get_nonce(); - $this->assertTrue( wp_verify_nonce( $nonce, 'id' ) !== false ); + $this->assertTrue( \wp_verify_nonce( $nonce, 'id' ) !== false ); } /** @@ -306,7 +305,7 @@ public function add_wpseo_notification_capabilities( $current_capabilities = [] * @param string $capability Capability to add. */ private function add_cap( $capability ) { - $me = wp_get_current_user(); + $me = \wp_get_current_user(); if ( ! empty( $me ) ) { $me->add_cap( $capability ); } @@ -318,7 +317,7 @@ private function add_cap( $capability ) { * @param string $capability Capability to remove. */ private function remove_cap( $capability ) { - $me = wp_get_current_user(); + $me = \wp_get_current_user(); if ( ! empty( $me ) ) { $me->remove_cap( $capability ); } diff --git a/tests/WP/Notifiers/test-class-dismissible-notification.php b/tests/WP/Notifiers/Dismissible_Notification_Test.php similarity index 94% rename from tests/WP/Notifiers/test-class-dismissible-notification.php rename to tests/WP/Notifiers/Dismissible_Notification_Test.php index 3be20b8c4d0..6ab5fe43987 100644 --- a/tests/WP/Notifiers/test-class-dismissible-notification.php +++ b/tests/WP/Notifiers/Dismissible_Notification_Test.php @@ -1,19 +1,17 @@ getMockBuilder( 'Yoast_Notification_Center' ) + ->getMockBuilder( Yoast_Notification_Center::class ) ->disableOriginalConstructor() ->setMethods( [ 'add_notification' ] ) ->getMock(); @@ -93,7 +91,7 @@ public function test_handle_where_situation_is_applicable() { */ public function test_handle_where_situation_is_not_applicable() { $notification_center = $this - ->getMockBuilder( 'Yoast_Notification_Center' ) + ->getMockBuilder( Yoast_Notification_Center::class ) ->disableOriginalConstructor() ->setMethods( [ 'remove_notification_by_id' ] ) ->getMock(); diff --git a/tests/WP/Repositories/test-class-seo-links-repository.php b/tests/WP/Repositories/SEO_Links_Repository_Test.php similarity index 99% rename from tests/WP/Repositories/test-class-seo-links-repository.php rename to tests/WP/Repositories/SEO_Links_Repository_Test.php index 99b2d0d931a..8f135fb4c30 100644 --- a/tests/WP/Repositories/test-class-seo-links-repository.php +++ b/tests/WP/Repositories/SEO_Links_Repository_Test.php @@ -1,9 +1,6 @@ instance->delete_many_by_id( $ids ); - $in = implode( ',', $ids ); + $in = \implode( ',', $ids ); $db = $wpdb->get_var( $wpdb->prepare( 'SELECT COUNT(*) FROM `' . $wpdb->prefix . 'yoast_seo_links` WHERE `id`IN (%s)', $in ) ); diff --git a/tests/WP/Sitemaps/test-class-wpseo-author-sitemap-provider.php b/tests/WP/Sitemaps/Author_Sitemap_Provider_Test.php similarity index 89% rename from tests/WP/Sitemaps/test-class-wpseo-author-sitemap-provider.php rename to tests/WP/Sitemaps/Author_Sitemap_Provider_Test.php index 41906786105..e9516e5e26b 100644 --- a/tests/WP/Sitemaps/test-class-wpseo-author-sitemap-provider.php +++ b/tests/WP/Sitemaps/Author_Sitemap_Provider_Test.php @@ -1,19 +1,19 @@ assertCount( 1, $sitemap_links ); // Makes sure it's the user we expected. - $this->assertContains( get_author_posts_url( $user_id ), wp_list_pluck( $sitemap_links, 'loc' ) ); + $this->assertContains( \get_author_posts_url( $user_id ), \wp_list_pluck( $sitemap_links, 'loc' ) ); } /** @@ -101,10 +101,10 @@ public function test_author_not_excluded_from_sitemap_by_zero_posts() { $this->assertCount( 3, $sitemap_links ); // Makes sure it are the users we expected. - $sitemap_urls = wp_list_pluck( $sitemap_links, 'loc' ); - $this->assertContains( get_author_posts_url( $author_id ), $sitemap_urls ); - $this->assertContains( get_author_posts_url( $admin_id ), $sitemap_urls ); - $this->assertContains( get_author_posts_url( $editor_id ), $sitemap_urls ); + $sitemap_urls = \wp_list_pluck( $sitemap_links, 'loc' ); + $this->assertContains( \get_author_posts_url( $author_id ), $sitemap_urls ); + $this->assertContains( \get_author_posts_url( $admin_id ), $sitemap_urls ); + $this->assertContains( \get_author_posts_url( $editor_id ), $sitemap_urls ); } /** @@ -123,7 +123,7 @@ public function test_author_exclusion() { $this->factory->post->create_many( 3, [ 'post_author' => $user_id ] ); // Excludes the user from the sitemaps. - update_user_meta( $user_id, 'wpseo_noindex_author', 'on' ); + \update_user_meta( $user_id, 'wpseo_noindex_author', 'on' ); // Checks which authors are in the sitemap, there should be none. self::$class_instance->get_sitemap_links( 'author', 10, 1 ); @@ -142,10 +142,10 @@ public function test_get_index_links_empty_sitemap() { WPSEO_Options::set( 'disable-author', false ); // Fetches the global sitemap. - set_query_var( 'sitemap', 'author' ); + \set_query_var( 'sitemap', 'author' ); // Sets the page to the second one, which should not contain an entry, and should not exist. - set_query_var( 'sitemap_n', '2' ); + \set_query_var( 'sitemap_n', '2' ); // Loads the sitemap. $sitemaps = new Sitemaps_Double(); @@ -165,7 +165,7 @@ public function test_get_index_links_disabled_archive() { WPSEO_Options::set( 'disable-author', true ); // Fetches the global sitemap. - set_query_var( 'sitemap', 'author' ); + \set_query_var( 'sitemap', 'author' ); // Loads the sitemap. $sitemaps = new Sitemaps_Double(); diff --git a/tests/WP/Sitemaps/test-class-wpseo-sitemaps-cache-data.php b/tests/WP/Sitemaps/Cache_Data_Test.php similarity index 94% rename from tests/WP/Sitemaps/test-class-wpseo-sitemaps-cache-data.php rename to tests/WP/Sitemaps/Cache_Data_Test.php index 040cd463338..eb43de5ea8b 100644 --- a/tests/WP/Sitemaps/test-class-wpseo-sitemaps-cache-data.php +++ b/tests/WP/Sitemaps/Cache_Data_Test.php @@ -1,18 +1,18 @@ subject->set_sitemap( $sitemap ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize -- Reason: There's no way for user input to get in between serialize and unserialize. - $tmp = serialize( $this->subject ); + $tmp = \serialize( $this->subject ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize -- Reason: There's no way for user input to get in between serialize and unserialize. - $test = unserialize( $tmp ); + $test = \unserialize( $tmp ); $this->assertEquals( $this->subject, $test ); } diff --git a/tests/WP/Sitemaps/test-class-wpseo-sitemaps-cache.php b/tests/WP/Sitemaps/Cache_Test.php similarity index 87% rename from tests/WP/Sitemaps/test-class-wpseo-sitemaps-cache.php rename to tests/WP/Sitemaps/Cache_Test.php index 7385f98e153..5e9ebc644aa 100644 --- a/tests/WP/Sitemaps/test-class-wpseo-sitemaps-cache.php +++ b/tests/WP/Sitemaps/Cache_Test.php @@ -1,24 +1,24 @@ assertEquals( $test, $result ); @@ -88,12 +88,12 @@ public function test_transient_string_to_cache_data() { $transient_key = WPSEO_Sitemaps_Cache_Validator::get_storage_key( $type, $page ); - set_transient( $transient_key, $sitemap, DAY_IN_SECONDS ); + \set_transient( $transient_key, $sitemap, \DAY_IN_SECONDS ); $cache = new WPSEO_Sitemaps_Cache(); $result = $cache->get_sitemap_data( $type, $page ); - $this->assertEquals( $sitemap, get_transient( $transient_key ) ); + $this->assertEquals( $sitemap, \get_transient( $transient_key ) ); $this->assertNull( $result ); } @@ -120,18 +120,18 @@ public function test_retrieving_transient_stored_in_php_lt_74() { * These functions are used in the get_sitemap[_data]() method to retrieve the transient. * This filter short-circuits those function calls to return the specific value we need for this test. */ - add_filter( + \add_filter( "pre_transient_{$transient_key}", static function ( $pre_transient ) { $pre_transient = 'C:24:"WPSEO_Sitemap_Cache_Data":107:{a:2:{s:6:"status";s:2:"ok";s:3:"xml";s:61:"this is a wpseo_sitemap_cache_data object stored in PHP < 7.4";}}'; - return maybe_unserialize( $pre_transient ); + return \maybe_unserialize( $pre_transient ); } ); $cache = new WPSEO_Sitemaps_Cache(); $result = $cache->get_sitemap_data( $type, $page ); - $this->assertInstanceOf( 'WPSEO_Sitemap_Cache_Data', $result ); + $this->assertInstanceOf( WPSEO_Sitemap_Cache_Data::class, $result ); $this->assertSame( $sitemap, $result->get_sitemap() ); $this->assertSame( 'ok', $result->get_status() ); } @@ -167,20 +167,20 @@ public function test_retrieving_transient_stored_in_php_gte_74() { * These functions are used in the get_sitemap[_data]() method to retrieve the transient. * This filter short-circuits those function calls to return the specific value we need for this test. */ - add_filter( + \add_filter( "pre_transient_{$transient_key}", static function ( $pre_transient ) { $pre_transient = 'O:24:"WPSEO_Sitemap_Cache_Data":2:{s:6:"status";s:2:"ok";s:3:"xml";s:62:"this is a wpseo_sitemap_cache_data object stored in PHP >= 7.4";}'; - return maybe_unserialize( $pre_transient ); + return \maybe_unserialize( $pre_transient ); } ); $cache = new WPSEO_Sitemaps_Cache(); $result = $cache->get_sitemap_data( $type, $page ); - if ( PHP_VERSION_ID >= 70400 ) { + if ( \PHP_VERSION_ID >= 70400 ) { // PHP 7.4+. - $this->assertInstanceOf( 'WPSEO_Sitemap_Cache_Data', $result ); + $this->assertInstanceOf( WPSEO_Sitemap_Cache_Data::class, $result ); $this->assertSame( $sitemap, $result->get_sitemap() ); $this->assertSame( 'ok', $result->get_status() ); } @@ -203,14 +203,14 @@ public function test_clear() { $test_content = 'test_content'; $cache_key = WPSEO_Sitemaps_Cache_Validator::get_storage_key( $type, $page ); - set_transient( $cache_key, $test_content ); + \set_transient( $cache_key, $test_content ); // Act. WPSEO_Sitemaps_Cache::clear(); WPSEO_Sitemaps_Cache::clear_queued(); $cache_key = WPSEO_Sitemaps_Cache_Validator::get_storage_key( $type, $page ); - $content = get_transient( $cache_key ); + $content = \get_transient( $cache_key ); // Assert. $this->assertEquals( $test_content, $content ); @@ -229,7 +229,7 @@ public function test_clear_type() { $test_content = 'test_content'; $cache_key = WPSEO_Sitemaps_Cache_Validator::get_storage_key( $type, $page ); - set_transient( $cache_key, $test_content ); + \set_transient( $cache_key, $test_content ); // Act. WPSEO_Sitemaps_Cache::clear( [ $type ] ); @@ -237,7 +237,7 @@ public function test_clear_type() { // Get the key again. $cache_key = WPSEO_Sitemaps_Cache_Validator::get_storage_key( $type, $page ); - $result = get_transient( $cache_key ); + $result = \get_transient( $cache_key ); // Assert. $this->assertEquals( $test_content, $result ); @@ -254,14 +254,14 @@ public function test_clear_index_also_cleared() { $test_index_content = 'test_content'; $index_cache_key = WPSEO_Sitemaps_Cache_Validator::get_storage_key(); - set_transient( $index_cache_key, $test_index_content ); + \set_transient( $index_cache_key, $test_index_content ); /* * The cache invalidator is based on time so if there isn't enough time * difference between the two generations we will end up with the same * cache invalidator, failing this test. */ - usleep( 10000 ); + \usleep( 10000 ); // Act. WPSEO_Sitemaps_Cache::clear( [ 'page' ] ); @@ -269,7 +269,7 @@ public function test_clear_index_also_cleared() { // Get the key again. $index_cache_key = WPSEO_Sitemaps_Cache_Validator::get_storage_key(); - $result = get_transient( $index_cache_key ); + $result = \get_transient( $index_cache_key ); // Assert. $this->assertEquals( $test_index_content, $result ); @@ -290,10 +290,10 @@ public function test_clear_type_isolation() { $type_b_content = 'content_b'; $type_a_key = WPSEO_Sitemaps_Cache_Validator::get_storage_key( $type_a ); - set_transient( $type_a_key, $type_a_content ); + \set_transient( $type_a_key, $type_a_content ); $type_b_key = WPSEO_Sitemaps_Cache_Validator::get_storage_key( $type_b ); - set_transient( $type_b_key, $type_b_content ); + \set_transient( $type_b_key, $type_b_content ); // Act. WPSEO_Sitemaps_Cache::clear( [ $type_a ] ); @@ -301,7 +301,7 @@ public function test_clear_type_isolation() { // Get the key again. $type_b_key = WPSEO_Sitemaps_Cache_Validator::get_storage_key( $type_b ); - $result = get_transient( $type_b_key ); + $result = \get_transient( $type_b_key ); // Assert. $this->assertEquals( $type_b_content, $result ); @@ -316,9 +316,9 @@ public function test_register_clear_on_option_update() { new WPSEO_Sitemaps_Cache(); // Hook will be added on default priority. - $has_action = has_action( + $has_action = \has_action( 'update_option', - [ 'WPSEO_Sitemaps_Cache', 'clear_on_option_update' ] + [ WPSEO_Sitemaps_Cache::class, 'clear_on_option_update' ] ); $this->assertEquals( 10, $has_action ); } @@ -340,16 +340,16 @@ public function test_clear_transient_cache() { WPSEO_Sitemaps_Cache::register_clear_on_option_update( $option, $type ); $cache_key = WPSEO_Sitemaps_Cache_Validator::get_storage_key( $type, $page ); - set_transient( $cache_key, $test_content ); + \set_transient( $cache_key, $test_content ); // Act. // Updating the option should clear cache for specified type. - do_action( 'update_option', $option ); + \do_action( 'update_option', $option ); WPSEO_Sitemaps_Cache::clear_queued(); // Get the key again. $cache_key = WPSEO_Sitemaps_Cache_Validator::get_storage_key( $type, $page ); - $result = get_transient( $cache_key ); + $result = \get_transient( $cache_key ); // Assert. $this->assertEquals( $test_content, $result ); diff --git a/tests/WP/Sitemaps/test-class-wpseo-sitemaps-cache-validator.php b/tests/WP/Sitemaps/Cache_Validator_Test.php similarity index 86% rename from tests/WP/Sitemaps/test-class-wpseo-sitemaps-cache-validator.php rename to tests/WP/Sitemaps/Cache_Validator_Test.php index 36d8be7460d..849d9e2df11 100644 --- a/tests/WP/Sitemaps/test-class-wpseo-sitemaps-cache-validator.php +++ b/tests/WP/Sitemaps/Cache_Validator_Test.php @@ -1,20 +1,19 @@ assertEquals( 45, strlen( $result ) ); + $this->assertEquals( 45, \strlen( $result ) ); } /** diff --git a/tests/WP/Sitemaps/test-class-wpseo-sitemap-image-parser.php b/tests/WP/Sitemaps/Image_Parser_Test.php similarity index 89% rename from tests/WP/Sitemaps/test-class-wpseo-sitemap-image-parser.php rename to tests/WP/Sitemaps/Image_Parser_Test.php index 4b350f48762..6a958db9490 100644 --- a/tests/WP/Sitemaps/test-class-wpseo-sitemap-image-parser.php +++ b/tests/WP/Sitemaps/Image_Parser_Test.php @@ -1,19 +1,17 @@ "jibberish" ] ); - $images = self::$class_instance->get_images( get_post( $post_id ) ); + $images = self::$class_instance->get_images( \get_post( $post_id ) ); $this->assertNotEmpty( $images[0] ); $content_image = $images[0]; $this->assertEquals( $content_src, $content_image['src'] ); diff --git a/tests/WP/Sitemaps/test-class-wpseo-post-type-sitemap-provider.php b/tests/WP/Sitemaps/Post_Type_Sitemap_Provider_Test.php similarity index 75% rename from tests/WP/Sitemaps/test-class-wpseo-post-type-sitemap-provider.php rename to tests/WP/Sitemaps/Post_Type_Sitemap_Provider_Test.php index 6c8f030172b..a32b4e33f4b 100644 --- a/tests/WP/Sitemaps/test-class-wpseo-post-type-sitemap-provider.php +++ b/tests/WP/Sitemaps/Post_Type_Sitemap_Provider_Test.php @@ -1,21 +1,20 @@ excluded_posts = [ $this->factory->post->create() ]; // Remove this post. $this->factory->post->create(); - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', [ $this, 'exclude_post' ] ); - add_filter( 'wpseo_sitemap_entries_per_page', [ $this, 'return_one' ] ); + \add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', [ $this, 'exclude_post' ] ); + \add_filter( 'wpseo_sitemap_entries_per_page', [ $this, 'return_one' ] ); // Fetch the global sitemap. - set_query_var( 'sitemap', 'post' ); + \set_query_var( 'sitemap', 'post' ); // Set the page to the second one, which should not contain an entry, but should exist. - set_query_var( 'sitemap_n', '2' ); + \set_query_var( 'sitemap_n', '2' ); // Load the sitemap. $sitemaps = new Sitemaps_Double(); @@ -114,7 +113,7 @@ public function test_get_index_links_empty_bucket() { ); // Remove the filter. - remove_filter( 'wpseo_exclude_from_sitemap_by_post_ids', [ $this, 'exclude_post' ] ); + \remove_filter( 'wpseo_exclude_from_sitemap_by_post_ids', [ $this, 'exclude_post' ] ); } /** @@ -124,10 +123,10 @@ public function test_get_index_links_empty_bucket() { */ public function test_get_index_links_empty_sitemap() { // Fetch the global sitemap. - set_query_var( 'sitemap', 'post' ); + \set_query_var( 'sitemap', 'post' ); // Set the page to the second one, which should not contain an entry, and should not exist. - set_query_var( 'sitemap_n', '2' ); + \set_query_var( 'sitemap_n', '2' ); // Load the sitemap. $sitemaps = new Sitemaps_Double(); @@ -145,51 +144,51 @@ public function test_get_index_links_empty_sitemap() { public function test_get_sitemap_links() { $sitemap_provider = new Post_Type_Sitemap_Provider_Double(); - $current_show_on_front = get_option( 'show_on_front' ); - $current_page_on_front = (int) get_option( 'page_on_front' ); - $current_page_for_posts = (int) get_option( 'page_for_posts' ); + $current_show_on_front = \get_option( 'show_on_front' ); + $current_page_on_front = (int) \get_option( 'page_on_front' ); + $current_page_for_posts = (int) \get_option( 'page_for_posts' ); $front_page = $this->factory()->post->create_and_get( [ 'post_type' => 'page' ] ); $posts_page = $this->factory()->post->create_and_get( [ 'post_type' => 'page' ] ); $post_id = $this->factory()->post->create_and_get( [ 'post_type' => 'post' ] ); - update_option( 'show_on_front', 'page' ); - update_option( 'page_on_front', $front_page->ID ); - update_option( 'page_for_posts', 0 ); + \update_option( 'show_on_front', 'page' ); + \update_option( 'page_on_front', $front_page->ID ); + \update_option( 'page_for_posts', 0 ); $sitemap_links = $sitemap_provider->get_sitemap_links( 'page', 1, 1 ); - $this->assertContains( get_permalink( $front_page->ID ), $sitemap_links[0] ); + $this->assertContains( \get_permalink( $front_page->ID ), $sitemap_links[0] ); $sitemap_links = $sitemap_provider->get_sitemap_links( 'post', 1, 1 ); - $this->assertContains( get_permalink( $post_id ), $sitemap_links[0] ); + $this->assertContains( \get_permalink( $post_id ), $sitemap_links[0] ); - update_option( 'show_on_front', 'page' ); - update_option( 'page_on_front', $front_page->ID ); - update_option( 'page_for_posts', $posts_page->ID ); + \update_option( 'show_on_front', 'page' ); + \update_option( 'page_on_front', $front_page->ID ); + \update_option( 'page_for_posts', $posts_page->ID ); $sitemap_links = $sitemap_provider->get_sitemap_links( 'page', 1, 1 ); - $this->assertContains( YoastSEO()->helpers->url->home(), $sitemap_links[0] ); - $this->assertContains( get_permalink( $front_page->ID ), $sitemap_links[0] ); + $this->assertContains( \YoastSEO()->helpers->url->home(), $sitemap_links[0] ); + $this->assertContains( \get_permalink( $front_page->ID ), $sitemap_links[0] ); $sitemap_links = $sitemap_provider->get_sitemap_links( 'post', 2, 1 ); - $this->assertContains( get_post_type_archive_link( 'post' ), $sitemap_links[0] ); - $this->assertContains( get_permalink( $posts_page->ID ), $sitemap_links[0] ); - $this->assertContains( get_permalink( $post_id ), $sitemap_links[1] ); + $this->assertContains( \get_post_type_archive_link( 'post' ), $sitemap_links[0] ); + $this->assertContains( \get_permalink( $posts_page->ID ), $sitemap_links[0] ); + $this->assertContains( \get_permalink( $post_id ), $sitemap_links[1] ); - update_option( 'show_on_front', 'posts' ); - update_option( 'page_on_front', 0 ); - update_option( 'page_for_posts', 0 ); + \update_option( 'show_on_front', 'posts' ); + \update_option( 'page_on_front', 0 ); + \update_option( 'page_for_posts', 0 ); $sitemap_links = $sitemap_provider->get_sitemap_links( 'page', 1, 1 ); - $this->assertContains( YoastSEO()->helpers->url->home(), $sitemap_links[0] ); + $this->assertContains( \YoastSEO()->helpers->url->home(), $sitemap_links[0] ); $sitemap_links = $sitemap_provider->get_sitemap_links( 'post', 2, 1 ); - $this->assertContains( YoastSEO()->helpers->url->home(), $sitemap_links[0] ); - $this->assertContains( get_permalink( $post_id ), $sitemap_links[1] ); + $this->assertContains( \YoastSEO()->helpers->url->home(), $sitemap_links[0] ); + $this->assertContains( \get_permalink( $post_id ), $sitemap_links[1] ); - update_option( 'show_on_front', $current_show_on_front ); - update_option( 'page_for_posts', $current_page_for_posts ); - update_option( 'page_on_front', $current_page_on_front ); + \update_option( 'show_on_front', $current_show_on_front ); + \update_option( 'page_for_posts', $current_page_for_posts ); + \update_option( 'page_on_front', $current_page_on_front ); } /** @@ -200,7 +199,7 @@ public function test_get_sitemap_links() { public function test_get_excluded_posts_with_set_filter() { $sitemap_provider = new Post_Type_Sitemap_Provider_Double(); - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', [ $this, 'filter_with_output' ] ); + \add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', [ $this, 'filter_with_output' ] ); $expected = [ 0 => 5, @@ -212,7 +211,7 @@ public function test_get_excluded_posts_with_set_filter() { $this->assertEquals( $expected, $sitemap_provider->get_excluded_posts( 'post' ) ); - remove_filter( 'wpseo_exclude_from_sitemap_by_post_ids', [ $this, 'filter_with_output' ] ); + \remove_filter( 'wpseo_exclude_from_sitemap_by_post_ids', [ $this, 'filter_with_output' ] ); } /** @@ -223,11 +222,11 @@ public function test_get_excluded_posts_with_set_filter() { public function test_get_excluded_posts_with_set_filter_that_has_invalid_return_value() { $sitemap_provider = new Post_Type_Sitemap_Provider_Double(); - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', [ $this, 'filter_with_invalid_output' ] ); + \add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', [ $this, 'filter_with_invalid_output' ] ); $this->assertEquals( [], $sitemap_provider->get_excluded_posts( 'post' ) ); - remove_filter( 'wpseo_exclude_from_sitemap_by_post_ids', [ $this, 'filter_with_invalid_output' ] ); + \remove_filter( 'wpseo_exclude_from_sitemap_by_post_ids', [ $this, 'filter_with_invalid_output' ] ); } /** @@ -265,7 +264,7 @@ public function filter_with_invalid_output( $excluded_post_ids ) { * @covers ::get_url */ public function test_get_url() { - $current_home = get_option( 'home' ); + $current_home = \get_option( 'home' ); $sitemap_provider = new Post_Type_Sitemap_Provider_Double(); $post_object = $this->factory()->post->create_and_get(); @@ -274,14 +273,14 @@ public function test_get_url() { $this->assertStringContainsString( $current_home, $post_url['loc'] ); // Change home URL. - update_option( 'home', 'http://example.com' ); - wp_cache_delete( 'alloptions', 'options' ); + \update_option( 'home', 'http://example.com' ); + \wp_cache_delete( 'alloptions', 'options' ); $this->assertFalse( $sitemap_provider->get_url( $post_object ) ); // Revert original home URL. - update_option( 'home', $current_home ); - wp_cache_delete( 'alloptions', 'options' ); + \update_option( 'home', $current_home ); + \wp_cache_delete( 'alloptions', 'options' ); } /** diff --git a/tests/WP/Sitemaps/test-class-wpseo-sitemap-provider-overlap.php b/tests/WP/Sitemaps/Provider_Overlap_Test.php similarity index 81% rename from tests/WP/Sitemaps/test-class-wpseo-sitemap-provider-overlap.php rename to tests/WP/Sitemaps/Provider_Overlap_Test.php index 10a2ac751fc..b307763e7db 100644 --- a/tests/WP/Sitemaps/test-class-wpseo-sitemap-provider-overlap.php +++ b/tests/WP/Sitemaps/Provider_Overlap_Test.php @@ -1,21 +1,19 @@ reset(); // Create private taxonomy "author", overlapping the "author" sitemap. - register_taxonomy( 'author', [ 'post' ], [ 'public' => false ] ); + \register_taxonomy( 'author', [ 'post' ], [ 'public' => false ] ); } /** * Clean up the taxonomy. */ public function tear_down() { - unregister_taxonomy( 'author' ); + \unregister_taxonomy( 'author' ); parent::tear_down(); } @@ -66,12 +64,12 @@ public function test_private_taxonomy_author_overlap() { $this->factory->post->create_many( 1, [ 'post_author' => $user_id ] ); // Fetch the global sitemap. - set_query_var( 'sitemap', '1' ); + \set_query_var( 'sitemap', '1' ); // Load the sitemap. self::$class_instance->redirect( $GLOBALS['wp_the_query'] ); - $url = home_url( 'author-sitemap.xml' ); + $url = \home_url( 'author-sitemap.xml' ); // Expect the author-sitemap to be present in the index. $this->expectOutputContains( @@ -88,14 +86,14 @@ public function test_private_taxonomy_author_overlap_author_in_sitemap() { $this->factory->post->create_many( 1, [ 'post_author' => $user_id ] ); // Fetch the global sitemap. - set_query_var( 'sitemap', 'author' ); + \set_query_var( 'sitemap', 'author' ); // Load the sitemap. self::$class_instance->redirect( $GLOBALS['wp_the_query'] ); // Expect the author-sitemap to be present in the index. $this->expectOutputContains( - '' . get_author_posts_url( $user_id ) . '' + '' . \get_author_posts_url( $user_id ) . '' ); } } diff --git a/tests/WP/Sitemaps/test-class-wpseo-sitemaps-renderer.php b/tests/WP/Sitemaps/Renderer_Test.php similarity index 93% rename from tests/WP/Sitemaps/test-class-wpseo-sitemaps-renderer.php rename to tests/WP/Sitemaps/Renderer_Test.php index 3a234d741fb..2c0254d40dc 100644 --- a/tests/WP/Sitemaps/test-class-wpseo-sitemaps-renderer.php +++ b/tests/WP/Sitemaps/Renderer_Test.php @@ -1,19 +1,17 @@ $loc, @@ -60,7 +58,7 @@ public function test_get_index() { public function test_get_sitemap() { $loc = 'http://example.com/?s=keyword&p=2'; - $mod = date( 'c' ); + $mod = \date( 'c' ); $image_a = 'http://example.com/image.jpg'; $image_b = 'example.com/my category/my=page*without"enco@ding/'; $image_c = '//example.com/my category?s=keyword&p=2'; @@ -88,7 +86,7 @@ public function test_get_sitemap() { $expected_c = 'http://example.com/my%20category?s=keyword&p=2'; $index = self::$class_instance->get_sitemap( $links, 'post', 0 ); - $this->assertStringContainsString( '' . str_replace( '&', '&', $loc ) . '', $index ); + $this->assertStringContainsString( '' . \str_replace( '&', '&', $loc ) . '', $index ); $this->assertStringContainsString( "{$mod}", $index ); $this->assertStringContainsString( "{$image_a}", $index ); $this->assertStringContainsString( "{$expected_b}", $index ); @@ -195,8 +193,8 @@ public function change_plugin_url() { public function test_is_home_url_returned_correctly() { $class_instance = new Sitemaps_Renderer_Double(); - add_filter( 'plugins_url', [ $this, 'change_plugin_url' ] ); + \add_filter( 'plugins_url', [ $this, 'change_plugin_url' ] ); $this->assertEquals( 'http://example.org/main-sitemap.xsl', $class_instance->get_xsl_url() ); - remove_filter( 'plugins_url', [ $this, 'change_plugin_url' ] ); + \remove_filter( 'plugins_url', [ $this, 'change_plugin_url' ] ); } } diff --git a/tests/WP/Sitemaps/test-class-wpseo-sitemaps-router.php b/tests/WP/Sitemaps/Router_Test.php similarity index 88% rename from tests/WP/Sitemaps/test-class-wpseo-sitemaps-router.php rename to tests/WP/Sitemaps/Router_Test.php index 85074a71cd3..15b5ac72a85 100644 --- a/tests/WP/Sitemaps/test-class-wpseo-sitemaps-router.php +++ b/tests/WP/Sitemaps/Router_Test.php @@ -1,18 +1,17 @@ query_vars['sitemap'] ); unset( $wp_query->query_vars['xls'] ); - $url = site_url(); + $url = \site_url(); $this->assertNotEmpty( self::$class_instance->redirect_canonical( $url ) ); - set_query_var( 'sitemap', 'sitemap_value' ); + \set_query_var( 'sitemap', 'sitemap_value' ); $this->assertFalse( self::$class_instance->redirect_canonical( $url ) ); - set_query_var( '$yoast_sitemap_xsl', 'xsl_value' ); + \set_query_var( '$yoast_sitemap_xsl', 'xsl_value' ); $this->assertFalse( self::$class_instance->redirect_canonical( $url ) ); } @@ -67,7 +66,7 @@ public function test_redirect_canonical() { * @param string $expected The expected test result. */ public function test_get_base_url( $home_url, $expected ) { - update_option( 'home', $home_url ); + \update_option( 'home', $home_url ); $this->assertSame( $expected, WPSEO_Sitemaps_Router::get_base_url( 'sitemap.xml' ) ); } @@ -108,13 +107,13 @@ public function test_needs_sitemap_index_redirect( $server_vars, $home_url, $wp_ $server_orig = $_SERVER; $wp_query_orig = $GLOBALS['wp_query']; - $_SERVER = array_merge( $_SERVER, $server_vars ); + $_SERVER = \array_merge( $_SERVER, $server_vars ); $this->home_url = $home_url; $GLOBALS['wp_query'] = $wp_query; - add_filter( 'home_url', [ $this, 'filter_home_url' ], 100, 2 ); + \add_filter( 'home_url', [ $this, 'filter_home_url' ], 100, 2 ); $result = self::$class_instance->needs_sitemap_index_redirect(); - remove_filter( 'home_url', [ $this, 'filter_home_url' ], 100 ); + \remove_filter( 'home_url', [ $this, 'filter_home_url' ], 100 ); $GLOBALS['wp_query'] = $wp_query_orig; $this->home_url = ''; @@ -134,7 +133,7 @@ public function test_needs_sitemap_index_redirect( $server_vars, $home_url, $wp_ public function filter_home_url( $home_url, $path ) { if ( ! empty( $this->home_url ) ) { if ( ! empty( $path ) ) { - return $this->home_url . '/' . ltrim( $path, '/' ); + return $this->home_url . '/' . \ltrim( $path, '/' ); } return $this->home_url; } @@ -206,7 +205,7 @@ public function data_needs_sitemap_index_redirect() { $testdata[] = [ $server_vars, $home_url, $wp_query, $expected ]; $expected = $home_url === 'https://' . $domain && $path === '/sitemap.xml' && $wp_query->is_404; - $testdata[] = [ array_merge( $server_vars, [ 'HTTPS' => 'on' ] ), $home_url, $wp_query, $expected ]; + $testdata[] = [ \array_merge( $server_vars, [ 'HTTPS' => 'on' ] ), $home_url, $wp_query, $expected ]; } } } diff --git a/tests/WP/Sitemaps/test-class-wpseo-sitemaps.php b/tests/WP/Sitemaps/Sitemaps_Test.php similarity index 90% rename from tests/WP/Sitemaps/test-class-wpseo-sitemaps.php rename to tests/WP/Sitemaps/Sitemaps_Test.php index 9d0f8d80316..18e7b2456ce 100644 --- a/tests/WP/Sitemaps/test-class-wpseo-sitemaps.php +++ b/tests/WP/Sitemaps/Sitemaps_Test.php @@ -1,19 +1,17 @@ reset(); - set_query_var( 'sitemap', 'post' ); + \set_query_var( 'sitemap', 'post' ); self::$class_instance->redirect( $GLOBALS['wp_the_query'] ); @@ -75,7 +73,7 @@ public function test_main_sitemap( $expected_output ) { self::$class_instance->reset(); - set_query_var( 'sitemap', '1' ); + \set_query_var( 'sitemap', '1' ); $this->factory->post->create(); @@ -107,16 +105,16 @@ public function test_index_links_filter() { self::$class_instance->reset(); - set_query_var( 'sitemap', '1' ); + \set_query_var( 'sitemap', '1' ); $this->factory->post->create(); - add_filter( + \add_filter( 'wpseo_sitemap_index_links', static function( $links ) { $links[] = [ 'loc' => 'test-sitemap.xml', - 'lastmod' => date( '1' ), + 'lastmod' => \date( '1' ), ]; return $links; } @@ -141,7 +139,7 @@ public function test_last_modified_post_type() { 'public' => true, 'has_archive' => true, ]; - register_post_type( 'yoast', $post_type_args ); + \register_post_type( 'yoast', $post_type_args ); $post_args = [ 'post_status' => 'publish', diff --git a/tests/WP/Sitemaps/test-class-wpseo-taxonomy-sitemap-provider.php b/tests/WP/Sitemaps/Taxonomy_Sitemap_Provider_Test.php similarity index 85% rename from tests/WP/Sitemaps/test-class-wpseo-taxonomy-sitemap-provider.php rename to tests/WP/Sitemaps/Taxonomy_Sitemap_Provider_Test.php index 44714b5ea1d..ae6e1a5bf65 100644 --- a/tests/WP/Sitemaps/test-class-wpseo-taxonomy-sitemap-provider.php +++ b/tests/WP/Sitemaps/Taxonomy_Sitemap_Provider_Test.php @@ -1,20 +1,18 @@ factory->category->create(); $post_id = $this->factory->post->create(); - wp_set_post_categories( $post_id, $category_id ); + \wp_set_post_categories( $post_id, $category_id ); $index_links = self::$class_instance->get_index_links( 1 ); $this->assertNotEmpty( $index_links ); @@ -52,7 +50,7 @@ public function test_get_index_links() { $category2_id = $this->factory->category->create(); $post2_id = $this->factory->post->create(); - wp_set_post_categories( $post2_id, $category2_id ); + \wp_set_post_categories( $post2_id, $category2_id ); $index_links = self::$class_instance->get_index_links( 1 ); $this->assertContains( 'http://example.org/category-sitemap.xml', $index_links[0] ); $this->assertContains( 'http://example.org/category-sitemap2.xml', $index_links[1] ); @@ -67,9 +65,9 @@ public function test_get_sitemap_links() { $category_id = $this->factory->category->create(); $post_id = $this->factory->post->create(); - wp_set_post_categories( $post_id, $category_id ); + \wp_set_post_categories( $post_id, $category_id ); $sitemap_links = self::$class_instance->get_sitemap_links( 'category', 1, 1 ); - $this->assertContains( get_category_link( $category_id ), $sitemap_links[0] ); + $this->assertContains( \get_category_link( $category_id ), $sitemap_links[0] ); } /** @@ -79,10 +77,10 @@ public function test_get_sitemap_links() { */ public function test_get_index_links_empty_sitemap() { // Fetch the global sitemap. - set_query_var( 'sitemap', 'category' ); + \set_query_var( 'sitemap', 'category' ); // Set the page to the second one, which should not contain an entry, and should not exist. - set_query_var( 'sitemap_n', '2' ); + \set_query_var( 'sitemap_n', '2' ); // Load the sitemap. $sitemaps = new Sitemaps_Double(); diff --git a/tests/WP/Statistics/test-class-statistics-service.php b/tests/WP/Statistics/Statistics_Service_Test.php similarity index 84% rename from tests/WP/Statistics/test-class-statistics-service.php rename to tests/WP/Statistics/Statistics_Service_Test.php index e340ddfa6b5..c2d848a2c5b 100644 --- a/tests/WP/Statistics/test-class-statistics-service.php +++ b/tests/WP/Statistics/Statistics_Service_Test.php @@ -1,10 +1,8 @@ get_data(); $this->assertEquals( - esc_url( admin_url( 'edit.php?post_status=publish&post_type=post&seo_filter=ok&author=0' ) ), + \esc_url( \admin_url( 'edit.php?post_status=publish&post_type=post&seo_filter=ok&author=0' ) ), $response_data['seo_scores'][0]['link'] ); } @@ -76,7 +74,7 @@ public function test_seo_score_links() { * @covers ::get_statistics */ public function test_admin_seo_score_links() { - $user = wp_get_current_user(); + $user = \wp_get_current_user(); $user->add_cap( 'edit_others_posts' ); $statistics = new Statistics_Mock( @@ -92,7 +90,7 @@ public function test_admin_seo_score_links() { $response_data = $rest_response->get_data(); $this->assertEquals( - esc_url( admin_url( 'edit.php?post_status=publish&post_type=post&seo_filter=ok' ) ), + \esc_url( \admin_url( 'edit.php?post_status=publish&post_type=post&seo_filter=ok' ) ), $response_data['seo_scores'][0]['link'] ); diff --git a/tests/WP/Taxonomy/test-class-taxonomy-presenter.php b/tests/WP/Taxonomy/Taxonomy_Fields_Presenter_Test.php similarity index 94% rename from tests/WP/Taxonomy/test-class-taxonomy-presenter.php rename to tests/WP/Taxonomy/Taxonomy_Fields_Presenter_Test.php index a5259ca3904..2e89bdb94c6 100644 --- a/tests/WP/Taxonomy/test-class-taxonomy-presenter.php +++ b/tests/WP/Taxonomy/Taxonomy_Fields_Presenter_Test.php @@ -1,16 +1,14 @@ test field

this is a test field

'; - $expected = sprintf( $expected, plugins_url( 'images/question-mark.png', WPSEO_FILE ) ); + $expected = \sprintf( $expected, \plugins_url( 'images/question-mark.png', \WPSEO_FILE ) ); $this->assertEquals( $expected, $output ); } @@ -77,7 +75,7 @@ public function test_display_fields_no_label() { ); $expected = '

this is a test field

'; - $expected = sprintf( $expected, plugins_url( 'images/question-mark.png', WPSEO_FILE ) ); + $expected = \sprintf( $expected, \plugins_url( 'images/question-mark.png', \WPSEO_FILE ) ); $this->assertEquals( $expected, $output ); } diff --git a/tests/WP/Taxonomy/test-class-taxonomy.php b/tests/WP/Taxonomy/Taxonomy_Test.php similarity index 93% rename from tests/WP/Taxonomy/test-class-taxonomy.php rename to tests/WP/Taxonomy/Taxonomy_Test.php index 2b84c59e81a..90180b05bbb 100644 --- a/tests/WP/Taxonomy/test-class-taxonomy.php +++ b/tests/WP/Taxonomy/Taxonomy_Test.php @@ -1,10 +1,8 @@