Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
burhandodhy committed Jan 28, 2025
1 parent 74ab5ea commit 9d40dae
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tests/php/TestAdminNotices.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 9d40dae

Please sign in to comment.