diff --git a/src/Renderer/Twig/Extensions/Uuid.php b/src/Renderer/Twig/Extensions/Uuid.php new file mode 100644 index 00000000..acf8072c --- /dev/null +++ b/src/Renderer/Twig/Extensions/Uuid.php @@ -0,0 +1,31 @@ + Markdown::class, 'translation' => Translation::class, 'url' => Url::class, + 'uuid' => Uuid::class, ]; public function register(): void diff --git a/tests/Unit/Renderer/Twig/Extensions/UuidTest.php b/tests/Unit/Renderer/Twig/Extensions/UuidTest.php new file mode 100644 index 00000000..e032b00e --- /dev/null +++ b/tests/Unit/Renderer/Twig/Extensions/UuidTest.php @@ -0,0 +1,49 @@ +getFunctions(); + + $this->assertExtensionExists('uuid', [$extension, 'getUuid'], $functions); + $this->assertExtensionExists('uuidBy', [$extension, 'getUuidBy'], $functions); + } + + /** + * @covers \Engelsystem\Renderer\Twig\Extensions\Uuid::getUuid + */ + public function testGetUuid(): void + { + $extension = new Uuid(); + + $uuid = $extension->getUuid(); + $this->assertTrue(Str::isUuid($uuid)); + } + + + /** + * @covers \Engelsystem\Renderer\Twig\Extensions\Uuid::getUuidBy + */ + public function testGetUuidBy(): void + { + $extension = new Uuid(); + + $uuid = $extension->getUuidBy('test'); + $this->assertTrue(Str::isUuid($uuid)); + $this->assertEquals('098f6bcd-4621-4373-8ade-4e832627b4f6', $uuid); + + $uuid = $extension->getUuidBy('test', '1337'); + $this->assertTrue(Str::isUuid($uuid)); + $this->assertStringStartsWith('1337', $uuid); + } +}