forked from COmanage/registry
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add mostly static pages tests.improve github actions yaml config
- Loading branch information
Showing
4 changed files
with
124 additions
and
4 deletions.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
app/tests/TestCase/Controller/MostlyStaticPagesControllerTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Test\TestCase\Controller; | ||
|
|
||
| use App\Lib\Enum\PageContextEnum; | ||
| use App\Lib\Enum\SuspendableStatusEnum; | ||
| use Cake\ORM\TableRegistry; | ||
| use Cake\TestSuite\TestCase; | ||
| use PHPUnit\Framework\Attributes\CoversClass; | ||
|
|
||
| #[CoversClass('MostlyStaticPagesController')] | ||
| final class MostlyStaticPagesControllerTest extends TestCase | ||
| { | ||
| use IntegrationTestTrait; | ||
|
|
||
| public static function defaultPageSlugsProvider(): array | ||
| { | ||
| return [ | ||
| ['duplicate-landing'], | ||
| ['default-handoff'], | ||
| ['error-landing'], | ||
| ['mfa-required'], | ||
| ['petition-complete'], | ||
| ]; | ||
| } | ||
|
|
||
| private function getComanageCoId(): int | ||
| { | ||
| $Cos = TableRegistry::getTableLocator()->get('Cos'); | ||
| $co = $Cos->find('COmanageCO')->firstOrFail(); | ||
|
|
||
| return (int)$co->id; | ||
| } | ||
|
|
||
| public function testDefaultPagesRenderOverHttp(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}"); | ||
|
|
||
| $this->assertResponseOk(); | ||
| $this->assertResponseContains((string)$page->title); | ||
| } | ||
|
|
||
| /** | ||
| * @dataProvider defaultPageSlugsProvider | ||
| */ | ||
| public function testDefaultPagesRenderOverHttp_withProvider(string $slug): void | ||
| { | ||
| $this->testDefaultPagesRenderOverHttp($slug); | ||
| } | ||
|
|
||
| private function assertDefaultPageExists(string $name, string $expectedContext): void | ||
| { | ||
| $coId = $this->getComanageCoId(); | ||
|
|
||
| $MostlyStaticPages = TableRegistry::getTableLocator()->get('MostlyStaticPages'); | ||
|
|
||
| $page = $MostlyStaticPages->find() | ||
| ->where([ | ||
| 'co_id' => $coId, | ||
| 'name' => $name, | ||
| 'status' => SuspendableStatusEnum::Active, | ||
| 'context' => $expectedContext, | ||
| ]) | ||
| ->first(); | ||
|
|
||
| $this->assertNotEmpty( | ||
| $page, | ||
| sprintf('Expected Mostly Static Page "%s" to exist for CO %d after setup', $name, $coId) | ||
| ); | ||
| } | ||
|
|
||
| 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 | ||
| { | ||
| $this->assertDefaultPageExists('petition-complete', PageContextEnum::EnrollmentHandoff); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters