Add API test for short URL path prefix

This commit is contained in:
Alejandro Celaya 2024-02-21 19:14:30 +01:00
parent f30c74b987
commit ff963a9df4

View File

@ -8,6 +8,7 @@ use Cake\Chronos\Chronos;
use GuzzleHttp\RequestOptions;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\TestWith;
use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase;
use function array_map;
@ -339,6 +340,21 @@ class CreateShortUrlTest extends ApiTestCase
self::assertNull($payload['title']);
}
#[Test]
#[TestWith([null])]
#[TestWith(['my-custom-slug'])]
public function prefixCanBeSet(?string $customSlug): void
{
[$statusCode, $payload] = $this->createShortUrl([
'longUrl' => 'https://github.com/shlinkio/shlink/issues/1557',
'pathPrefix' => 'foo/b ar-baz',
'customSlug' => $customSlug,
]);
self::assertEquals(self::STATUS_OK, $statusCode);
self::assertStringStartsWith('foo-b--ar-baz', $payload['shortCode']);
}
/**
* @return array{int, array}
*/