From 9d40dae9d6e60984da51fcb3f1ac622d91690856 Mon Sep 17 00:00:00 2001 From: Burhan Nasir Date: Tue, 28 Jan 2025 18:33:23 +0500 Subject: [PATCH] Add test --- tests/php/TestAdminNotices.php | 47 ++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tests/php/TestAdminNotices.php b/tests/php/TestAdminNotices.php index ad80a7355..c27b3dcda 100644 --- a/tests/php/TestAdminNotices.php +++ b/tests/php/TestAdminNotices.php @@ -674,6 +674,8 @@ public function testNumberOfPostsBiggerThanItemPerCycle() { /** * Tests that the admin notice with the scope 'site' appears only on the sub site when the plugin is network-activated. + * + * @group skip-on-single-site */ public function testNoticeWithScopeSiteShowsOnlyOnSite() { global $pagenow, $tax; @@ -715,6 +717,51 @@ function ( $notices ) { $this->assertArrayHasKey( 'too_many_posts_on_term', $notices ); } + /** + * Tests that the admin notice with the scope 'site' has no effect when the plugin is not network-activated. + * + * @group skip-on-multi-site + */ + public function testNoticeWithScopeSiteHasNoEffectOnNonNetwork() { + global $pagenow, $tax; + + // set global variables. + $pagenow = 'edit-tags.php'; + + set_current_screen( 'edit-tags' ); + $tax = get_taxonomy( 'category' ); + + $number_of_posts = ElasticPress\IndexHelper::factory()->get_index_default_per_page() + 10; + $term = $this->factory->term->create_and_get( array( 'taxonomy' => 'category' ) ); + $this->posts = $this->factory->post->create_many( + $number_of_posts, + [ + 'tax_input' => [ + 'category' => [ + $term->term_id, + ], + ], + ] + ); + + add_action( + 'ep_admin_notices', + function ( $notices ) { + $notices['test_notice'] = [ + 'type' => 'error', + 'dismiss' => true, + 'html' => 'Test notice', + ]; + + return $notices; + } + ); + + $notices = ElasticPress\AdminNotices::factory()->get_notices(); + $this->assertCount( 2, $notices ); + $this->assertArrayHasKey( 'too_many_posts_on_term', $notices ); + } + /** * Utilitary function to set `ep_post_mapping_version_determined` * as the wanted Mapping version.