Skip to content

Commit

Permalink
add mostly static pages tests.improve github actions yaml config
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis committed Apr 14, 2026
1 parent aa5d790 commit 7990aff
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 4 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/registry-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
2 changes: 2 additions & 0 deletions app/tests/TestCase/Command/RegistrySetupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
111 changes: 111 additions & 0 deletions app/tests/TestCase/Controller/MostlyStaticPagesControllerTest.php
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);
}
}
6 changes: 3 additions & 3 deletions app/tests/TestCase/Controller/PagesControllerTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/**
Expand All @@ -20,10 +21,9 @@
use Cake\TestSuite\Constraint\Response\StatusCode;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;

/**
* PagesControllerTest class
*/
#[CoversClass('PagesController')]
class PagesControllerTest extends TestCase
{
use IntegrationTestTrait;
Expand Down

0 comments on commit 7990aff

Please sign in to comment.