diff --git a/tests/Services/RobotsGeneratorTest.php b/tests/Services/RobotsGeneratorTest.php index 265dfef..9c6e178 100644 --- a/tests/Services/RobotsGeneratorTest.php +++ b/tests/Services/RobotsGeneratorTest.php @@ -6,16 +6,33 @@ beforeEach(function () { $this->generator = new RobotsGenerator(); + + $this->tempDir = sys_get_temp_dir() . '/sitemaps'; + mkdir($this->tempDir, 0777, true); + + file_put_contents($this->tempDir . '/sitemap.xml', ''); + file_put_contents($this->tempDir . '/sitemap.xml.gz', ''); + + Config::$boarddir = $this->tempDir; }); -it('generator method', function () { +afterEach(function () { + if (is_dir($this->tempDir)) { + array_map('unlink', glob($this->tempDir . '/*')); + rmdir($this->tempDir); + } +}); + +it('generates correct links', function () { $this->generator->generate(); + Config::$modSettings['xmlnews_enable'] = true; + expect(Utils::$context['new_robots_content']) ->toContain('User-agent: *'); }); -it('generator method with SEF enabled', function () { +it('generates correct links with SEF enabled', function () { $this->generator->useSef = true; $this->generator->generate(); @@ -25,7 +42,7 @@ $this->generator->useSef = false; }); -it('generator method with queryless_urls enabled', function () { +it('generates correct links with queryless_urls enabled', function () { Config::$modSettings['queryless_urls'] = true; $this->generator->generate(); @@ -35,3 +52,11 @@ Config::$modSettings['queryless_urls'] = false; }); + +it('can process custom rules', function () { + $this->generator->customRules['GoogleBot']['disallow'][] = '/'; + $this->generator->generate(); + + expect(Utils::$context['new_robots_content']) + ->toContain('User-agent: GoogleBot'); +}); diff --git a/tests/Services/SitemapGeneratorTest.php b/tests/Services/SitemapGeneratorTest.php index 537584f..c2fd723 100644 --- a/tests/Services/SitemapGeneratorTest.php +++ b/tests/Services/SitemapGeneratorTest.php @@ -212,3 +212,20 @@ function(AddonEvent $event) use ($testAddon) { ->toContain('https://example.com/custom') ->and(file_exists($this->tempDir . '/sitemap.xml'))->toBeTrue(); }); + +it('gets last date from links array', function () { + $maxDate = time(); + $links = [ + ['loc' => 'https://example.com/page1', 'lastmod' => strtotime('-3 days', $maxDate)], + ['loc' => 'https://example.com/page2', 'lastmod' => $maxDate] + ]; + + $method = new ReflectionMethod($this->generator, 'getLastDate'); + $result = $method->invoke($this->generator, $links); + + expect($result)->toBe($maxDate); + + $result = $method->invoke($this->generator, []); + + expect($result)->toBe($maxDate); +});