@@ -59,6 +59,26 @@ public function it_migrates_global_variables_in_a_single_site_install()
5959 unlink ($ this ->globalsPath .'/en/test.yaml ' );
6060 }
6161
62+ #[Test]
63+ public function it_migrates_global_variables_with_empty_data_in_a_single_site_install ()
64+ {
65+ File::put ($ this ->globalsPath .'/test.yaml ' , "title: Test \ndata: " );
66+
67+ $ this ->runUpdateScript (UpdateGlobalVariables::class);
68+
69+ $ expected = <<<'YAML'
70+ title: Test
71+
72+ YAML;
73+ $ this ->assertEquals ($ expected , File::get ($ this ->globalsPath .'/test.yaml ' ));
74+
75+ // Empty data should produce an empty array, not null
76+ $ this ->assertEquals ([], YAML ::parse (File::get ($ this ->globalsPath .'/en/test.yaml ' )));
77+
78+ unlink ($ this ->globalsPath .'/test.yaml ' );
79+ unlink ($ this ->globalsPath .'/en/test.yaml ' );
80+ }
81+
6282 #[Test]
6383 public function it_builds_the_sites_array_in_a_multi_site_install ()
6484 {
@@ -96,4 +116,25 @@ public function it_builds_the_sites_array_in_a_multi_site_install()
96116 $ this ->assertEquals (['foo ' => 'Bar ' ], YAML ::parse (File::get ($ this ->globalsPath .'/fr/test.yaml ' )));
97117 $ this ->assertEquals ([], YAML ::parse (File::get ($ this ->globalsPath .'/de/test.yaml ' )));
98118 }
119+
120+ #[Test]
121+ public function it_handles_null_content_in_global_variables_in_a_multi_site_install ()
122+ {
123+ $ this ->setSites ([
124+ 'en ' => ['url ' => '/ ' , 'locale ' => 'en_US ' , 'name ' => 'English ' ],
125+ 'fr ' => ['url ' => '/ ' , 'locale ' => 'fr_FR ' , 'name ' => 'French ' ],
126+ ]);
127+
128+ File::ensureDirectoryExists ($ this ->globalsPath .'/en ' );
129+ File::ensureDirectoryExists ($ this ->globalsPath .'/fr ' );
130+
131+ File::put ($ this ->globalsPath .'/test.yaml ' , Yaml::dump (['title ' => 'Test ' ]));
132+ File::put ($ this ->globalsPath .'/en/test.yaml ' , Yaml::dump (['foo ' => 'Bar ' ]));
133+ File::put ($ this ->globalsPath .'/fr/test.yaml ' , 'null ' );
134+
135+ $ this ->runUpdateScript (UpdateGlobalVariables::class);
136+
137+ // File with null content should result in empty array after update
138+ $ this ->assertEquals ([], YAML ::parse (File::get ($ this ->globalsPath .'/fr/test.yaml ' )));
139+ }
99140}
0 commit comments