2019-01-30 11:28:07 -06:00
|
|
|
<?php
|
2019-10-05 10:26:10 -05:00
|
|
|
|
2019-01-30 11:28:07 -06:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkioApiTest\Shlink\Rest\Action;
|
|
|
|
|
|
|
|
use Cake\Chronos\Chronos;
|
|
|
|
use GuzzleHttp\RequestOptions;
|
2019-08-11 09:30:46 -05:00
|
|
|
use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase;
|
2019-02-26 15:56:43 -06:00
|
|
|
|
2019-02-17 13:28:34 -06:00
|
|
|
use function Functional\map;
|
|
|
|
use function range;
|
2019-11-27 13:48:35 -06:00
|
|
|
use function sprintf;
|
2019-01-30 11:28:07 -06:00
|
|
|
|
2021-01-24 02:25:36 -06:00
|
|
|
class CreateShortUrlTest extends ApiTestCase
|
2019-01-30 11:28:07 -06:00
|
|
|
{
|
2019-02-17 13:28:34 -06:00
|
|
|
/** @test */
|
2019-02-03 04:01:38 -06:00
|
|
|
public function createsNewShortUrlWhenOnlyLongUrlIsProvided(): void
|
2019-01-30 11:28:07 -06:00
|
|
|
{
|
|
|
|
$expectedKeys = ['shortCode', 'shortUrl', 'longUrl', 'dateCreated', 'visitsCount', 'tags'];
|
|
|
|
[$statusCode, $payload] = $this->createShortUrl();
|
|
|
|
|
2020-10-03 17:35:14 -05:00
|
|
|
self::assertEquals(self::STATUS_OK, $statusCode);
|
2019-01-30 11:28:07 -06:00
|
|
|
foreach ($expectedKeys as $key) {
|
2020-10-03 17:35:14 -05:00
|
|
|
self::assertArrayHasKey($key, $payload);
|
2019-01-30 11:28:07 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-17 13:28:34 -06:00
|
|
|
/** @test */
|
2019-02-03 04:01:38 -06:00
|
|
|
public function createsNewShortUrlWithCustomSlug(): void
|
2019-01-30 11:28:07 -06:00
|
|
|
{
|
|
|
|
[$statusCode, $payload] = $this->createShortUrl(['customSlug' => 'my cool slug']);
|
|
|
|
|
2020-10-03 17:35:14 -05:00
|
|
|
self::assertEquals(self::STATUS_OK, $statusCode);
|
|
|
|
self::assertEquals('my-cool-slug', $payload['shortCode']);
|
2019-01-30 11:28:07 -06:00
|
|
|
}
|
|
|
|
|
2019-10-02 13:13:25 -05:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @dataProvider provideConflictingSlugs
|
|
|
|
*/
|
|
|
|
public function failsToCreateShortUrlWithDuplicatedSlug(string $slug, ?string $domain): void
|
|
|
|
{
|
2019-11-27 13:48:35 -06:00
|
|
|
$suffix = $domain === null ? '' : sprintf(' for domain "%s"', $domain);
|
|
|
|
$detail = sprintf('Provided slug "%s" is already in use%s.', $slug, $suffix);
|
|
|
|
|
2019-10-02 13:13:25 -05:00
|
|
|
[$statusCode, $payload] = $this->createShortUrl(['customSlug' => $slug, 'domain' => $domain]);
|
|
|
|
|
2020-10-03 17:35:14 -05:00
|
|
|
self::assertEquals(self::STATUS_BAD_REQUEST, $statusCode);
|
|
|
|
self::assertEquals(self::STATUS_BAD_REQUEST, $payload['status']);
|
|
|
|
self::assertEquals($detail, $payload['detail']);
|
|
|
|
self::assertEquals('INVALID_SLUG', $payload['type']);
|
|
|
|
self::assertEquals('Invalid custom slug', $payload['title']);
|
|
|
|
self::assertEquals($slug, $payload['customSlug']);
|
2019-11-27 13:48:35 -06:00
|
|
|
|
|
|
|
if ($domain !== null) {
|
2020-10-03 17:35:14 -05:00
|
|
|
self::assertEquals($domain, $payload['domain']);
|
2019-11-27 13:48:35 -06:00
|
|
|
} else {
|
2020-10-03 17:35:14 -05:00
|
|
|
self::assertArrayNotHasKey('domain', $payload);
|
2019-11-27 13:48:35 -06:00
|
|
|
}
|
2019-10-02 13:13:25 -05:00
|
|
|
}
|
|
|
|
|
2022-08-13 10:48:55 -05:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @dataProvider provideDuplicatedSlugApiVersions
|
|
|
|
*/
|
|
|
|
public function expectedTypeIsReturnedForConflictingSlugBasedOnApiVersion(
|
|
|
|
string $version,
|
|
|
|
string $expectedType,
|
|
|
|
): void {
|
|
|
|
[, $payload] = $this->createShortUrl(['customSlug' => 'custom'], version: $version);
|
|
|
|
self::assertEquals($expectedType, $payload['type']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideDuplicatedSlugApiVersions(): iterable
|
|
|
|
{
|
|
|
|
yield ['1', 'INVALID_SLUG'];
|
|
|
|
yield ['2', 'INVALID_SLUG'];
|
|
|
|
yield ['3', 'https://shlink.io/api/error/non-unique-slug'];
|
|
|
|
}
|
|
|
|
|
2021-01-31 03:53:18 -06:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @dataProvider provideTags
|
|
|
|
*/
|
|
|
|
public function createsNewShortUrlWithTags(array $providedTags, array $expectedTags): void
|
2019-01-30 11:28:07 -06:00
|
|
|
{
|
2021-01-31 03:53:18 -06:00
|
|
|
[$statusCode, ['tags' => $tags]] = $this->createShortUrl(['tags' => $providedTags]);
|
2019-01-30 11:28:07 -06:00
|
|
|
|
2020-10-03 17:35:14 -05:00
|
|
|
self::assertEquals(self::STATUS_OK, $statusCode);
|
2021-01-31 03:53:18 -06:00
|
|
|
self::assertEquals($expectedTags, $tags);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideTags(): iterable
|
|
|
|
{
|
|
|
|
yield 'simple tags' => [$simpleTags = ['foo', 'bar', 'baz'], $simpleTags];
|
|
|
|
yield 'tags with spaces' => [['fo o', ' bar', 'b az'], ['fo-o', 'bar', 'b-az']];
|
|
|
|
yield 'tags with special chars' => [['UUU', 'Aäa'], ['uuu', 'aäa']];
|
2019-01-30 11:28:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @dataProvider provideMaxVisits
|
|
|
|
*/
|
2019-02-03 04:01:38 -06:00
|
|
|
public function createsNewShortUrlWithVisitsLimit(int $maxVisits): void
|
2019-01-30 11:28:07 -06:00
|
|
|
{
|
|
|
|
[$statusCode, ['shortCode' => $shortCode]] = $this->createShortUrl(['maxVisits' => $maxVisits]);
|
|
|
|
|
2020-10-03 17:35:14 -05:00
|
|
|
self::assertEquals(self::STATUS_OK, $statusCode);
|
2019-01-30 11:28:07 -06:00
|
|
|
|
|
|
|
// Last request to the short URL will return a 404, and the rest, a 302
|
|
|
|
for ($i = 0; $i < $maxVisits; $i++) {
|
2020-10-03 17:35:14 -05:00
|
|
|
self::assertEquals(self::STATUS_FOUND, $this->callShortUrl($shortCode)->getStatusCode());
|
2019-01-30 11:28:07 -06:00
|
|
|
}
|
|
|
|
$lastResp = $this->callShortUrl($shortCode);
|
2020-10-03 17:35:14 -05:00
|
|
|
self::assertEquals(self::STATUS_NOT_FOUND, $lastResp->getStatusCode());
|
2019-01-30 11:28:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
public function provideMaxVisits(): array
|
|
|
|
{
|
2019-12-29 16:16:55 -06:00
|
|
|
return map(range(10, 15), fn (int $i) => [$i]);
|
2019-01-30 11:28:07 -06:00
|
|
|
}
|
|
|
|
|
2019-02-17 13:28:34 -06:00
|
|
|
/** @test */
|
2019-02-03 04:01:38 -06:00
|
|
|
public function createsShortUrlWithValidSince(): void
|
2019-01-30 11:28:07 -06:00
|
|
|
{
|
|
|
|
[$statusCode, ['shortCode' => $shortCode]] = $this->createShortUrl([
|
|
|
|
'validSince' => Chronos::now()->addDay()->toAtomString(),
|
|
|
|
]);
|
|
|
|
|
2020-10-03 17:35:14 -05:00
|
|
|
self::assertEquals(self::STATUS_OK, $statusCode);
|
2019-01-30 11:28:07 -06:00
|
|
|
|
2019-10-11 02:14:25 -05:00
|
|
|
// Request to the short URL will return a 404 since it's not valid yet
|
2019-01-30 11:28:07 -06:00
|
|
|
$lastResp = $this->callShortUrl($shortCode);
|
2020-10-03 17:35:14 -05:00
|
|
|
self::assertEquals(self::STATUS_NOT_FOUND, $lastResp->getStatusCode());
|
2019-01-30 11:28:07 -06:00
|
|
|
}
|
|
|
|
|
2019-02-17 13:28:34 -06:00
|
|
|
/** @test */
|
2019-02-03 04:01:38 -06:00
|
|
|
public function createsShortUrlWithValidUntil(): void
|
2019-01-30 11:28:07 -06:00
|
|
|
{
|
|
|
|
[$statusCode, ['shortCode' => $shortCode]] = $this->createShortUrl([
|
|
|
|
'validUntil' => Chronos::now()->subDay()->toAtomString(),
|
|
|
|
]);
|
|
|
|
|
2020-10-03 17:35:14 -05:00
|
|
|
self::assertEquals(self::STATUS_OK, $statusCode);
|
2019-01-30 11:28:07 -06:00
|
|
|
|
|
|
|
// Request to the short URL will return a 404 since it's no longer valid
|
|
|
|
$lastResp = $this->callShortUrl($shortCode);
|
2020-10-03 17:35:14 -05:00
|
|
|
self::assertEquals(self::STATUS_NOT_FOUND, $lastResp->getStatusCode());
|
2019-01-30 11:28:07 -06:00
|
|
|
}
|
|
|
|
|
2019-02-03 04:01:38 -06:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @dataProvider provideMatchingBodies
|
|
|
|
*/
|
|
|
|
public function returnsAnExistingShortUrlWhenRequested(array $body): void
|
|
|
|
{
|
|
|
|
[$firstStatusCode, ['shortCode' => $firstShortCode]] = $this->createShortUrl($body);
|
|
|
|
|
|
|
|
$body['findIfExists'] = true;
|
|
|
|
[$secondStatusCode, ['shortCode' => $secondShortCode]] = $this->createShortUrl($body);
|
|
|
|
|
2020-10-03 17:35:14 -05:00
|
|
|
self::assertEquals(self::STATUS_OK, $firstStatusCode);
|
|
|
|
self::assertEquals(self::STATUS_OK, $secondStatusCode);
|
|
|
|
self::assertEquals($firstShortCode, $secondShortCode);
|
2019-02-03 04:01:38 -06:00
|
|
|
}
|
|
|
|
|
2019-02-17 13:28:34 -06:00
|
|
|
public function provideMatchingBodies(): iterable
|
2019-02-03 04:01:38 -06:00
|
|
|
{
|
|
|
|
$longUrl = 'https://www.alejandrocelaya.com';
|
|
|
|
|
2019-02-17 13:28:34 -06:00
|
|
|
yield 'only long URL' => [['longUrl' => $longUrl]];
|
|
|
|
yield 'long URL and tags' => [['longUrl' => $longUrl, 'tags' => ['boo', 'far']]];
|
|
|
|
yield 'long URL and custom slug' => [['longUrl' => $longUrl, 'customSlug' => 'my cool slug']];
|
|
|
|
yield 'several params' => [[
|
|
|
|
'longUrl' => $longUrl,
|
|
|
|
'tags' => ['boo', 'far'],
|
|
|
|
'validSince' => Chronos::now()->toAtomString(),
|
|
|
|
'maxVisits' => 7,
|
|
|
|
]];
|
2019-02-03 04:01:38 -06:00
|
|
|
}
|
|
|
|
|
2019-10-02 13:13:25 -05:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @dataProvider provideConflictingSlugs
|
|
|
|
*/
|
|
|
|
public function returnsErrorWhenRequestingReturnExistingButCustomSlugIsInUse(string $slug, ?string $domain): void
|
2019-02-03 04:01:38 -06:00
|
|
|
{
|
|
|
|
$longUrl = 'https://www.alejandrocelaya.com';
|
|
|
|
|
|
|
|
[$firstStatusCode] = $this->createShortUrl(['longUrl' => $longUrl]);
|
|
|
|
[$secondStatusCode] = $this->createShortUrl([
|
|
|
|
'longUrl' => $longUrl,
|
2019-10-02 13:13:25 -05:00
|
|
|
'customSlug' => $slug,
|
2019-02-03 04:01:38 -06:00
|
|
|
'findIfExists' => true,
|
2019-10-02 13:13:25 -05:00
|
|
|
'domain' => $domain,
|
2019-02-03 04:01:38 -06:00
|
|
|
]);
|
|
|
|
|
2020-10-03 17:35:14 -05:00
|
|
|
self::assertEquals(self::STATUS_OK, $firstStatusCode);
|
|
|
|
self::assertEquals(self::STATUS_BAD_REQUEST, $secondStatusCode);
|
2019-02-03 04:01:38 -06:00
|
|
|
}
|
|
|
|
|
2019-10-02 13:13:25 -05:00
|
|
|
public function provideConflictingSlugs(): iterable
|
|
|
|
{
|
|
|
|
yield 'without domain' => ['custom', null];
|
|
|
|
yield 'with domain' => ['custom-with-domain', 'some-domain.com'];
|
|
|
|
}
|
|
|
|
|
2019-02-17 13:28:34 -06:00
|
|
|
/** @test */
|
2019-02-03 04:01:38 -06:00
|
|
|
public function createsNewShortUrlIfRequestedToFindButThereIsNoMatch(): void
|
|
|
|
{
|
|
|
|
[$firstStatusCode, ['shortCode' => $firstShortCode]] = $this->createShortUrl([
|
|
|
|
'longUrl' => 'https://www.alejandrocelaya.com',
|
|
|
|
]);
|
|
|
|
[$secondStatusCode, ['shortCode' => $secondShortCode]] = $this->createShortUrl([
|
|
|
|
'longUrl' => 'https://www.alejandrocelaya.com/projects',
|
|
|
|
'findIfExists' => true,
|
|
|
|
]);
|
|
|
|
|
2020-10-03 17:35:14 -05:00
|
|
|
self::assertEquals(self::STATUS_OK, $firstStatusCode);
|
|
|
|
self::assertEquals(self::STATUS_OK, $secondStatusCode);
|
|
|
|
self::assertNotEquals($firstShortCode, $secondShortCode);
|
2019-02-03 04:01:38 -06:00
|
|
|
}
|
|
|
|
|
2019-11-16 05:38:45 -06:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @dataProvider provideIdn
|
|
|
|
*/
|
|
|
|
public function createsNewShortUrlWithInternationalizedDomainName(string $longUrl): void
|
2019-11-16 03:06:55 -06:00
|
|
|
{
|
2019-11-16 06:37:53 -06:00
|
|
|
[$statusCode, $payload] = $this->createShortUrl(['longUrl' => $longUrl]);
|
2019-11-16 03:06:55 -06:00
|
|
|
|
2020-10-03 17:35:14 -05:00
|
|
|
self::assertEquals(self::STATUS_OK, $statusCode);
|
|
|
|
self::assertEquals($payload['longUrl'], $longUrl);
|
2019-11-16 03:06:55 -06:00
|
|
|
}
|
|
|
|
|
2019-11-16 05:38:45 -06:00
|
|
|
public function provideIdn(): iterable
|
|
|
|
{
|
2019-11-16 06:37:53 -06:00
|
|
|
yield ['http://tést.shlink.io']; // Redirects to https://shlink.io
|
|
|
|
yield ['http://test.shlink.io']; // Redirects to http://tést.shlink.io
|
|
|
|
yield ['http://téstb.shlink.io']; // Redirects to http://tést.shlink.io
|
2019-11-16 05:38:45 -06:00
|
|
|
}
|
|
|
|
|
2021-01-30 07:18:44 -06:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @dataProvider provideInvalidUrls
|
|
|
|
*/
|
2022-08-13 10:48:55 -05:00
|
|
|
public function failsToCreateShortUrlWithInvalidLongUrl(string $url, string $version, string $expectedType): void
|
2019-11-26 14:33:22 -06:00
|
|
|
{
|
2019-11-27 13:48:35 -06:00
|
|
|
$expectedDetail = sprintf('Provided URL %s is invalid. Try with a different one.', $url);
|
|
|
|
|
2022-08-13 10:48:55 -05:00
|
|
|
[$statusCode, $payload] = $this->createShortUrl(['longUrl' => $url, 'validateUrl' => true], version: $version);
|
2019-11-26 14:33:22 -06:00
|
|
|
|
2020-10-03 17:35:14 -05:00
|
|
|
self::assertEquals(self::STATUS_BAD_REQUEST, $statusCode);
|
|
|
|
self::assertEquals(self::STATUS_BAD_REQUEST, $payload['status']);
|
2022-08-13 10:48:55 -05:00
|
|
|
self::assertEquals($expectedType, $payload['type']);
|
2020-10-03 17:35:14 -05:00
|
|
|
self::assertEquals($expectedDetail, $payload['detail']);
|
|
|
|
self::assertEquals('Invalid URL', $payload['title']);
|
|
|
|
self::assertEquals($url, $payload['url']);
|
2019-11-26 14:33:22 -06:00
|
|
|
}
|
|
|
|
|
2021-01-30 07:18:44 -06:00
|
|
|
public function provideInvalidUrls(): iterable
|
|
|
|
{
|
2022-08-13 10:48:55 -05:00
|
|
|
yield 'empty URL' => ['', '2', 'INVALID_URL'];
|
|
|
|
yield 'non-reachable URL' => ['https://this-has-to-be-invalid.com', '2', 'INVALID_URL'];
|
|
|
|
yield 'API version 3' => ['', '3', 'https://shlink.io/api/error/invalid-url'];
|
2021-01-30 07:18:44 -06:00
|
|
|
}
|
|
|
|
|
2022-08-13 10:48:55 -05:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @dataProvider provideInvalidArgumentApiVersions
|
|
|
|
*/
|
|
|
|
public function failsToCreateShortUrlWithoutLongUrl(string $version, string $expectedType): void
|
2021-01-30 07:18:44 -06:00
|
|
|
{
|
2022-08-13 10:48:55 -05:00
|
|
|
$resp = $this->callApiWithKey(
|
|
|
|
self::METHOD_POST,
|
|
|
|
sprintf('/rest/v%s/short-urls', $version),
|
|
|
|
[RequestOptions::JSON => []],
|
|
|
|
);
|
2021-01-30 07:18:44 -06:00
|
|
|
$payload = $this->getJsonResponsePayload($resp);
|
|
|
|
|
|
|
|
self::assertEquals(self::STATUS_BAD_REQUEST, $resp->getStatusCode());
|
|
|
|
self::assertEquals(self::STATUS_BAD_REQUEST, $payload['status']);
|
2022-08-13 10:48:55 -05:00
|
|
|
self::assertEquals($expectedType, $payload['type']);
|
2021-01-30 07:18:44 -06:00
|
|
|
self::assertEquals('Provided data is not valid', $payload['detail']);
|
|
|
|
self::assertEquals('Invalid data', $payload['title']);
|
|
|
|
}
|
|
|
|
|
2022-08-13 10:48:55 -05:00
|
|
|
public function provideInvalidArgumentApiVersions(): iterable
|
|
|
|
{
|
|
|
|
yield ['2', 'INVALID_ARGUMENT'];
|
|
|
|
yield ['3', 'https://shlink.io/api/error/invalid-data'];
|
|
|
|
}
|
|
|
|
|
2020-02-08 05:30:47 -06:00
|
|
|
/** @test */
|
|
|
|
public function defaultDomainIsDroppedIfProvided(): void
|
|
|
|
{
|
|
|
|
[$createStatusCode, ['shortCode' => $shortCode]] = $this->createShortUrl([
|
|
|
|
'longUrl' => 'https://www.alejandrocelaya.com',
|
|
|
|
'domain' => 'doma.in',
|
|
|
|
]);
|
|
|
|
$getResp = $this->callApiWithKey(self::METHOD_GET, '/short-urls/' . $shortCode);
|
|
|
|
$payload = $this->getJsonResponsePayload($getResp);
|
|
|
|
|
2020-10-03 17:35:14 -05:00
|
|
|
self::assertEquals(self::STATUS_OK, $createStatusCode);
|
|
|
|
self::assertEquals(self::STATUS_OK, $getResp->getStatusCode());
|
|
|
|
self::assertArrayHasKey('domain', $payload);
|
|
|
|
self::assertNull($payload['domain']);
|
2020-02-08 05:30:47 -06:00
|
|
|
}
|
|
|
|
|
2021-01-10 02:09:56 -06:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @dataProvider provideDomains
|
|
|
|
*/
|
|
|
|
public function apiKeyDomainIsEnforced(?string $providedDomain): void
|
|
|
|
{
|
|
|
|
[$statusCode, ['domain' => $returnedDomain]] = $this->createShortUrl(
|
|
|
|
['domain' => $providedDomain],
|
|
|
|
'domain_api_key',
|
|
|
|
);
|
|
|
|
|
|
|
|
self::assertEquals(self::STATUS_OK, $statusCode);
|
|
|
|
self::assertEquals('example.com', $returnedDomain);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideDomains(): iterable
|
|
|
|
{
|
|
|
|
yield 'no domain' => [null];
|
|
|
|
yield 'invalid domain' => ['this-will-be-overwritten.com'];
|
|
|
|
yield 'example domain' => ['example.com'];
|
|
|
|
}
|
|
|
|
|
2021-02-18 14:33:30 -06:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @dataProvider provideTwitterUrls
|
|
|
|
*/
|
|
|
|
public function urlsWithBothProtectionCanBeShortenedWithUrlValidationEnabled(string $longUrl): void
|
|
|
|
{
|
|
|
|
[$statusCode] = $this->createShortUrl(['longUrl' => $longUrl, 'validateUrl' => true]);
|
|
|
|
self::assertEquals(self::STATUS_OK, $statusCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideTwitterUrls(): iterable
|
|
|
|
{
|
|
|
|
yield ['https://twitter.com/shlinkio'];
|
|
|
|
yield ['https://mobile.twitter.com/shlinkio'];
|
|
|
|
yield ['https://twitter.com/shlinkio/status/1360637738421268481'];
|
|
|
|
yield ['https://mobile.twitter.com/shlinkio/status/1360637738421268481'];
|
|
|
|
}
|
|
|
|
|
2022-01-10 06:04:16 -06:00
|
|
|
/** @test */
|
|
|
|
public function canCreateShortUrlsWithEmojis(): void
|
|
|
|
{
|
|
|
|
[$statusCode, $payload] = $this->createShortUrl([
|
|
|
|
'longUrl' => 'https://emojipedia.org/fire/',
|
|
|
|
'title' => '🔥🔥🔥',
|
|
|
|
'customSlug' => '🦣🦣🦣',
|
|
|
|
]);
|
|
|
|
self::assertEquals(self::STATUS_OK, $statusCode);
|
|
|
|
self::assertEquals('🔥🔥🔥', $payload['title']);
|
|
|
|
self::assertEquals('🦣🦣🦣', $payload['shortCode']);
|
|
|
|
self::assertEquals('http://doma.in/🦣🦣🦣', $payload['shortUrl']);
|
|
|
|
}
|
|
|
|
|
2019-01-30 11:28:07 -06:00
|
|
|
/**
|
2022-10-24 13:25:06 -05:00
|
|
|
* @return array{int, array}
|
2019-01-30 11:28:07 -06:00
|
|
|
*/
|
2022-08-13 10:48:55 -05:00
|
|
|
private function createShortUrl(array $body = [], string $apiKey = 'valid_api_key', string $version = '2'): array
|
2019-01-30 11:28:07 -06:00
|
|
|
{
|
2019-02-03 04:01:38 -06:00
|
|
|
if (! isset($body['longUrl'])) {
|
|
|
|
$body['longUrl'] = 'https://app.shlink.io';
|
|
|
|
}
|
2022-08-13 10:48:55 -05:00
|
|
|
$resp = $this->callApiWithKey(
|
|
|
|
self::METHOD_POST,
|
|
|
|
sprintf('/rest/v%s/short-urls', $version),
|
|
|
|
[RequestOptions::JSON => $body],
|
|
|
|
$apiKey,
|
|
|
|
);
|
2019-01-30 11:28:07 -06:00
|
|
|
$payload = $this->getJsonResponsePayload($resp);
|
|
|
|
|
|
|
|
return [$resp->getStatusCode(), $payload];
|
|
|
|
}
|
|
|
|
}
|