[ 'single_pages' => ['contact'], 'supported_locales' => ['fr', 'en'], 'cruds' => [], 'schedule' => false, 'cron' => '45 15 * * *', 'localizer' => 'default', 'output_path' => $this->testXmlPath, ], ]); // WHEN $sitemapConfig = new SitemapConfig($configRepository); // THEN expect($sitemapConfig)->toBeInstanceOf(SitemapConfig::class) ->and($sitemapConfig->singlePages)->toBe(['contact']) ->and($sitemapConfig->supportedLocales)->toBe(['fr', 'en']) ->and($sitemapConfig->cruds)->toBe([]) ->and($sitemapConfig->schedule)->toBeFalse() ->and($sitemapConfig->localizer)->toBe('default') ->and($sitemapConfig->cron)->toBeInstanceOf(CronExpression::class) ->and($sitemapConfig->outputPath)->toBe($this->testXmlPath); }); it('falls back to legacy singlePages config', function () { // GIVEN $configRepository = new ConfigRepository([ SitemapConfig::CONFIG_KEY => [ 'singlePages' => ['legacy-page'], 'supported_locales' => ['fr'], 'cruds' => [], 'schedule' => false, 'cron' => '* * * * *', 'localizer' => 'default', 'output_path' => '/tmp/sitemap.xml', ], ]); // WHEN $sitemapConfig = new SitemapConfig($configRepository); // THEN expect($sitemapConfig->singlePages) ->toBe(['legacy-page']); }); it('throws exception when cron expression is invalid', function () { // GIVEN $configRepository = new ConfigRepository([ SitemapConfig::CONFIG_KEY => [ 'single_pages' => [], 'supported_locales' => ['fr'], 'cruds' => [], 'schedule' => false, 'cron' => 'invalid-cron', 'localizer' => 'default', 'output_path' => '/tmp/sitemap.xml', ], ]); // WHEN $action = fn () => new SitemapConfig($configRepository); // THEN expect($action) ->toThrow(SitemapException::class, "Cron config is not a valid expression 'invalid-cron'"); }); it('throws exception when output path does not end with .xml', function () { // GIVEN $configRepository = new ConfigRepository([ SitemapConfig::CONFIG_KEY => [ 'single_pages' => [], 'supported_locales' => ['fr'], 'cruds' => [], 'schedule' => false, 'cron' => '* * * * *', 'localizer' => 'default', 'output_path' => '/tmp/sitemap.txt', ], ]); // WHEN $action = fn () => new SitemapConfig($configRepository); // THEN expect($action) ->toThrow( SitemapException::class, "Output path should indicate an XML file location '/tmp/sitemap.txt'" ); }); it('can parse cruds configuration properly', function () { // GIVEN $configRepository = new ConfigRepository([ SitemapConfig::CONFIG_KEY => [ 'single_pages' => [], 'supported_locales' => ['fr'], 'cruds' => [ [ 'model' => ModelClass::class, 'relationFilters' => ['posts' => fn () => true], 'modelFilters' => [['is_active', '=', true]], 'allowNullRelations' => ['category'], ], ], 'schedule' => false, 'cron' => '* * * * *', 'localizer' => 'default', 'output_path' => '/tmp/sitemap.xml', ], ]); // WHEN $sitemapConfig = new SitemapConfig($configRepository); // THEN expect($sitemapConfig->cruds)->toHaveCount(1) ->and($sitemapConfig->cruds[0]->modelClass)->toBe(ModelClass::class) ->and($sitemapConfig->cruds[0]->allowNullRelations)->toBe(['category']); }); it('returns the configured localizer instance', function () { // GIVEN $configRepository = new ConfigRepository([ SitemapConfig::CONFIG_KEY => [ 'single_pages' => [], 'supported_locales' => ['fr'], 'cruds' => [], 'schedule' => false, 'cron' => '* * * * *', 'localizer' => 'default', 'output_path' => '/tmp/sitemap.xml', ], ]); // WHEN $sitemapConfig = new SitemapConfig($configRepository); $localizer = $sitemapConfig->getConfiguredLocalizerFor(app()); // THEN expect($localizer)->toBeInstanceOf(DefaultRouteLocalizer::class); }); });