-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Miscellaneous Client Test Suite (#88)
* Miscellaneous Client Test Suite * InvoiceCheckoutHtml Result Class + Test
- Loading branch information
Showing
7 changed files
with
130 additions
and
19 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
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BTCPayServer\Result; | ||
|
||
class InvoiceCheckoutHtml | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $html; | ||
|
||
public function __construct(string $html) | ||
{ | ||
$this->html = $html; | ||
} | ||
|
||
public function getHtml(): string | ||
{ | ||
return $this->html; | ||
} | ||
|
||
public function __toString() | ||
{ | ||
return $this->html; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BTCPayServer\Result; | ||
|
||
class PermissionMetadataList extends AbstractListResult | ||
{ | ||
/** | ||
* @return PermissionMetadata[] | ||
*/ | ||
public function all(): array | ||
{ | ||
$permissionMetadataList = []; | ||
foreach ($this->getData() as $permissionMetadata) { | ||
$permissionMetadataList[] = new PermissionMetadata($permissionMetadata); | ||
} | ||
return $permissionMetadataList; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BTCPayServer\Tests; | ||
|
||
use BTCPayServer\Client\Invoice; | ||
use BTCPayServer\Client\Miscellaneous; | ||
use BTCPayServer\Result\InvoiceCheckoutHtml; | ||
use BTCPayServer\Result\LanguageCode; | ||
use BTCPayServer\Result\LanguageCodeList; | ||
use BTCPayServer\Result\PermissionMetadata; | ||
use BTCPayServer\Result\PermissionMetadataList; | ||
use BTCPayServer\Util\PreciseNumber; | ||
|
||
final class MiscellaneousTest extends BaseTest | ||
{ | ||
private Miscellaneous $miscellaneousClient; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->miscellaneousClient = new Miscellaneous($this->host, $this->apiKey); | ||
} | ||
|
||
public function testItCanGetPermissionMetadata(): void | ||
{ | ||
$result = $this->miscellaneousClient->getPermissionMetadata(); | ||
|
||
$this->assertInstanceOf(PermissionMetadataList::class, $result); | ||
|
||
foreach ($result->all() as $permissionMetadata) { | ||
$this->assertInstanceOf(PermissionMetadata::class, $permissionMetadata); | ||
$this->assertIsString($permissionMetadata->getName()); | ||
$this->assertIsArray($permissionMetadata->getIncluded()); | ||
} | ||
} | ||
|
||
public function testItCanGetLanguageCodes(): void | ||
{ | ||
$result = $this->miscellaneousClient->getLanguageCodes(); | ||
|
||
$this->assertInstanceOf(LanguageCodeList::class, $result); | ||
|
||
foreach ($result->all() as $languageCode) { | ||
$this->assertInstanceOf(LanguageCode::class, $languageCode); | ||
$this->assertIsString($languageCode->getCode()); | ||
$this->assertIsString($languageCode->getCurrentLanguage()); | ||
} | ||
} | ||
|
||
public function testItCanGetInvoiceCheckout(): void | ||
{ | ||
$invoiceClient = new Invoice($this->host, $this->apiKey); | ||
|
||
$invoice = $invoiceClient->createInvoice( | ||
storeId: $this->storeId, | ||
currency: 'SATS', | ||
amount: PreciseNumber::parseString('1000'), | ||
); | ||
|
||
$result = $this->miscellaneousClient->getInvoiceCheckout($invoice->getId(), null); | ||
|
||
$this->assertInstanceOf(InvoiceCheckoutHtml::class, $result); | ||
$this->assertStringContainsString('<!DOCTYPE html>', $result->getHtml()); | ||
} | ||
} |