Skip to content

Commit

Permalink
Merge pull request #8966 from awesomemotive/issue/8965
Browse files Browse the repository at this point in the history
Catch exceptions and return false #8965
  • Loading branch information
ashleyfae authored Nov 3, 2021
2 parents 09836af + 5ea4f9e commit 4895669
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 4 deletions.
24 changes: 20 additions & 4 deletions includes/admin/class-pass-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,11 @@ public function hasIndividualLicense() {
* @return bool
*/
public function hasPersonalPass() {
return self::pass_compare( $this->highest_pass_id, self::PERSONAL_PASS_ID, '=' );
try {
return self::pass_compare( $this->highest_pass_id, self::PERSONAL_PASS_ID, '=' );
} catch ( \Exception $e ) {
return false;
}
}

/**
Expand All @@ -185,7 +189,11 @@ public function hasPersonalPass() {
* @return bool
*/
public function hasExtendedPass() {
return self::pass_compare( $this->highest_pass_id, self::EXTENDED_PASS_ID, '=' );
try {
return self::pass_compare( $this->highest_pass_id, self::EXTENDED_PASS_ID, '=' );
} catch ( \Exception $e ) {
return false;
}
}

/**
Expand All @@ -196,7 +204,11 @@ public function hasExtendedPass() {
* @return bool
*/
public function hasProfessionalPass() {
return self::pass_compare( $this->highest_pass_id, self::PROFESSIONAL_PASS_ID, '=' );
try {
return self::pass_compare( $this->highest_pass_id, self::PROFESSIONAL_PASS_ID, '=' );
} catch( \Exception $e ) {
return false;
}
}

/**
Expand All @@ -208,7 +220,11 @@ public function hasProfessionalPass() {
* @return bool
*/
public function hasAllAccessPass() {
return self::pass_compare( $this->highest_pass_id, self::ALL_ACCESS_PASS_ID, '>=' );
try {
return self::pass_compare( $this->highest_pass_id, self::ALL_ACCESS_PASS_ID, '>=' );
} catch( \Exception $e ) {
return false;
}
}

/**
Expand Down
40 changes: 40 additions & 0 deletions tests/tests-pass-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public static function wpSetUpBeforeClass() {
public function setUp() {
parent::setUp();

global $edd_licensed_products;
$edd_licensed_products = array();

delete_option( 'edd_pass_licenses' );
}

Expand Down Expand Up @@ -115,4 +118,41 @@ public function test_no_pass_id_if_pass_outside_check_window() {
$this->assertFalse( $manager->has_pass() );
}

/**
* @covers \EDD\Admin\Pass_Manager::isFree
*/
public function test_site_with_no_licenses() {
$passManager = new \EDD\Admin\Pass_Manager();

$this->assertTrue( $passManager->isFree() );
$this->assertFalse( $passManager->hasPersonalPass() );
$this->assertFalse( $passManager->hasExtendedPass() );
$this->assertFalse( $passManager->hasProfessionalPass() );
$this->assertFalse( $passManager->hasAllAccessPass() );
$this->assertFalse( $passManager->has_pass() );
}

/**
* @covers \EDD\Admin\Pass_Manager::hasPersonalPass
*/
public function test_site_with_personal_pass() {
$passes = array(
'license_1' => array(
'pass_id' => \EDD\Admin\Pass_Manager::PERSONAL_PASS_ID,
'time_checked' => time()
),
);

update_option( 'edd_pass_licenses', json_encode( $passes ) );

global $edd_licensed_products;
$edd_licensed_products[] = 'product';

$passManager = new \EDD\Admin\Pass_Manager();

$this->assertFalse( $passManager->isFree() );
$this->assertTrue( $passManager->hasPersonalPass() );
$this->assertTrue( $passManager->has_pass() );
}

}

0 comments on commit 4895669

Please sign in to comment.