From 7990aff3f518e455bc8956b455b0a0134a9b8242 Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Tue, 14 Apr 2026 12:40:17 +0000 Subject: [PATCH] add mostly static pages tests.improve github actions yaml config --- .github/workflows/registry-ci.yml | 9 +- .../TestCase/Command/RegistrySetupTest.php | 2 + .../MostlyStaticPagesControllerTest.php | 111 ++++++++++++++++++ .../Controller/PagesControllerTest.php | 6 +- 4 files changed, 124 insertions(+), 4 deletions(-) create mode 100644 app/tests/TestCase/Controller/MostlyStaticPagesControllerTest.php diff --git a/.github/workflows/registry-ci.yml b/.github/workflows/registry-ci.yml index 407cd801f..4e58f47ae 100644 --- a/.github/workflows/registry-ci.yml +++ b/.github/workflows/registry-ci.yml @@ -239,9 +239,16 @@ jobs: set -euxo pipefail tree -L 3 "${COMANAGE_REGISTRY_DIR}" + - name: Composer update (dev) + shell: bash + working-directory: ${{ env.COMANAGE_REGISTRY_DIR }}/app + run: | + set -euxo pipefail + composer update --no-interaction --no-progress --dev + - name: Run PHPUnit (DB_ENGINE=${{ matrix.db.engine }}) shell: bash - working-directory: /srv/comanage-registry/app + working-directory: ${{ env.COMANAGE_REGISTRY_DIR }}/app run: | set -euxo pipefail echo "DB_ENGINE=${DB_ENGINE}" diff --git a/app/tests/TestCase/Command/RegistrySetupTest.php b/app/tests/TestCase/Command/RegistrySetupTest.php index 1bf85f6cd..06ca74c40 100644 --- a/app/tests/TestCase/Command/RegistrySetupTest.php +++ b/app/tests/TestCase/Command/RegistrySetupTest.php @@ -7,9 +7,11 @@ use Cake\Console\TestSuite\ConsoleIntegrationTestTrait; use Cake\Datasource\ConnectionManager; use Cake\TestSuite\TestCase; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Group; #[Group('registry-setup')] +#[CoversClass('SetupCommand')] final class RegistrySetupTest extends TestCase { use ConsoleIntegrationTestTrait; diff --git a/app/tests/TestCase/Controller/MostlyStaticPagesControllerTest.php b/app/tests/TestCase/Controller/MostlyStaticPagesControllerTest.php new file mode 100644 index 000000000..07dda8eed --- /dev/null +++ b/app/tests/TestCase/Controller/MostlyStaticPagesControllerTest.php @@ -0,0 +1,111 @@ +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); + } +} diff --git a/app/tests/TestCase/Controller/PagesControllerTest.php b/app/tests/TestCase/Controller/PagesControllerTest.php index f0f72c9d0..ebc70bb95 100644 --- a/app/tests/TestCase/Controller/PagesControllerTest.php +++ b/app/tests/TestCase/Controller/PagesControllerTest.php @@ -1,4 +1,5 @@