diff --git a/src/Commands/ExportSites.php b/src/Commands/ExportSites.php index 203377db..51ef08a9 100644 --- a/src/Commands/ExportSites.php +++ b/src/Commands/ExportSites.php @@ -35,13 +35,13 @@ public function handle() $sites = SiteModel::all() ->mapWithKeys(function ($model) { return [ - $model->handle => [ + $model->handle => collect([ 'name' => $model->name, - 'lang' => $model->lang, + 'lang' => $model->lang ?? null, 'locale' => $model->locale, 'url' => $model->url, 'attributes' => $model->attributes ?? [], - ], + ])->filter()->all(), ]; }); diff --git a/tests/Commands/ExportSitesTest.php b/tests/Commands/ExportSitesTest.php new file mode 100644 index 00000000..57c73332 --- /dev/null +++ b/tests/Commands/ExportSitesTest.php @@ -0,0 +1,52 @@ + 'en', 'name' => 'English', 'locale' => 'en_US', 'lang' => '', 'url' => 'http://test.com/', 'attributes' => []]); + SiteModel::create(['handle' => 'fr', 'name' => 'French', 'locale' => 'fr_FR', 'lang' => '', 'url' => 'http://fr.test.com/', 'attributes' => []]); + SiteModel::create(['handle' => 'es', 'name' => 'Spanish', 'locale' => 'es_ES', 'lang' => '', 'url' => 'http://test.com/es/', 'attributes' => ['foo' => 'bar']]); + SiteModel::create(['handle' => 'de', 'name' => 'German', 'locale' => 'de_DE', 'lang' => 'de', 'url' => 'http://test.com/de/', 'attributes' => []]); + + $this->artisan('statamic:eloquent:export-sites') + ->expectsOutputToContain('Sites exported') + ->assertExitCode(0); + + $this->assertEquals([ + 'en' => [ + 'name' => 'English', + 'locale' => 'en_US', + 'url' => 'http://test.com/', + ], + 'fr' => [ + 'name' => 'French', + 'locale' => 'fr_FR', + 'url' => 'http://fr.test.com/', + ], + 'es' => [ + 'name' => 'Spanish', + 'locale' => 'es_ES', + 'url' => 'http://test.com/es/', + 'attributes' => ['foo' => 'bar'], + ], + 'de' => [ + 'name' => 'German', + 'lang' => 'de', + 'locale' => 'de_DE', + 'url' => 'http://test.com/de/', + ], + ], (new Sites)->config()); + } +}