Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis committed Apr 14, 2026
1 parent 333c811 commit 1e47055
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 62 deletions.
38 changes: 11 additions & 27 deletions app/tests/TestCase/ApplicationTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/**
Expand All @@ -14,33 +15,25 @@
* @since 3.3.0
* @license https://opensource.org/licenses/mit-license.php MIT License
*/

namespace App\Test\TestCase;

use App\Application;
use App\Middleware\HostHeaderMiddleware;
use Cake\Core\Configure;
use Cake\Error\Middleware\ErrorHandlerMiddleware;
use Cake\Http\MiddlewareQueue;
use Cake\Routing\Middleware\AssetMiddleware;
use Cake\Routing\Middleware\RoutingMiddleware;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;

/**
* ApplicationTest class
*/
class ApplicationTest extends TestCase
#[CoversClass(Application::class)]
final class ApplicationTest extends TestCase
{
use IntegrationTestTrait;

/**
* Test bootstrap in production.
*
* @return void
*/
public function testBootstrap()
public function testBootstrap(): void
{
Configure::write('debug', false);

$app = new Application(dirname(__DIR__, 2) . '/config');
$app->bootstrap();
$plugins = $app->getPlugins();
Expand All @@ -50,31 +43,22 @@ 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();

$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());
Expand Down
56 changes: 21 additions & 35 deletions app/tests/TestCase/Controller/MostlyStaticPagesControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand All @@ -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
Expand All @@ -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);
}
}

0 comments on commit 1e47055

Please sign in to comment.