-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release v2.2.3
- Loading branch information
Showing
51 changed files
with
1,502 additions
and
303 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
Tests/Fixtures/classes/Admin/AdminSubscriber/pluginActionLinks.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
return [ | ||
'test_data' => [ | ||
'testShouldReturnDocumentationLinkAmongPluginLinksIfPlanLabelIsNotStarter' => [ | ||
'config' => [ | ||
'plan_id' => 2, | ||
], | ||
'expected' => [ | ||
'Documentation' | ||
], | ||
], | ||
'testShouldReturnUpgradeLinkAmongPluginLinksIfPlanLabelIsStarter' => [ | ||
'config' => [ | ||
'plan_id' => 1, | ||
], | ||
'expected' => [ | ||
'Upgrade', | ||
'class="imagify-plugin-upgrade"' | ||
], | ||
], | ||
] | ||
]; |
42 changes: 42 additions & 0 deletions
42
Tests/Unit/classes/Admin/AdminSubscriber/pluginActionLinks.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
namespace Imagify\Tests\Unit\classes; | ||
|
||
use Mockery; | ||
use Brain\Monkey\Functions; | ||
use Imagify\Tests\Unit\TestCase; | ||
use Imagify\User\User; | ||
use Imagify\Admin\AdminSubscriber; | ||
|
||
/** | ||
* Tests for \Imagify\Admin\AdminSubscriber->plugin_action_links(). | ||
* | ||
* @covers \Imagify\Admin\AdminSubscriber::plugin_action_links | ||
* @group ImagifyAPI | ||
*/ | ||
class Test_PluginActionLinks extends TestCase { | ||
protected $admin_subscriber, $user, $plan_id; | ||
|
||
public function setUp(): void { | ||
parent::setUp(); | ||
|
||
$this->user = Mockery::mock( User::class ); | ||
$this->admin_subscriber = new AdminSubscriber( $this->user ); | ||
} | ||
|
||
/** | ||
* @dataProvider configTestData | ||
*/ | ||
public function testShouldReturnAsExpected( $config, $expected ) { | ||
$this->user->plan_id = $config['plan_id']; | ||
|
||
Functions\when( 'imagify_get_external_url' )->justReturn( 'https://example.org' ); | ||
Functions\when( 'get_imagify_admin_url' )->justReturn( 'https://example.org' ); | ||
|
||
$plugin_action_links = $this->admin_subscriber->plugin_action_links([]); | ||
$plugin_action_links = implode( '|', $plugin_action_links ); | ||
|
||
foreach ( $expected as $text ) { | ||
$this->assertStringContainsString( $text, $plugin_action_links ); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,18 +31,47 @@ public function testShouldReturnFalseWhenFetchedUserData() { | |
'is_monthly' => true, | ||
]; | ||
|
||
Functions\when( 'get_transient' )->justReturn( false ); | ||
Functions\when( 'get_imagify_user' )->justReturn( $userData ); | ||
Functions\when( 'set_transient')->justReturn(); | ||
|
||
$this->assertFalse( ( new User() )->get_error() ); | ||
} | ||
|
||
/** | ||
* Test \Imagify\User\User() should return cached user data if available. | ||
*/ | ||
public function testShouldReturnFromCachedUserDataIfAvailable() { | ||
$userData = (object) [ | ||
'id' => 1, | ||
'email' => '[email protected]', | ||
'plan_id' => '1', | ||
'plan_label' => 'free', | ||
'quota' => 456, | ||
'extra_quota' => 0, | ||
'extra_quota_consumed' => 0, | ||
'consumed_current_month_quota' => 123, | ||
'next_date_update' => '', | ||
'is_active' => 1, | ||
'is_monthly' => true, | ||
]; | ||
|
||
Functions\when( 'get_transient' )->justReturn( $userData ); | ||
Functions\expect( 'get_imagify_user' )->never(); | ||
Functions\when( 'set_transient')->justReturn(); | ||
|
||
$this->assertSame( '[email protected]', ( new User() )->email ); | ||
} | ||
|
||
/** | ||
* Test \Imagify\User\User->get_error() should return a WP_Error object when couldn’t fetch user account data. | ||
*/ | ||
public function testShouldReturnErrorWhenCouldNotFetchUserData() { | ||
$wp_error = new WP_Error( 'error_id', 'Error Message' ); | ||
|
||
Functions\when( 'get_transient' )->justReturn( false ); | ||
Functions\when( 'get_imagify_user' )->justReturn( $wp_error ); | ||
Functions\when( 'set_transient')->justReturn(); | ||
|
||
$this->assertSame( $wp_error, ( new User() )->get_error() ); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.