Files

107 lines
3.5 KiB
PHP
Raw Permalink Normal View History

2020-09-27 10:23:17 +02:00
<?php
declare(strict_types=1);
namespace ShlinkioApiTest\Shlink\Rest\Action;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
2020-09-27 10:23:17 +02:00
use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase;
class ListDomainsTest extends ApiTestCase
{
#[Test, DataProvider('provideApiKeysAndDomains')]
public function domainsAreProperlyListed(string $apiKey, array $expectedDomains): void
2020-09-27 10:23:17 +02:00
{
$resp = $this->callApiWithKey(self::METHOD_GET, '/domains', [], $apiKey);
2020-09-27 10:23:17 +02:00
$respPayload = $this->getJsonResponsePayload($resp);
self::assertEquals(self::STATUS_OK, $resp->getStatusCode());
self::assertEquals(
[
'domains' => [
'data' => $expectedDomains,
'defaultRedirects' => [
'baseUrlRedirect' => null,
'regular404Redirect' => null,
'invalidShortUrlRedirect' => null,
],
],
2020-09-27 10:23:17 +02:00
],
$respPayload,
);
2020-09-27 10:23:17 +02:00
}
2023-02-09 09:32:38 +01:00
public static function provideApiKeysAndDomains(): iterable
{
yield 'admin API key' => [
'valid_api_key',
[
[
'domain' => 's.test',
'isDefault' => true,
'redirects' => [
'baseUrlRedirect' => null,
'regular404Redirect' => null,
'invalidShortUrlRedirect' => null,
],
2021-08-03 17:00:26 +02:00
],
[
'domain' => 'detached-with-redirects.com',
'isDefault' => false,
'redirects' => [
'baseUrlRedirect' => 'foo.com',
'regular404Redirect' => 'bar.com',
'invalidShortUrlRedirect' => null,
],
2021-08-03 17:00:26 +02:00
],
[
'domain' => 'example.com',
'isDefault' => false,
'redirects' => [
'baseUrlRedirect' => null,
'regular404Redirect' => null,
'invalidShortUrlRedirect' => null,
],
2021-08-03 17:00:26 +02:00
],
[
'domain' => 'some-domain.com',
'isDefault' => false,
'redirects' => [
'baseUrlRedirect' => null,
'regular404Redirect' => null,
'invalidShortUrlRedirect' => null,
],
2021-08-03 17:00:26 +02:00
],
],
];
yield 'author API key' => [
'author_api_key',
[
[
'domain' => 's.test',
'isDefault' => true,
'redirects' => [
'baseUrlRedirect' => null,
'regular404Redirect' => null,
'invalidShortUrlRedirect' => null,
],
2021-08-03 17:00:26 +02:00
],
],
];
yield 'domain API key' => [
'domain_api_key',
[
[
'domain' => 'example.com',
'isDefault' => false,
'redirects' => [
'baseUrlRedirect' => null,
'regular404Redirect' => null,
'invalidShortUrlRedirect' => null,
],
2021-08-03 17:00:26 +02:00
],
],
];
}
2020-09-27 10:23:17 +02:00
}