Files
intranet/worker/contentpanel_aushang/tests/web_fixture.php
T

40 lines
1.7 KiB
PHP

<?php
// Only copied into a temporary test document root. Never used by the application.
session_start();
$groups = ['Allgemein' => !isset($_GET['deny'])];
$user = ['mail' => 'member@example.test', 'first_name' => 'Test', 'last_name' => 'Person'];
class TestStatement extends PDOStatement
{
public function __construct(private string $sql) {}
public function execute(?array $params = null): bool
{
if (!str_starts_with($this->sql, 'SELECT')) {
$log = str_contains($this->sql, 'WHERE COALESCE(ansage_datum_bis, ansage_datum_von) < ?')
? '/cleanup.jsonl' : '/writes.jsonl';
file_put_contents($_SERVER['DOCUMENT_ROOT'] . $log, json_encode([$this->sql, $params]) . "\n", FILE_APPEND);
}
return true;
}
public function fetchAll(int $mode = PDO::FETCH_DEFAULT, mixed ...$args): array
{
return str_contains($this->sql, 'FROM gottesdienst')
? [['id' => 1, 'title' => 'Joh 3,16', 'subtitle' => '<script>unsafe()</script>', 'date' => '2030-12-31']]
: [['id' => 2, 'title' => 'Gemeindefest', 'subtitle' => '', 'location' => 'Gemeindesaal',
'time' => '11:30:00', 'date' => '2030-12-31', 'end_date' => null]];
}
}
class TestPDO extends PDO
{
public function __construct() {}
public function prepare(string $query, array $options = []): PDOStatement|false
{
return new TestStatement($query);
}
public function query(string $query, ?int $fetchMode = null, mixed ...$fetchModeArgs): PDOStatement|false
{
return new TestStatement($query);
}
public function exec(string $statement): int|false { return 0; }
}
$pdo = new TestPDO();