Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions admin/class-convertkit-mm-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@ private function check_credentials() {
// Remove from settings.
$this->settings->delete_credentials();

// Redirect to General screen, which will now show the ConvertKit_Settings_OAuth screen, because
// the Plugin has no access token.
// Reload settings screen, to reflect no credentials exist.
wp_safe_redirect(
add_query_arg(
array(
Expand Down
8 changes: 4 additions & 4 deletions includes/class-convertkit-mm-api.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php
/**
* ConvertKit API class for WPForms.
* ConvertKit API class for MemberMouse.
*
* @package ConvertKit_WPForms
* @package ConvertKit_MM
* @author ConvertKit
*/

/**
* ConvertKit API class for WPForms.
* ConvertKit API class for MemberMouse.
*
* @package ConvertKit_WPForms
* @package ConvertKit_MM
* @author ConvertKit
*/
class ConvertKit_MM_API extends ConvertKit_API_V4 {
Expand Down
2 changes: 1 addition & 1 deletion includes/class-convertkit-mm-resource-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* ConvertKit Tags Resource class.
*
* @package ConvertKit_WPForms
* @package ConvertKit_MM
* @author ConvertKit
*/

Expand Down
162 changes: 162 additions & 0 deletions tests/Integration/ResourceCustomFieldsNoDataTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
<?php

namespace Tests;

use lucatume\WPBrowser\TestCase\WPTestCase;

/**
* Tests for the CKWC_Resource_Custom_Fields class when no data is present in the API.
*
* @since 1.3.7
*/
class ResourceCustomFieldsNoDataTest extends \Codeception\TestCase\WPTestCase
{
/**
* The testing implementation.
*
* @var \WpunitTester.
*/
protected $tester;

/**
* Holds the ConvertKit Settings class.
*
* @since 1.3.7
*
* @var ConvertKit_MM_Settings
*/
private $settings;

/**
* Holds the ConvertKit Resource class.
*
* @since 1.3.7
*
* @var ConvertKit_MM_Resource_Custom_Fields
*/
private $resource;

/**
* Performs actions before each test.
*
* @since 1.3.7
*/
public function setUp(): void
{
parent::setUp();

// Activate Plugin.
activate_plugins('convertkit/wp-convertkit.php');

// Store credentials in Plugin's settings.
$this->settings = new \ConvertKit_MM_Settings();
update_option(
$this->settings::SETTINGS_NAME,
[
'access_token' => $_ENV['CONVERTKIT_OAUTH_ACCESS_TOKEN_NO_DATA'],
'refresh_token' => $_ENV['CONVERTKIT_OAUTH_REFRESH_TOKEN_NO_DATA'],
]
);

// Initialize the resource class we want to test.
$this->resource = new \ConvertKit_MM_Resource_Custom_Fields();

// Confirm initialization didn't result in an error.
$this->assertNotInstanceOf(\WP_Error::class, $this->resource->resources);

// Initialize the resource class, fetching resources from the API and caching them in the options table.
$result = $this->resource->init();

// Confirm calling init() didn't result in an error.
$this->assertNotInstanceOf(\WP_Error::class, $result);
}

/**
* Performs actions after each test.
*
* @since 1.3.7
*/
public function tearDown(): void
{
// Delete Credentials and Resources from Plugin's settings.
delete_option($this->settings::SETTINGS_NAME);
delete_option($this->resource->settings_name);
delete_option($this->resource->settings_name . '_last_queried');

// Destroy the resource class we tested.
unset($this->resource);

// Deactivate Plugin.
deactivate_plugins('convertkit/wp-convertkit.php');

parent::tearDown();
}

/**
* Test that the refresh() function performs as expected.
*
* @since 1.3.7
*/
public function testRefresh()
{
// Confirm that no resources exist in the stored options table data.
$result = $this->resource->refresh();
$this->assertNotInstanceOf(\WP_Error::class, $result);
$this->assertIsArray($result);
$this->assertCount(0, $result);
}

/**
* Test that the expiry timestamp is set and returns the expected value.
*
* @since 1.3.7
*/
public function testExpiry()
{
// Define the expected expiry date based on the resource class' $cache_duration setting.
$expectedExpiryDate = date('Y-m-d', time() + $this->resource->cache_duration);

// Fetch the actual expiry date set when the resource class was initialized.
$expiryDate = date('Y-m-d', $this->resource->last_queried + $this->resource->cache_duration);

// Confirm both dates match.
$this->assertEquals($expectedExpiryDate, $expiryDate);
}

/**
* Test that the get() function performs as expected.
*
* @since 1.3.7
*/
public function testGet()
{
// Confirm that no resources exist in the stored options table data.
$result = $this->resource->get();
$this->assertNotInstanceOf(\WP_Error::class, $result);
$this->assertIsArray($result);
$this->assertCount(0, $result);
}

/**
* Test that the count() function returns the number of resources.
*
* @since 1.3.7
*/
public function testCount()
{
$result = $this->resource->get();
$this->assertEquals($this->resource->count(), count($result));
}

/**
* Test that the exist() function performs as expected.
*
* @since 1.3.7
*/
public function testExist()
{
// Confirm that the function returns false, because resources do not exist.
$result = $this->resource->exist();
$this->assertSame($result, false);
}
}
Loading