1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-08 06:06:45 +02:00

feat(shortcodes): upd logic for uuid shortcode and upd tests

This commit is contained in:
Awilum
2022-05-25 18:13:56 +03:00
parent f317b20ac6
commit 39ff8ef7bc
3 changed files with 15 additions and 44 deletions

View File

@@ -22,39 +22,22 @@ use function app;
use function parsers;
use function registry;
// Shortcode: [uuid1]
parsers()->shortcodes()->addHandler('uuid1', static function () {
// Shortcode: uuid
// Usage: (uuid) (uuid:4)
parsers()->shortcodes()->addHandler('uuid', static function () {
if (! registry()->get('flextype.settings.parsers.shortcodes.shortcodes.uuid.enabled')) {
return '';
}
return Uuid::uuid1()->toString();
});
// Shortcode: [uuid2]
parsers()->shortcodes()->addHandler('uuid2', static function () {
if (! registry()->get('flextype.settings.parsers.shortcodes.shortcodes.uuid.enabled')) {
return '';
$result = '';
$uuid = ($s->getBbCode() != null) ? strings(parsers()->shortcodes()->parse($s->getBbCode()))->toInteger() : 4;
switch ($uuid) {
case 4:
default:
$result = Uuid::uuid4()->toString();
break;
}
return Uuid::uuid2()->toString();
});
// Shortcode: [uuid3]
parsers()->shortcodes()->addHandler('uuid3', static function () {
if (! registry()->get('flextype.settings.parsers.shortcodes.shortcodes.uuid.enabled')) {
return '';
}
return Uuid::uuid3()->toString();
});
// Shortcode: [uuid4]
parsers()->shortcodes()->addHandler('uuid4', static function () {
if (! registry()->get('flextype.settings.parsers.shortcodes.shortcodes.uuid.enabled')) {
return '';
}
return Uuid::uuid4()->toString();
return $result;
});

View File

@@ -1,10 +0,0 @@
<?php
declare(strict_types=1);
test('(uuid1-4) shortcode', function () {
expect(strings(parsers()->shortcodes()->parse('(uuid1)'))->length() > 0)->toBeTrue();
expect(strings(parsers()->shortcodes()->parse('(uuid2)'))->length() > 0)->toBeTrue();
expect(strings(parsers()->shortcodes()->parse('(uuid3)'))->length() > 0)->toBeTrue();
expect(strings(parsers()->shortcodes()->parse('(uuid4)'))->length() > 0)->toBeTrue();
});

View File

@@ -2,9 +2,7 @@
declare(strict_types=1);
test('uuid shortcode', function () {
expect(strings(parsers()->shortcodes()->parse('(uuid1)'))->length() > 0)->toBeTrue();
expect(strings(parsers()->shortcodes()->parse('(uuid2)'))->length() > 0)->toBeTrue();
expect(strings(parsers()->shortcodes()->parse('(uuid3)'))->length() > 0)->toBeTrue();
expect(strings(parsers()->shortcodes()->parse('(uuid4)'))->length() > 0)->toBeTrue();
test('uuid shortcode', function () {
expect(strings(parsers()->shortcodes()->parse('(uuid)'))->length() > 0)->toBeTrue();
expect(strings(parsers()->shortcodes()->parse('(uuid:4)'))->length() > 0)->toBeTrue();
});