diff --git a/tests/WP/Dashboard/User_Interface/Readability_Scores/Abstract_Readability_Scores_Test.php b/tests/WP/Dashboard/User_Interface/Readability_Scores/Abstract_Readability_Scores_Test.php new file mode 100644 index 00000000000..c11a3e8973f --- /dev/null +++ b/tests/WP/Dashboard/User_Interface/Readability_Scores/Abstract_Readability_Scores_Test.php @@ -0,0 +1,45 @@ +score_results_repository = Mockery::mock( Readability_Score_Results_Repository::class ); + + $this->instance = new Readability_Scores_Route( $this->score_results_repository ); + + $user = $this->factory->user->create_and_get(); + $user->add_cap( 'wpseo_manage_options' ); + + \wp_set_current_user( $user->ID ); + } +} diff --git a/tests/WP/Dashboard/User_Interface/Readability_Scores/Excluded_Content_Type_Test.php b/tests/WP/Dashboard/User_Interface/Readability_Scores/Excluded_Content_Type_Test.php new file mode 100644 index 00000000000..cae35bd222d --- /dev/null +++ b/tests/WP/Dashboard/User_Interface/Readability_Scores/Excluded_Content_Type_Test.php @@ -0,0 +1,55 @@ +set_param( 'contentType', 'post' ); + + \add_filter( 'wpseo_indexable_excluded_post_types', [ $this, 'filter_exclude_post' ] ); + + $response = \rest_get_server()->dispatch( $request ); + + $this->assertInstanceOf( WP_REST_Response::class, $response ); + + $response_data = $response->get_data(); + + $this->assertSame( 400, $response->status ); + $this->assertSame( $response_data['error'], 'Invalid content type.' ); + + \remove_filter( 'wpseo_indexable_excluded_post_types', [ $this, 'filter_exclude_post' ] ); + } + + /** + * Filter function to exclude posts from indexable creation. + * + * @param array $excluded_post_types The excluded post types before the filter. + * + * @return array The excluded post types after the filter. + */ + public function filter_exclude_post( $excluded_post_types ) { + $excluded_post_types[] = 'post'; + + return $excluded_post_types; + } +} diff --git a/tests/WP/Dashboard/User_Interface/Readability_Scores/Get_Scores_Test.php b/tests/WP/Dashboard/User_Interface/Readability_Scores/Get_Scores_Test.php new file mode 100644 index 00000000000..3e839f4d8aa --- /dev/null +++ b/tests/WP/Dashboard/User_Interface/Readability_Scores/Get_Scores_Test.php @@ -0,0 +1,241 @@ +> $inserted_posts The posts to be insterted. + * @param bool $taxonomy_filter Whether there's a taxonomy filter. + * @param array $expected_amounts The amounts of the scores that are expected to be returned. + * + * @return void + */ + public function test_get_readability_scores( $inserted_posts, $taxonomy_filter, $expected_amounts ) { + $this->register_blog_post_type(); + + $term = self::factory()->term->create_and_get( + [ + 'name' => 'Test category', + 'taxonomy' => 'category', + [ + 'slug' => 'test-category', + ], + ] + ); + + $term_id = (int) $term->term_id; + $term_slug = 'test-category'; + + $request = new WP_REST_Request( 'GET', '/yoast/v1/readability_scores' ); + $request->set_param( 'contentType', 'blog-post' ); + + if ( ! empty( $taxonomy_filter ) ) { + $request->set_param( 'taxonomy', 'category' ); + $request->set_param( 'term', $term_id ); + } + + $new_ids = []; + foreach ( $inserted_posts as $key => $post ) { + $meta_input = []; + foreach ( $post['meta_input'] as $meta_key => $meta_value ) { + $meta_input[ $meta_key ] = $meta_value; + } + + $new_ids[] = self::factory()->post->create( + [ + 'post_title' => 'Test Post ' . $key, + 'post_status' => 'publish', + 'post_type' => 'blog-post', + 'post_category' => ( $post['custom_category'] ) ? [ $term_id ] : [ 1 ], + 'meta_input' => $meta_input, + ] + ); + } + + $response = \rest_get_server()->dispatch( $request ); + + $this->assertInstanceOf( WP_REST_Response::class, $response ); + + $response_data = $response->get_data(); + + $this->assertIsArray( $response_data ); + $this->assertIsArray( $response_data['scores'] ); + $this->assertIsFloat( $response_data['queryTime'] ); + $this->assertIsBool( $response_data['cacheUsed'] ); + + $this->assertEquals( $response_data['scores'][0]['name'], 'good' ); + $this->assertEquals( $response_data['scores'][0]['amount'], $expected_amounts['good'] ); + + $this->assertEquals( $response_data['scores'][1]['name'], 'ok' ); + $this->assertEquals( $response_data['scores'][1]['amount'], $expected_amounts['ok'] ); + + $this->assertEquals( $response_data['scores'][2]['name'], 'bad' ); + $this->assertEquals( $response_data['scores'][2]['amount'], $expected_amounts['bad'] ); + + $this->assertEquals( $response_data['scores'][3]['name'], 'notAnalyzed' ); + $this->assertEquals( $response_data['scores'][3]['amount'], $expected_amounts['notAnalyzed'] ); + + $link_suffix = ( $taxonomy_filter ) ? '&category_name=' . $term_slug : ''; + $this->assertEquals( $response_data['scores'][0]['links']['view'], 'http://example.org/wp-admin/edit.php?post_status=publish&post_type=blog-post&readability_filter=good' . $link_suffix ); + $this->assertEquals( $response_data['scores'][1]['links']['view'], 'http://example.org/wp-admin/edit.php?post_status=publish&post_type=blog-post&readability_filter=ok' . $link_suffix ); + $this->assertEquals( $response_data['scores'][2]['links']['view'], 'http://example.org/wp-admin/edit.php?post_status=publish&post_type=blog-post&readability_filter=bad' . $link_suffix ); + $this->assertEquals( $response_data['scores'][3]['links']['view'], 'http://example.org/wp-admin/edit.php?post_status=publish&post_type=blog-post&readability_filter=na' . $link_suffix ); + + // Clean up. + foreach ( $new_ids as $new_id ) { + \wp_delete_post( $new_id, true ); + } + \unregister_post_type( 'blog-post' ); + \wp_delete_term( $term_id, 'category' ); + } + + /** + * Data provider for test_get_readability_scores. + * + * @return array + */ + public static function data_provider_get_readability_scores() { + + $inserted_posts_in_multiple_terms = [ + [ + 'custom_category' => false, + 'meta_input' => [ + '_yoast_wpseo_content_score' => '30', + ], + ], + [ + 'custom_category' => true, + 'meta_input' => [ + '_yoast_wpseo_content_score' => '30', + ], + ], + [ + 'custom_category' => false, + 'meta_input' => [ + '_yoast_wpseo_content_score' => '10', + ], + ], + [ + 'custom_category' => true, + 'meta_input' => [ + '_yoast_wpseo_content_score' => '10', + ], + ], + [ + 'custom_category' => false, + 'meta_input' => [ + '_yoast_wpseo_content_score' => '50', + ], + ], + [ + 'custom_category' => true, + 'meta_input' => [ + '_yoast_wpseo_content_score' => '50', + ], + ], + [ + 'custom_category' => false, + 'meta_input' => [ + '_yoast_wpseo_content_score' => '80', + ], + ], + [ + 'custom_category' => true, + 'meta_input' => [ + '_yoast_wpseo_content_score' => '80', + ], + ], + [ + 'custom_category' => false, + 'meta_input' => [], + ], + [ + 'custom_category' => true, + 'meta_input' => [], + ], + ]; + + yield 'No posts inserted' => [ + 'inserted_posts' => [], + 'taxonomy_filter' => false, + 'expected_amounts' => [ + 'good' => 0, + 'ok' => 0, + 'bad' => 0, + 'notAnalyzed' => 0, + ], + ]; + yield 'Multiple posts of all sorts of SEO scores from term with ID 1' => [ + 'inserted_posts' => $inserted_posts_in_multiple_terms, + 'taxonomy_filter' => true, + 'expected_amounts' => [ + 'good' => 1, + 'ok' => 1, + 'bad' => 2, + 'notAnalyzed' => 1, + ], + ]; + yield 'Multiple posts of all sorts of SEO scores from all terms' => [ + 'inserted_posts' => $inserted_posts_in_multiple_terms, + 'taxonomy_filter' => false, + 'expected_amounts' => [ + 'good' => 2, + 'ok' => 2, + 'bad' => 4, + 'notAnalyzed' => 2, + ], + ]; + } + + /** + * Action function to register new blog post post type. + * + * @return void + */ + public function register_blog_post_type() { + $args = [ + 'label' => 'Blog posts', + 'public' => true, + 'has_archive' => true, + 'show_in_rest' => true, + 'taxonomies' => [ 'category' ], + ]; + + \register_post_type( 'blog-post', $args ); + } +} diff --git a/tests/WP/Dashboard/User_Interface/Readability_Scores/Invalid_Term_Test.php b/tests/WP/Dashboard/User_Interface/Readability_Scores/Invalid_Term_Test.php new file mode 100644 index 00000000000..cdd06e1b4d9 --- /dev/null +++ b/tests/WP/Dashboard/User_Interface/Readability_Scores/Invalid_Term_Test.php @@ -0,0 +1,45 @@ + 'test-tag', + ] + ); + + $request = new WP_REST_Request( 'GET', '/yoast/v1/readability_scores' ); + $request->set_param( 'contentType', 'post' ); + $request->set_param( 'taxonomy', 'category' ); + $request->set_param( 'term', $tag_id['term_id'] ); + + $response = \rest_get_server()->dispatch( $request ); + + $this->assertInstanceOf( WP_REST_Response::class, $response ); + + $response_data = $response->get_data(); + + $this->assertSame( 400, $response->status ); + $this->assertSame( $response_data['error'], 'Invalid term.' ); + } +} diff --git a/tests/WP/Dashboard/User_Interface/Readability_Scores/Non_Existing_Content_Type_Test.php b/tests/WP/Dashboard/User_Interface/Readability_Scores/Non_Existing_Content_Type_Test.php new file mode 100644 index 00000000000..53b326ff921 --- /dev/null +++ b/tests/WP/Dashboard/User_Interface/Readability_Scores/Non_Existing_Content_Type_Test.php @@ -0,0 +1,36 @@ +set_param( 'contentType', 'not-existing-content-type' ); + + $response = \rest_get_server()->dispatch( $request ); + + $this->assertInstanceOf( WP_REST_Response::class, $response ); + + $response_data = $response->get_data(); + + $this->assertSame( 400, $response->status ); + $this->assertSame( $response_data['error'], 'Invalid content type.' ); + } +} diff --git a/tests/WP/Dashboard/User_Interface/Readability_Scores/Non_Filtering_Taxonomy_Test.php b/tests/WP/Dashboard/User_Interface/Readability_Scores/Non_Filtering_Taxonomy_Test.php new file mode 100644 index 00000000000..702622eaf45 --- /dev/null +++ b/tests/WP/Dashboard/User_Interface/Readability_Scores/Non_Filtering_Taxonomy_Test.php @@ -0,0 +1,38 @@ +set_param( 'contentType', 'post' ); + $request->set_param( 'taxonomy', 'post_tag' ); + $request->set_param( 'term', 'irrelevant' ); + + $response = \rest_get_server()->dispatch( $request ); + + $this->assertInstanceOf( WP_REST_Response::class, $response ); + + $response_data = $response->get_data(); + + $this->assertSame( 400, $response->status ); + $this->assertSame( $response_data['error'], 'Invalid taxonomy.' ); + } +} diff --git a/tests/WP/Dashboard/User_Interface/Readability_Scores/Not_Priviliged_User_Test.php b/tests/WP/Dashboard/User_Interface/Readability_Scores/Not_Priviliged_User_Test.php new file mode 100644 index 00000000000..a72a5159b51 --- /dev/null +++ b/tests/WP/Dashboard/User_Interface/Readability_Scores/Not_Priviliged_User_Test.php @@ -0,0 +1,38 @@ +factory->user->create_and_get( [ 'role' => 'author' ] ); + \wp_set_current_user( $user->ID ); + + $request = new WP_REST_Request( 'GET', '/yoast/v1/readability_scores' ); + $request->set_param( 'contentType', 'post' ); + + $response = \rest_get_server()->dispatch( $request ); + + $this->assertInstanceOf( WP_REST_Response::class, $response ); + + $response_data = $response->get_data(); + + $this->assertSame( $response_data['code'], 'rest_forbidden' ); + $this->assertSame( $response_data['data']['status'], 403 ); + } +} diff --git a/tests/WP/Dashboard/User_Interface/SEO_Scores/Abstract_SEO_Scores_Test.php b/tests/WP/Dashboard/User_Interface/SEO_Scores/Abstract_SEO_Scores_Test.php new file mode 100644 index 00000000000..b28973adc3e --- /dev/null +++ b/tests/WP/Dashboard/User_Interface/SEO_Scores/Abstract_SEO_Scores_Test.php @@ -0,0 +1,45 @@ +score_results_repository = Mockery::mock( SEO_Score_Results_Repository::class ); + + $this->instance = new SEO_Scores_Route( $this->score_results_repository ); + + $user = $this->factory->user->create_and_get(); + $user->add_cap( 'wpseo_manage_options' ); + + \wp_set_current_user( $user->ID ); + } +} diff --git a/tests/WP/Dashboard/User_Interface/SEO_Scores/Excluded_Content_Type_Test.php b/tests/WP/Dashboard/User_Interface/SEO_Scores/Excluded_Content_Type_Test.php new file mode 100644 index 00000000000..af00501da23 --- /dev/null +++ b/tests/WP/Dashboard/User_Interface/SEO_Scores/Excluded_Content_Type_Test.php @@ -0,0 +1,55 @@ +set_param( 'contentType', 'post' ); + + \add_filter( 'wpseo_indexable_excluded_post_types', [ $this, 'filter_exclude_post' ] ); + + $response = \rest_get_server()->dispatch( $request ); + + $this->assertInstanceOf( WP_REST_Response::class, $response ); + + $response_data = $response->get_data(); + + $this->assertSame( 400, $response->status ); + $this->assertSame( $response_data['error'], 'Invalid content type.' ); + + \remove_filter( 'wpseo_indexable_excluded_post_types', [ $this, 'filter_exclude_post' ] ); + } + + /** + * Filter function to exclude posts from indexable creation. + * + * @param array $excluded_post_types The excluded post types before the filter. + * + * @return array The excluded post types after the filter. + */ + public function filter_exclude_post( $excluded_post_types ) { + $excluded_post_types[] = 'post'; + + return $excluded_post_types; + } +} diff --git a/tests/WP/Dashboard/User_Interface/SEO_Scores/Get_Scores_Test.php b/tests/WP/Dashboard/User_Interface/SEO_Scores/Get_Scores_Test.php new file mode 100644 index 00000000000..f642b75befb --- /dev/null +++ b/tests/WP/Dashboard/User_Interface/SEO_Scores/Get_Scores_Test.php @@ -0,0 +1,249 @@ +> $inserted_posts The posts to be insterted. + * @param bool $taxonomy_filter Whether there's a taxonomy filter. + * @param array $expected_amounts The amounts of the scores that are expected to be returned. + * + * @return void + */ + public function test_get_seo_scores( $inserted_posts, $taxonomy_filter, $expected_amounts ) { + $this->register_blog_post_type(); + + $term = self::factory()->term->create_and_get( + [ + 'name' => 'Test category', + 'taxonomy' => 'category', + [ + 'slug' => 'test-category', + ], + ] + ); + + $term_id = (int) $term->term_id; + $term_slug = 'test-category'; + + $request = new WP_REST_Request( 'GET', '/yoast/v1/seo_scores' ); + $request->set_param( 'contentType', 'blog-post' ); + + if ( ! empty( $taxonomy_filter ) ) { + $request->set_param( 'taxonomy', 'category' ); + $request->set_param( 'term', $term_id ); + } + + $new_ids = []; + foreach ( $inserted_posts as $key => $post ) { + $meta_input = []; + foreach ( $post['meta_input'] as $meta_key => $meta_value ) { + $meta_input[ $meta_key ] = $meta_value; + } + + $new_ids[] = self::factory()->post->create( + [ + 'post_title' => 'Test Post ' . $key, + 'post_status' => 'publish', + 'post_type' => 'blog-post', + 'post_category' => ( $post['custom_category'] ) ? [ $term_id ] : [ 1 ], + 'meta_input' => $meta_input, + ] + ); + } + + $response = \rest_get_server()->dispatch( $request ); + + $this->assertInstanceOf( WP_REST_Response::class, $response ); + + $response_data = $response->get_data(); + + $this->assertIsArray( $response_data ); + $this->assertIsArray( $response_data['scores'] ); + $this->assertIsFloat( $response_data['queryTime'] ); + $this->assertIsBool( $response_data['cacheUsed'] ); + + $this->assertEquals( $response_data['scores'][0]['name'], 'good' ); + $this->assertEquals( $response_data['scores'][0]['amount'], $expected_amounts['good'] ); + + $this->assertEquals( $response_data['scores'][1]['name'], 'ok' ); + $this->assertEquals( $response_data['scores'][1]['amount'], $expected_amounts['ok'] ); + + $this->assertEquals( $response_data['scores'][2]['name'], 'bad' ); + $this->assertEquals( $response_data['scores'][2]['amount'], $expected_amounts['bad'] ); + + $this->assertEquals( $response_data['scores'][3]['name'], 'notAnalyzed' ); + $this->assertEquals( $response_data['scores'][3]['amount'], $expected_amounts['notAnalyzed'] ); + + $link_suffix = ( $taxonomy_filter ) ? '&category_name=' . $term_slug : ''; + $this->assertEquals( $response_data['scores'][0]['links']['view'], 'http://example.org/wp-admin/edit.php?post_status=publish&post_type=blog-post&seo_filter=good' . $link_suffix ); + $this->assertEquals( $response_data['scores'][1]['links']['view'], 'http://example.org/wp-admin/edit.php?post_status=publish&post_type=blog-post&seo_filter=ok' . $link_suffix ); + $this->assertEquals( $response_data['scores'][2]['links']['view'], 'http://example.org/wp-admin/edit.php?post_status=publish&post_type=blog-post&seo_filter=bad' . $link_suffix ); + $this->assertEquals( $response_data['scores'][3]['links']['view'], 'http://example.org/wp-admin/edit.php?post_status=publish&post_type=blog-post&seo_filter=na' . $link_suffix ); + + // Clean up. + foreach ( $new_ids as $new_id ) { + \wp_delete_post( $new_id, true ); + } + \unregister_post_type( 'blog-post' ); + \wp_delete_term( $term_id, 'category' ); + } + + /** + * Data provider for test_get_seo_scores. + * + * @return array + */ + public static function data_provider_get_seo_scores() { + + $inserted_posts_in_multiple_terms = [ + [ + 'custom_category' => false, + 'meta_input' => [ + '_yoast_wpseo_linkdex' => '30', + '_yoast_wpseo_focuskw' => 'test', + ], + ], + [ + 'custom_category' => true, + 'meta_input' => [ + '_yoast_wpseo_linkdex' => '30', + '_yoast_wpseo_focuskw' => 'test', + ], + ], + [ + 'custom_category' => false, + 'meta_input' => [ + '_yoast_wpseo_linkdex' => '10', + '_yoast_wpseo_focuskw' => 'test', + ], + ], + [ + 'custom_category' => true, + 'meta_input' => [ + '_yoast_wpseo_linkdex' => '10', + '_yoast_wpseo_focuskw' => 'test', + ], + ], + [ + 'custom_category' => false, + 'meta_input' => [ + '_yoast_wpseo_linkdex' => '50', + '_yoast_wpseo_focuskw' => 'test', + ], + ], + [ + 'custom_category' => true, + 'meta_input' => [ + '_yoast_wpseo_linkdex' => '50', + '_yoast_wpseo_focuskw' => 'test', + ], + ], + [ + 'custom_category' => false, + 'meta_input' => [ + '_yoast_wpseo_linkdex' => '80', + '_yoast_wpseo_focuskw' => 'test', + ], + ], + [ + 'custom_category' => true, + 'meta_input' => [ + '_yoast_wpseo_linkdex' => '80', + '_yoast_wpseo_focuskw' => 'test', + ], + ], + [ + 'custom_category' => false, + 'meta_input' => [], + ], + [ + 'custom_category' => true, + 'meta_input' => [], + ], + ]; + + yield 'No posts inserted' => [ + 'inserted_posts' => [], + 'taxonomy_filter' => false, + 'expected_amounts' => [ + 'good' => 0, + 'ok' => 0, + 'bad' => 0, + 'notAnalyzed' => 0, + ], + ]; + yield 'Multiple posts of all sorts of SEO scores from term with ID 1' => [ + 'inserted_posts' => $inserted_posts_in_multiple_terms, + 'taxonomy_filter' => true, + 'expected_amounts' => [ + 'good' => 1, + 'ok' => 1, + 'bad' => 2, + 'notAnalyzed' => 1, + ], + ]; + yield 'Multiple posts of all sorts of SEO scores from all terms' => [ + 'inserted_posts' => $inserted_posts_in_multiple_terms, + 'taxonomy_filter' => false, + 'expected_amounts' => [ + 'good' => 2, + 'ok' => 2, + 'bad' => 4, + 'notAnalyzed' => 2, + ], + ]; + } + + /** + * Action function to register new blog post post type. + * + * @return void + */ + public function register_blog_post_type() { + $args = [ + 'label' => 'Blog posts', + 'public' => true, + 'has_archive' => true, + 'show_in_rest' => true, + 'taxonomies' => [ 'category' ], + ]; + + \register_post_type( 'blog-post', $args ); + } +} diff --git a/tests/WP/Dashboard/User_Interface/SEO_Scores/Invalid_Term_Test.php b/tests/WP/Dashboard/User_Interface/SEO_Scores/Invalid_Term_Test.php new file mode 100644 index 00000000000..d149bac86a6 --- /dev/null +++ b/tests/WP/Dashboard/User_Interface/SEO_Scores/Invalid_Term_Test.php @@ -0,0 +1,45 @@ + 'test-tag', + ] + ); + + $request = new WP_REST_Request( 'GET', '/yoast/v1/seo_scores' ); + $request->set_param( 'contentType', 'post' ); + $request->set_param( 'taxonomy', 'category' ); + $request->set_param( 'term', $tag_id['term_id'] ); + + $response = \rest_get_server()->dispatch( $request ); + + $this->assertInstanceOf( WP_REST_Response::class, $response ); + + $response_data = $response->get_data(); + + $this->assertSame( 400, $response->status ); + $this->assertSame( $response_data['error'], 'Invalid term.' ); + } +} diff --git a/tests/WP/Dashboard/User_Interface/SEO_Scores/Non_Existing_Content_Type_Test.php b/tests/WP/Dashboard/User_Interface/SEO_Scores/Non_Existing_Content_Type_Test.php new file mode 100644 index 00000000000..c0917b5d42d --- /dev/null +++ b/tests/WP/Dashboard/User_Interface/SEO_Scores/Non_Existing_Content_Type_Test.php @@ -0,0 +1,36 @@ +set_param( 'contentType', 'not-existing-content-type' ); + + $response = \rest_get_server()->dispatch( $request ); + + $this->assertInstanceOf( WP_REST_Response::class, $response ); + + $response_data = $response->get_data(); + + $this->assertSame( 400, $response->status ); + $this->assertSame( $response_data['error'], 'Invalid content type.' ); + } +} diff --git a/tests/WP/Dashboard/User_Interface/SEO_Scores/Non_Filtering_Taxonomy_Test.php b/tests/WP/Dashboard/User_Interface/SEO_Scores/Non_Filtering_Taxonomy_Test.php new file mode 100644 index 00000000000..0f1a834702a --- /dev/null +++ b/tests/WP/Dashboard/User_Interface/SEO_Scores/Non_Filtering_Taxonomy_Test.php @@ -0,0 +1,38 @@ +set_param( 'contentType', 'post' ); + $request->set_param( 'taxonomy', 'post_tag' ); + $request->set_param( 'term', 'irrelevant' ); + + $response = \rest_get_server()->dispatch( $request ); + + $this->assertInstanceOf( WP_REST_Response::class, $response ); + + $response_data = $response->get_data(); + + $this->assertSame( 400, $response->status ); + $this->assertSame( $response_data['error'], 'Invalid taxonomy.' ); + } +} diff --git a/tests/WP/Dashboard/User_Interface/SEO_Scores/Not_Priviliged_User_Test.php b/tests/WP/Dashboard/User_Interface/SEO_Scores/Not_Priviliged_User_Test.php new file mode 100644 index 00000000000..8cc6831bbcc --- /dev/null +++ b/tests/WP/Dashboard/User_Interface/SEO_Scores/Not_Priviliged_User_Test.php @@ -0,0 +1,38 @@ +factory->user->create_and_get( [ 'role' => 'author' ] ); + \wp_set_current_user( $user->ID ); + + $request = new WP_REST_Request( 'GET', '/yoast/v1/seo_scores' ); + $request->set_param( 'contentType', 'post' ); + + $response = \rest_get_server()->dispatch( $request ); + + $this->assertInstanceOf( WP_REST_Response::class, $response ); + + $response_data = $response->get_data(); + + $this->assertSame( $response_data['code'], 'rest_forbidden' ); + $this->assertSame( $response_data['data']['status'], 403 ); + } +} diff --git a/tests/WP/Sitemaps/Post_Type_Sitemap_Provider_Test.php b/tests/WP/Sitemaps/Post_Type_Sitemap_Provider_Test.php index 68668c8595c..c768615f2a2 100644 --- a/tests/WP/Sitemaps/Post_Type_Sitemap_Provider_Test.php +++ b/tests/WP/Sitemaps/Post_Type_Sitemap_Provider_Test.php @@ -102,9 +102,9 @@ public function test_get_index_links_multiple_entries_non_paged() { */ public function test_get_index_links_empty_bucket() { - $this->factory->post->create(); - $this->excluded_posts = [ $this->factory->post->create() ]; // Remove this post. - $this->factory->post->create(); + self::factory()->post->create( [ 'post_date' => '2024-01-01 00:00:01' ] ); + $this->excluded_posts = [ self::factory()->post->create( [ 'post_date' => '2024-01-01 00:00:02' ] ) ]; // Remove this post. + self::factory()->post->create( [ 'post_date' => '2024-01-01 00:00:03' ] ); \add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', [ $this, 'exclude_post' ] ); \add_filter( 'wpseo_sitemap_entries_per_page', [ $this, 'return_one' ] );