shlink/module/Rest/test-api/Action/ListDomainsTest.php

97 lines
3 KiB
PHP
Raw Normal View History

2020-09-27 11:23:17 +03:00
<?php
declare(strict_types=1);
namespace ShlinkioApiTest\Shlink\Rest\Action;
use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase;
class ListDomainsTest extends ApiTestCase
{
/**
* @test
* @dataProvider provideApiKeysAndDomains
*/
public function domainsAreProperlyListed(string $apiKey, array $expectedDomains): void
2020-09-27 11:23:17 +03:00
{
$resp = $this->callApiWithKey(self::METHOD_GET, '/domains', [], $apiKey);
2020-09-27 11:23:17 +03: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 11:23:17 +03:00
],
], $respPayload);
}
public function provideApiKeysAndDomains(): iterable
{
yield 'admin API key' => ['valid_api_key', [
[
'domain' => 'doma.in',
'isDefault' => true,
2021-08-03 18:00:26 +03:00
'redirects' => [
'baseUrlRedirect' => null,
'regular404Redirect' => null,
'invalidShortUrlRedirect' => null,
],
],
[
'domain' => 'detached-with-redirects.com',
'isDefault' => false,
2021-08-03 18:00:26 +03:00
'redirects' => [
'baseUrlRedirect' => 'foo.com',
'regular404Redirect' => 'bar.com',
'invalidShortUrlRedirect' => null,
],
],
[
'domain' => 'example.com',
'isDefault' => false,
2021-08-03 18:00:26 +03:00
'redirects' => [
'baseUrlRedirect' => null,
'regular404Redirect' => null,
'invalidShortUrlRedirect' => null,
],
],
[
'domain' => 'some-domain.com',
'isDefault' => false,
2021-08-03 18:00:26 +03:00
'redirects' => [
'baseUrlRedirect' => null,
'regular404Redirect' => null,
'invalidShortUrlRedirect' => null,
],
],
]];
yield 'author API key' => ['author_api_key', [
[
'domain' => 'doma.in',
'isDefault' => true,
2021-08-03 18:00:26 +03:00
'redirects' => [
'baseUrlRedirect' => null,
'regular404Redirect' => null,
'invalidShortUrlRedirect' => null,
],
],
]];
yield 'domain API key' => ['domain_api_key', [
[
'domain' => 'example.com',
'isDefault' => false,
2021-08-03 18:00:26 +03:00
'redirects' => [
'baseUrlRedirect' => null,
'regular404Redirect' => null,
'invalidShortUrlRedirect' => null,
],
],
]];
}
2020-09-27 11:23:17 +03:00
}