@@ -90,6 +90,67 @@ public function testParseEntries(): void
9090 assertCount (7 , $ entries );
9191 }
9292
93+ public function testParseLocalizedCollectionEntriesFromLanguageDirectories (): void
94+ {
95+ $ dir = sys_get_temp_dir () . '/yiipress-localized-collection- ' . uniqid ();
96+ mkdir ($ dir . '/blog/ru ' , 0o755 , true );
97+ file_put_contents ($ dir . '/blog/_collection.yaml ' , "title: Blog \n" );
98+ file_put_contents ($ dir . '/blog/post.md ' , "--- \ntitle: Hello \n--- \n" );
99+ file_put_contents ($ dir . '/blog/ru/post.md ' , "--- \ntitle: Привет \n--- \n" );
100+ file_put_contents (
101+ $ dir . '/blog/ru/override.md ' ,
102+ "--- \ntitle: Override \nlanguage: uk \n--- \n" ,
103+ );
104+
105+ try {
106+ $ entries = iterator_to_array ($ this ->parser ->parseEntries ($ dir , 'blog ' ), false );
107+ $ byTitle = [];
108+ foreach ($ entries as $ entry ) {
109+ $ byTitle [$ entry ->title ] = $ entry ;
110+ }
111+
112+ assertCount (3 , $ entries );
113+ assertSame ('' , $ byTitle ['Hello ' ]->language );
114+ assertSame ('ru ' , $ byTitle ['Привет ' ]->language );
115+ assertSame ('uk ' , $ byTitle ['Override ' ]->language );
116+ assertSame ('post ' , $ byTitle ['Привет ' ]->slug );
117+ } finally {
118+ unlink ($ dir . '/blog/ru/override.md ' );
119+ unlink ($ dir . '/blog/ru/post.md ' );
120+ unlink ($ dir . '/blog/post.md ' );
121+ unlink ($ dir . '/blog/_collection.yaml ' );
122+ rmdir ($ dir . '/blog/ru ' );
123+ rmdir ($ dir . '/blog ' );
124+ rmdir ($ dir );
125+ }
126+ }
127+
128+ public function testParseLocalizedStandalonePagesFromLanguageDirectories (): void
129+ {
130+ $ dir = sys_get_temp_dir () . '/yiipress-localized-pages- ' . uniqid ();
131+ mkdir ($ dir . '/cs ' , 0o755 , true );
132+ file_put_contents ($ dir . '/about.md ' , "--- \ntitle: About \n--- \n" );
133+ file_put_contents ($ dir . '/cs/about.md ' , "--- \ntitle: O nás \n--- \n" );
134+
135+ try {
136+ $ entries = iterator_to_array ($ this ->parser ->parseStandalonePages ($ dir ), false );
137+ $ byTitle = [];
138+ foreach ($ entries as $ entry ) {
139+ $ byTitle [$ entry ->title ] = $ entry ;
140+ }
141+
142+ assertCount (2 , $ entries );
143+ assertSame ('cs ' , $ byTitle ['O nás ' ]->language );
144+ assertSame ('' , $ byTitle ['About ' ]->language );
145+ assertSame ('about ' , $ byTitle ['O nás ' ]->slug );
146+ } finally {
147+ unlink ($ dir . '/cs/about.md ' );
148+ unlink ($ dir . '/about.md ' );
149+ rmdir ($ dir . '/cs ' );
150+ rmdir ($ dir );
151+ }
152+ }
153+
93154 public function testParseAuthors (): void
94155 {
95156 $ authors = iterator_to_array ($ this ->parser ->parseAuthors ($ this ->dataDir ));
0 commit comments