mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-25 16:19:19 +02:00
Phase 4 cleanup: migrate old tests to PHPUnit, add ErrorHandler/PureLogic/SearchController tests, remove app/tests/, update justfile test target
This commit is contained in:
52
tests/phpunit/SearchControllerTest.php
Normal file
52
tests/phpunit/SearchControllerTest.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* SearchControllerTest — Regression test for SearchController::handleSearch()
|
||||
* always returning a 'coverMap' key.
|
||||
*/
|
||||
class SearchControllerTest extends TestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
TestDatabase::resetData();
|
||||
TestDatabase::seedBasicThesis('Test Thesis', 'Author', 2024);
|
||||
|
||||
// Set up GET for SearchController (it reads from $_GET)
|
||||
$_GET = ['query' => ''];
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$_GET = [];
|
||||
}
|
||||
|
||||
public function testHandleSearchReturnsCoverMapKey(): void
|
||||
{
|
||||
$db = TestDatabase::getInstance();
|
||||
$rateLimit = new RateLimit(1000, 60, sys_get_temp_dir() . '/xamxam_rl_test_' . uniqid());
|
||||
$searchCtrl = new SearchController($db, $rateLimit);
|
||||
|
||||
$vars = $searchCtrl->handleSearch();
|
||||
|
||||
$this->assertArrayHasKey('coverMap', $vars);
|
||||
$this->assertIsArray($vars['coverMap']);
|
||||
}
|
||||
|
||||
public function testCoverMapContainsKnownThesis(): void
|
||||
{
|
||||
$pdo = TestDatabase::getPDO();
|
||||
$thesisId = $pdo->query('SELECT id FROM theses LIMIT 1')->fetchColumn();
|
||||
|
||||
$db = TestDatabase::getInstance();
|
||||
$rateLimit = new RateLimit(1000, 60, sys_get_temp_dir() . '/xamxam_rl_test2_' . uniqid());
|
||||
$searchCtrl = new SearchController($db, $rateLimit);
|
||||
|
||||
$vars = $searchCtrl->handleSearch();
|
||||
|
||||
if (!empty($vars['results'])) {
|
||||
$this->assertArrayHasKey((int)$thesisId, $vars['coverMap']);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user