Skip to content

Commit

Permalink
Add quick checks to facade (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
ildyria authored Sep 27, 2024
1 parent 75130dc commit 6395cf0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion config/verify.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
'validation' => [
ValidateHash::class => 'c34da4a4523e54f303c23cd22eaf252f74ed7965',
ValidateSignature::class => 'a3d4081247b4f56c8aeb7c6b192415700e27acc0',
Verify::class => 'cda79b50522e9189aa928a5f471ebc20a049db76',
Verify::class => 'd186e2502a0b89e1713ce4d43d1c69ff5e7c311c',
VerifySupporterStatus::class => '6358c45ed0414c1e2697e0881238659fa6221bed',
VerifyServiceProvider::class => '927a8f3c811fc82cb8a0ac2667c06e7d292c3633',
],
Expand Down
20 changes: 20 additions & 0 deletions src/Verify.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,26 @@ public function check(Status $required_status = Status::SUPPORTER_EDITION): bool
return false;
}

/**
* Returns true if the user is a supporter (or plus registered user).
*
* @return bool
*/
public function is_supporter(): bool
{
return $this->check(Status::SUPPORTER_EDITION);
}

/**
* Return true of the user is a plus registered user.
*
* @return bool
*/
public function is_plus(): bool
{
return $this->check(Status::PLUS_EDITION);
}

/**
* Authorize the operation if the installation is verified.
* Otherwise throw an exception.
Expand Down
6 changes: 6 additions & 0 deletions tests/Verify/VerifyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public function testVerifyDefault(): void
self::assertTrue($verify->check(Status::FREE_EDITION));
self::assertFalse($verify->check(Status::SUPPORTER_EDITION));
self::assertFalse($verify->check(Status::PLUS_EDITION));
self::assertFalse($verify->is_supporter()); // User is not recognised as supporter.
self::assertFalse($verify->is_plus()); // User is not recognised as plus.

$this->assertThrows(fn () => $verify->authorize(Status::SUPPORTER_EDITION), SupporterOnlyOperationException::class, 'supporters');
$this->assertThrows(fn () => $verify->authorize(Status::PLUS_EDITION), SupporterOnlyOperationException::class, 'plus');
Expand All @@ -37,6 +39,8 @@ public function testVerifySupporterDefault(): void
self::assertTrue($verify->check(Status::FREE_EDITION));
self::assertTrue($verify->check(Status::SUPPORTER_EDITION));
self::assertFalse($verify->check(Status::PLUS_EDITION));
self::assertTrue($verify->is_supporter()); // User is recognised as supporter.
self::assertFalse($verify->is_plus()); // User is not recognised as plus.

$this->assertThrows(fn () => $verify->authorize(Status::PLUS_EDITION), SupporterOnlyOperationException::class, 'plus');
}
Expand All @@ -52,6 +56,8 @@ public function testVerifyPlus(): void
self::assertTrue($verify->check(Status::FREE_EDITION));
self::assertTrue($verify->check(Status::SUPPORTER_EDITION));
self::assertTrue($verify->check(Status::PLUS_EDITION));
self::assertTrue($verify->is_supporter()); // user is recognised as supporter.
self::assertTrue($verify->is_plus()); // user is recognised as plus.
}

public function testVerifyValidate(): void
Expand Down

0 comments on commit 6395cf0

Please sign in to comment.