Skip to content

Commit

Permalink
Update tests to reflect new changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ernilambar committed Dec 26, 2023
1 parent f603ecd commit bb56374
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
8 changes: 5 additions & 3 deletions includes/Admin/Admin_Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,20 +220,22 @@ public function filter_plugin_action_links( $actions, $plugin_file, $plugin_data

$plugin_check_base_name = plugin_basename( WP_PLUGIN_CHECK_MAIN_FILE );

if ( in_array( $context, array( 'mustuse', 'dropins' ), true ) ) {
return $actions;

Check warning on line 224 in includes/Admin/Admin_Page.php

View check run for this annotation

Codecov / codecov/patch

includes/Admin/Admin_Page.php#L223-L224

Added lines #L223 - L224 were not covered by tests
}

if ( $plugin_check_base_name === $plugin_file ) {
$actions = array_merge(
array(
'plugin-check' => sprintf(
sprintf(
'<a href="%1$s">%2$s</a>',
esc_url( admin_url( 'tools.php?page=plugin-check' ) ),
esc_html__( 'Plugin Check', 'plugin-check' )
),
),
$actions
);

Check warning on line 237 in includes/Admin/Admin_Page.php

View check run for this annotation

Codecov / codecov/patch

includes/Admin/Admin_Page.php#L227-L237

Added lines #L227 - L237 were not covered by tests
}

if ( in_array( $context, array( 'mustuse', 'dropins' ), true ) || $plugin_check_base_name === $plugin_file ) {
return $actions;
}

Expand Down
16 changes: 13 additions & 3 deletions tests/phpunit/tests/Admin/Admin_Page_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,13 @@ public function test_filter_plugin_action_links() {
);
}

public function test_filter_plugin_action_links_should_not_add_check_link_for_plugin_checker() {
public function test_filter_plugin_action_links_plugin_should_have_self_admin_page_link_only() {

$base_file = plugin_basename( WP_PLUGIN_CHECK_MAIN_FILE );

$action_links = $this->admin_page->filter_plugin_action_links( array(), $base_file, array(), 'all' );
$this->assertEmpty( $action_links );
$this->assertNotEmpty( $action_links );
$this->assertEquals( 1, count( $action_links ) );

/** Administrator check */
$admin_user = self::factory()->user->create( array( 'role' => 'administrator' ) );
Expand All @@ -171,7 +172,16 @@ public function test_filter_plugin_action_links_should_not_add_check_link_for_pl
wp_set_current_user( $admin_user );
$action_links = $this->admin_page->filter_plugin_action_links( array(), $base_file, array(), 'all' );

$this->assertEmpty( $action_links );
$this->assertEquals( 1, count( $action_links ) );

$this->assertEquals(
sprintf(
'<a href="%1$s">%2$s</a>',
esc_url( admin_url( 'tools.php?page=plugin-check' ) ),
esc_html__( 'Plugin Check', 'plugin-check' )
),
$action_links[0]
);
}

/**
Expand Down

0 comments on commit bb56374

Please sign in to comment.