Skip to content

Commit fe7efa9

Browse files
committed
test: cover dead link detection
1 parent 373afa4 commit fe7efa9

File tree

2 files changed

+44
-8
lines changed

2 files changed

+44
-8
lines changed

tests/Integration/Http/Static/Fixtures/StaticPageController.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Tempest\View\View;
1313
use Tempest\Vite\Exceptions\ManifestNotFoundException;
1414

15+
use function Tempest\uri;
1516
use function Tempest\view;
1617

1718
final readonly class StaticPageController
@@ -47,4 +48,14 @@ public function vite(
4748
): void {
4849
throw new ViewCompilationError('view.php', '', new ManifestNotFoundException('fake-manifest.json'));
4950
}
51+
52+
#[Get('/static/dead-link')]
53+
#[StaticPage]
54+
public function deadLink(): string
55+
{
56+
return implode(PHP_EOL, [
57+
sprintf('<a href="%s">foo</a>', uri('/404')),
58+
'<a href="https://google.com/404">foo</a>',
59+
]);
60+
}
5061
}

tests/Integration/Http/Static/StaticGenerateCommandTest.php

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ protected function setUp(): void
2727

2828
public function test_static_site_generate_command(): void
2929
{
30-
$appConfig = new AppConfig(baseUri: 'https://test.com');
31-
$this->container->config($appConfig);
30+
$this->container->config(new AppConfig(baseUri: 'https://test.com'));
3231

3332
$this->console
3433
->call(StaticGenerateCommand::class)
@@ -56,8 +55,7 @@ public function test_failure_status_code(): void
5655
$this->registerRoute([StaticPageController::class, 'http500']);
5756
$this->registerStaticPage([StaticPageController::class, 'http500']);
5857

59-
$appConfig = new AppConfig(baseUri: 'https://test.com');
60-
$this->container->config($appConfig);
58+
$this->container->config(new AppConfig(baseUri: 'https://test.com'));
6159

6260
$this->console
6361
->call(StaticGenerateCommand::class)
@@ -70,8 +68,7 @@ public function test_failure_no_textual_content(): void
7068
$this->registerRoute([StaticPageController::class, 'noTextualContent']);
7169
$this->registerStaticPage([StaticPageController::class, 'noTextualContent']);
7270

73-
$appConfig = new AppConfig(baseUri: 'https://test.com');
74-
$this->container->config($appConfig);
71+
$this->container->config(new AppConfig(baseUri: 'https://test.com'));
7572

7673
$this->console
7774
->call(StaticGenerateCommand::class)
@@ -84,12 +81,40 @@ public function test_failure_no_build(): void
8481
$this->registerRoute([StaticPageController::class, 'vite']);
8582
$this->registerStaticPage([StaticPageController::class, 'vite']);
8683

87-
$appConfig = new AppConfig(baseUri: 'https://test.com');
88-
$this->container->config($appConfig);
84+
$this->container->config(new AppConfig(baseUri: 'https://test.com'));
8985

9086
$this->console
9187
->call(StaticGenerateCommand::class)
9288
->assertSee('A Vite build is needed for [/static/vite/a/b]')
9389
->assertExitCode(ExitCode::ERROR);
9490
}
91+
92+
public function test_dead_link(): void
93+
{
94+
$this->registerRoute([StaticPageController::class, 'deadLink']);
95+
$this->registerStaticPage([StaticPageController::class, 'deadLink']);
96+
97+
$this->container->config(new AppConfig(baseUri: 'https://test.com'));
98+
99+
$this->console
100+
->call(StaticGenerateCommand::class)
101+
->assertSee('1 DEAD LINK')
102+
->assertSee('https://test.com/404')
103+
->assertExitCode(ExitCode::ERROR);
104+
}
105+
106+
public function test_external_dead_links(): void
107+
{
108+
$this->registerRoute([StaticPageController::class, 'deadLink']);
109+
$this->registerStaticPage([StaticPageController::class, 'deadLink']);
110+
111+
$this->container->config(new AppConfig(baseUri: 'https://test.com'));
112+
113+
$this->console
114+
->call(StaticGenerateCommand::class, ['--allow-external-dead-links' => false])
115+
->assertSee('2 DEAD LINKS')
116+
->assertSee('https://test.com/404')
117+
->assertSee('https://google.com/404')
118+
->assertExitCode(ExitCode::ERROR);
119+
}
95120
}

0 commit comments

Comments
 (0)