Working state

This commit is contained in:
julien
2026-03-16 09:46:48 +01:00
parent fd3f608059
commit e24ee5d622
5 changed files with 178 additions and 3 deletions

View File

@@ -9,7 +9,6 @@ use PHPUnit\Framework\TestCase;
use Twig\TwigFunction;
#[\PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations]
final class PostExtensionTest extends TestCase
{
/** @var array<string, TwigFunction> */
@@ -25,6 +24,16 @@ final class PostExtensionTest extends TestCase
}
}
public function testRegistersExpectedTwigFunctions(): void
{
self::assertSame([
'post_excerpt',
'post_url',
'post_thumbnail',
'post_initials',
], array_keys($this->functions));
}
public function testPostUrlUsesStoredSlug(): void
{
$post = new Post(1, 'Mon article', '<p>Contenu</p>', 'mon-article-2');
@@ -45,6 +54,13 @@ final class PostExtensionTest extends TestCase
self::assertStringEndsWith('…', $excerpt);
}
public function testPostExcerptReturnsOriginalHtmlWhenAlreadyShortEnough(): void
{
$post = new Post(10, 'Titre', '<p><strong>Bonjour</strong> <em>monde</em></p>', 'titre-10');
self::assertSame('<strong>Bonjour</strong> <em>monde</em>', $this->call('post_excerpt', $post, 100));
}
public function testPostThumbnailReturnsFirstImageSource(): void
{
$post = new Post(1, 'Titre', '<p><img src="/media/a.webp" alt="a"><img src="/media/b.webp"></p>', 'titre');
@@ -63,11 +79,11 @@ final class PostExtensionTest extends TestCase
{
$post = new Post(1, 'Article de Blog', '<p>Contenu</p>', 'slug');
$single = new Post(2, 'A B', '<p>Contenu</p>', 'slug-2');
$emptyLike = new Post(3, 'A', '<p>Contenu</p>', 'slug-3');
$stopWordsOnly = new Post(3, 'de la', '<p>Contenu</p>', 'slug-3');
self::assertSame('AB', $this->call('post_initials', $post));
self::assertSame('A', $this->call('post_initials', $single));
self::assertSame('A', $this->call('post_initials', $emptyLike));
self::assertSame('D', $this->call('post_initials', $stopWordsOnly));
}
private function call(string $name, mixed ...$args): mixed