mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-25 16:19:19 +02:00
53 lines
1.5 KiB
PHP
53 lines
1.5 KiB
PHP
<?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']);
|
|
}
|
|
}
|
|
}
|