diff --git a/app/tests/TestCase/ApplicationTest.php b/app/tests/TestCase/ApplicationTest.php index 2bb013320..4c2fbde99 100644 --- a/app/tests/TestCase/ApplicationTest.php +++ b/app/tests/TestCase/ApplicationTest.php @@ -1,4 +1,5 @@ bootstrap(); $plugins = $app->getPlugins(); @@ -50,14 +43,10 @@ public function testBootstrap() $this->assertTrue($plugins->has('Migrations'), 'plugins has Migrations?'); } - /** - * Test bootstrap add DebugKit plugin in debug mode. - * - * @return void - */ - public function testBootstrapInDebug() + public function testBootstrapInDebug(): void { Configure::write('debug', true); + $app = new Application(dirname(__DIR__, 2) . '/config'); $app->bootstrap(); $plugins = $app->getPlugins(); @@ -65,16 +54,11 @@ public function testBootstrapInDebug() $this->assertTrue($plugins->has('DebugKit'), 'plugins has DebugKit?'); } - /** - * testMiddleware - * - * @return void - */ - public function testMiddleware() + public function testMiddleware(): void { $app = new Application(dirname(__DIR__, 2) . '/config'); - $middleware = new MiddlewareQueue(); + $middleware = new MiddlewareQueue(); $middleware = $app->middleware($middleware); $this->assertInstanceOf(ErrorHandlerMiddleware::class, $middleware->current()); diff --git a/app/tests/TestCase/Controller/MostlyStaticPagesControllerTest.php b/app/tests/TestCase/Controller/MostlyStaticPagesControllerTest.php index 889f91423..97169a123 100644 --- a/app/tests/TestCase/Controller/MostlyStaticPagesControllerTest.php +++ b/app/tests/TestCase/Controller/MostlyStaticPagesControllerTest.php @@ -10,12 +10,24 @@ use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; #[CoversClass('MostlyStaticPagesController')] final class MostlyStaticPagesControllerTest extends TestCase { use IntegrationTestTrait; + public static function defaultPagesProvider(): array + { + return [ + ['duplicate-landing', PageContextEnum::EnrollmentHandoff], + ['default-handoff', PageContextEnum::EnrollmentHandoff], + ['error-landing', PageContextEnum::ErrorLanding], + ['mfa-required', PageContextEnum::ErrorLanding], + ['petition-complete', PageContextEnum::EnrollmentHandoff], + ]; + } + public static function defaultPageSlugsProvider(): array { return [ @@ -35,33 +47,26 @@ private function getComanageCoId(): int return (int)$co->id; } - public function testDefaultPagesRenderOverHttp(string $slug): void + private function assertDefaultPageRendersOverHttp(string $slug): void { $coId = $this->getComanageCoId(); - // Optional: fetch expected title from DB so the assertion is stable $MostlyStaticPages = TableRegistry::getTableLocator()->get('MostlyStaticPages'); $page = $MostlyStaticPages->find() ->where(['co_id' => $coId, 'name' => $slug]) ->firstOrFail(); - // Use the *actual URL* your app routes to the “show static page” endpoint. - // Common patterns are one of these — pick the correct one for your routes: - // $this->get("/{$coId}/pages/show/{$slug}"); - // $this->get("/{$coId}/{$slug}"); - - $this->get("/{$coId}/pages/show/{$slug}"); + // Correct route is /{coid}/{name} + $this->get("/{$coId}/{$slug}"); $this->assertResponseOk(); $this->assertResponseContains((string)$page->title); } - /** - * @dataProvider defaultPageSlugsProvider - */ - public function testDefaultPagesRenderOverHttp_withProvider(string $slug): void + #[DataProvider('defaultPageSlugsProvider')] + public function testDefaultPagesRenderOverHttp(string $slug): void { - $this->testDefaultPagesRenderOverHttp($slug); + $this->assertDefaultPageRendersOverHttp($slug); } private function assertDefaultPageExists(string $name, string $expectedContext): void @@ -85,28 +90,9 @@ private function assertDefaultPageExists(string $name, string $expectedContext): ); } - public function testDuplicateLandingExists(): void - { - $this->assertDefaultPageExists('duplicate-landing', PageContextEnum::EnrollmentHandoff); - } - - public function testDefaultHandoffExists(): void - { - $this->assertDefaultPageExists('default-handoff', PageContextEnum::EnrollmentHandoff); - } - - public function testErrorLandingExists(): void - { - $this->assertDefaultPageExists('error-landing', PageContextEnum::ErrorLanding); - } - - public function testMfaRequiredExists(): void - { - $this->assertDefaultPageExists('mfa-required', PageContextEnum::ErrorLanding); - } - - public function testPetitionCompleteExists(): void + #[DataProvider('defaultPagesProvider')] + public function testDefaultPagesExist(string $name, string $expectedContext): void { - $this->assertDefaultPageExists('petition-complete', PageContextEnum::EnrollmentHandoff); + $this->assertDefaultPageExists($name, $expectedContext); } }