From 51d4198605e81b379968103e1616587ab83dc34c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 22 Dec 2024 12:04:12 +0100 Subject: [PATCH] Use data provider to test more character sets --- .../Feature/InternationalizationTest.php | 85 ++++++++++++++----- 1 file changed, 66 insertions(+), 19 deletions(-) diff --git a/packages/framework/tests/Feature/InternationalizationTest.php b/packages/framework/tests/Feature/InternationalizationTest.php index 75738b2877c..04e6d6fa861 100644 --- a/packages/framework/tests/Feature/InternationalizationTest.php +++ b/packages/framework/tests/Feature/InternationalizationTest.php @@ -16,22 +16,38 @@ */ class InternationalizationTest extends TestCase { - public function testCanCreateBlogPostFilesWithInternationalCharacterSets() - { - $creator = new CreatesNewMarkdownPostFile('你好世界', '简短描述', 'blog', 'default', '2024-12-22 10:45'); + /** + * @dataProvider internationalCharacterSetsProvider + */ + public function testCanCreateBlogPostFilesWithInternationalCharacterSets( + string $title, + string $description, + string $expectedSlug, + string $expectedTitle + ) { + $creator = new CreatesNewMarkdownPostFile($title, $description, 'blog', 'default', '2024-12-22 10:45'); $path = $creator->save(); - $this->assertSame('_posts/ni-hao-shi-jie.md', $path); - $this->assertSame('ni-hao-shi-jie', $creator->getIdentifier()); - $this->assertSame($creator->getIdentifier(), Hyde::makeSlug('你好世界')); + $this->assertSame("_posts/$expectedSlug.md", $path); + $this->assertSame($expectedSlug, $creator->getIdentifier()); + $this->assertSame($creator->getIdentifier(), Hyde::makeSlug($title)); $this->assertFileExists($path); $contents = file_get_contents($path); - $this->assertStringContainsString('title: 你好世界', $contents); - $this->assertSame(<<<'EOF' + + if (str_contains($title, ' ')) { + $expectedTitle = "'$expectedTitle'"; + } + + if (str_contains($description, ' ')) { + $description = "'$description'"; + } + + $this->assertStringContainsString("title: $expectedTitle", $contents); + $this->assertSame(<< '你好世界', - 'description' => '简短描述', + /** + * @dataProvider internationalCharacterSetsProvider + */ + public function testCanCompileBlogPostFilesWithInternationalCharacterSets( + string $title, + string $description, + string $expectedSlug, + string $expectedTitle + ) { + $page = new MarkdownPost($expectedSlug, [ + 'title' => $title, + 'description' => $description, 'category' => 'blog', 'author' => 'default', 'date' => '2024-12-22 10:45', @@ -56,15 +79,39 @@ public function testCanCompileBlogPostFilesWithInternationalCharacterSets() $path = StaticPageBuilder::handle($page); - $this->assertSame(Hyde::path('_site/posts/ni-hao-shi-jie.html'), $path); + $this->assertSame(Hyde::path("_site/posts/$expectedSlug.html"), $path); $this->assertFileExists($path); $contents = file_get_contents($path); - $this->assertStringContainsString('HydePHP - 你好世界', $contents); - $this->assertStringContainsString('

你好世界

', $contents); - $this->assertStringContainsString('', $contents); + $this->assertStringContainsString("HydePHP - $expectedTitle", $contents); + $this->assertStringContainsString("

$expectedTitle

", $contents); + $this->assertStringContainsString("", $contents); Filesystem::unlink($path); } + + public static function internationalCharacterSetsProvider(): array + { + return [ + 'Chinese (Simplified)' => [ + '你好世界', + '简短描述', + 'ni-hao-shi-jie', + '你好世界', + ], + 'Japanese' => [ + 'こんにちは世界', + '短い説明', + 'konnichihashi-jie', + 'こんにちは世界', + ], + 'Korean' => [ + '안녕하세요 세계', + '짧은 설명', + 'annyeonghaseyo-segye', + '안녕하세요 세계', + ], + ]; + } }