Skip to content

Commit

Permalink
Updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jeawhanlee committed Oct 18, 2024
1 parent a72f32d commit 7bf9c44
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
'link' => 'https://imagify.io/',
'cta' => [
'text' => 'Activate',
'url' => 'http://example.org/wp-admin/admin-post.php?action=install_imagify_from_partner_backwpup&_wpnonce=9a68f00b8d&_wp_http_referer=http%253A%252F%252Fexample.org%252Fwp-admin'
'url' => 'http://example.org/wp-admin/admin-post.php?action=install_imagify_from_partner_backwpup&_wpnonce=9a68f00b8d&_wp_http_referer=https%3A%2F%2Fexample.org%2Fwp-admin'
],
],
'seo-by-rank-math/rank-math' => [
Expand Down Expand Up @@ -267,7 +267,7 @@
'link' => 'https://imagify.io/',
'cta' => [
'text' => 'Install',
'url' => 'http://example.org/wp-admin/admin-post.php?action=install_imagify_from_partner_uk-cookie-consent&_wpnonce=9a68f00b8d&_wp_http_referer=http%253A%252F%252Fexample.org%252Fwp-admin'
'url' => 'http://example.org/wp-admin/admin-post.php?action=install_imagify_from_partner_uk-cookie-consent&_wpnonce=9a68f00b8d&_wp_http_referer=https%3A%2F%2Fexample.org%2Fwp-admin'
],
],
'seo-by-rank-math/rank-math' => [
Expand Down
23 changes: 17 additions & 6 deletions tests/Unit/src/Model/PluginFamily/filterPluginsByActivation.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,19 @@ class TestFilterPluginsByActivation extends TestCase {

public function set_up() {
parent::set_up();

$this->plugin_family = $this->getMockBuilder(PluginFamily::class)
->setMethods( ['get_current_url'] )
->getMock();

$this->plugin_family = new PluginFamily();

$_SERVER = [
'SERVER_PORT' => 80,
'HTTP_HOST' => 'example.org',
'REQUEST_URI' => '/wp-admin',
];
}

public function tear_down() {
$_SERVER = [];

parent::tear_down();
}

Expand All @@ -47,7 +53,11 @@ public function testShouldReturnExpected( $config, $expected ) {
return $plugin === $config['active_plugin'];
} );

Functions\when( 'admin_url' )->justReturn( 'http://example.org/wp-admin/admin-post.php' );
Functions\when( 'admin_url' )->alias(
function ( $path ) {
return "http://example.org/wp-admin/{$path}";
}
);
Functions\when( 'wp_create_nonce' )->justReturn( '9a68f00b8d' );
Functions\when( 'add_query_arg' )->alias( function( $args, $link ) {
$url = '';
Expand All @@ -59,7 +69,8 @@ public function testShouldReturnExpected( $config, $expected ) {
return $link . '?' . rtrim( $url, '&' );
} );

$this->plugin_family->method('get_current_url')->willReturn( 'http%3A%2F%2Fexample.org%2Fwp-admin' );
Functions\when( 'wp_unslash' )->returnArg();
Functions\when( 'is_ssl' )->justReturn( true );

if ( isset( $config['is_installed'] ) ) {
Functions\when( 'file_exists' )->justReturn( $config['is_installed'] );
Expand Down

0 comments on commit 7bf9c44

Please sign in to comment.