You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
3.8 KiB
PHP
95 lines
3.8 KiB
PHP
<?php
|
|
|
|
// Characterize the public ticket queue and controller contracts before the
|
|
// read/write modules are deepened. These assertions intentionally verify
|
|
// outcomes rather than the current controller implementation structure.
|
|
require dirname(__DIR__) . '/vendor/autoload.php';
|
|
|
|
use App\Models\Ticket;
|
|
use Illuminate\Database\Capsule\Manager as Capsule;
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
|
|
$assert = static function ($condition, string $message): void {
|
|
if (!$condition) {
|
|
throw new RuntimeException($message);
|
|
}
|
|
};
|
|
|
|
$capsule = new Capsule();
|
|
$capsule->addConnection(['driver' => 'sqlite', 'database' => ':memory:'], 'default');
|
|
$capsule->setAsGlobal();
|
|
$capsule->bootEloquent();
|
|
$schema = $capsule->getConnection('default')->getSchemaBuilder();
|
|
$schema->create('ticket', static function (Blueprint $table): void {
|
|
$table->increments('id');
|
|
$table->text('title');
|
|
$table->text('content');
|
|
$table->integer('rootid')->default(0);
|
|
$table->integer('userid');
|
|
$table->integer('datetime');
|
|
$table->integer('status')->default(1);
|
|
$table->string('ticket_type')->default('technical');
|
|
$table->string('priority')->default('medium');
|
|
$table->integer('instance_id')->nullable();
|
|
});
|
|
|
|
$roots = [];
|
|
for ($id = 1; $id <= 130; $id += 1) {
|
|
$roots[] = [
|
|
'id' => $id,
|
|
'title' => 'Ticket ' . $id,
|
|
'content' => 'Root ' . $id,
|
|
'rootid' => 0,
|
|
'userid' => 7,
|
|
'datetime' => 1_700_000_000 + $id,
|
|
'status' => $id % 2,
|
|
'ticket_type' => 'technical',
|
|
'priority' => 'medium',
|
|
'instance_id' => null,
|
|
];
|
|
}
|
|
Capsule::table('ticket')->insert($roots);
|
|
Capsule::table('ticket')->insert([
|
|
'id' => 131,
|
|
'title' => 'Ticket 1',
|
|
'content' => 'Latest reply',
|
|
'rootid' => 1,
|
|
'userid' => 9,
|
|
'datetime' => 1_800_000_000,
|
|
'status' => 1,
|
|
'ticket_type' => 'technical',
|
|
'priority' => 'medium',
|
|
'instance_id' => null,
|
|
]);
|
|
|
|
$queue = Ticket::where('userid', 7)->where('rootid', 0)
|
|
->selectRaw('ticket.*, COALESCE((SELECT MAX(ticket_replies.datetime) '
|
|
. 'FROM ticket AS ticket_replies WHERE ticket_replies.rootid = ticket.id), '
|
|
. 'ticket.datetime) AS last_activity_at')
|
|
->orderByDesc('last_activity_at')->orderByDesc('id')
|
|
->paginate(15, ['*'], 'page', 9);
|
|
|
|
$assert($queue->total() === 130, 'The user queue lost tickets beyond an old preload cap.');
|
|
$assert($queue->lastPage() === 9 && $queue->count() === 10,
|
|
'The user queue does not expose the final page of a 130-ticket history.');
|
|
$first = Ticket::where('userid', 7)->where('rootid', 0)
|
|
->selectRaw('ticket.*, COALESCE((SELECT MAX(ticket_replies.datetime) '
|
|
. 'FROM ticket AS ticket_replies WHERE ticket_replies.rootid = ticket.id), '
|
|
. 'ticket.datetime) AS last_activity_at')
|
|
->orderByDesc('last_activity_at')->orderByDesc('id')->first();
|
|
$assert($first !== null && (int) $first->id === 1,
|
|
'A recent reply did not move its thread to the front of the queue.');
|
|
|
|
$userController = file_get_contents(dirname(__DIR__) . '/app/Controllers/UserController.php');
|
|
$adminController = file_get_contents(dirname(__DIR__) . '/app/Controllers/Admin/TicketController.php');
|
|
$createTransaction = strpos($userController, '(new TicketThreadService())->open');
|
|
$createNotification = strpos($userController, '$this->notifyTicketCreated($result->root)');
|
|
$assert($createTransaction !== false && $createNotification !== false
|
|
&& $createTransaction < $createNotification,
|
|
'Ticket creation notifications are not visibly ordered after persistence.');
|
|
$assert(str_contains($adminController, 'generate(false)')
|
|
&& str_contains($adminController, "'statusTotals'"),
|
|
'The administrator queue no longer exposes server paging and complete totals.');
|
|
|
|
echo "Ticket workflow characterization checks passed.\n";
|