<?php
/**
 * Slice 8Z-p · Smoke test for ApprovalChain::myQueue $q + entityDetailUrl().
 *
 * - Confirms `q` filters ref_label / chain title / submitter name.
 * - Confirms entityDetailUrl returns the right URL per entity_type.
 */
define('DS', DIRECTORY_SEPARATOR);
define('ROOT', dirname(__DIR__));
define('PROOT', '/rsflow.dspera/');
require_once ROOT . DS . 'config' . DS . 'config.php';
require_once ROOT . DS . 'core' . DS . 'Application.php';
require_once ROOT . DS . 'core' . DS . 'Model.php';
require_once ROOT . DS . 'core' . DS . 'DB.php';
require_once ROOT . DS . 'app' . DS . 'models' . DS . 'ApprovalChain.php';

function ok(bool $c, string $m): void { echo ($c ? "  ✓ " : "  ✗ ") . $m . "\n"; }
function h(string $t): void { echo "\n==== $t ====\n"; }

$ac = new ApprovalChain();

h('1. entityDetailUrl per entity_type');
$cases = [
    ['type' => 'TENDER_CONTRACT',        'eid' => 400, 'aid' => 1195, 'want' => '/rsflow.dspera/Tenders/view/400#tab-contract'],
    ['type' => 'TENDER_PRICING',         'eid' => 273, 'aid' => 999,  'want' => '/rsflow.dspera/Tenders/view/273#tab-pricing'],
    ['type' => 'lpo',                    'eid' => 42,  'aid' => 500,  'want' => '/rsflow.dspera/FinChains/view/500'],
    ['type' => 'payment_schedule',       'eid' => 77,  'aid' => 501,  'want' => '/rsflow.dspera/FinChains/view/501'],
    ['type' => 'SERVICE_REQUISITION',    'eid' => 11,  'aid' => 502,  'want' => '/rsflow.dspera/FinChains/view/502'],
];
foreach ($cases as $c) {
    $got = $ac->entityDetailUrl(['entity_type' => $c['type'], 'entity_id' => $c['eid'], 'c0d' => $c['aid']]);
    ok($got === $c['want'], sprintf("%-24s → %s", $c['type'], $got));
}

h('2. myQueue accepts q param without errors');
$res = $ac->myQueue(0, 'Administrator', '', '', 1, 25, 'nothing-matches-this-string-xyz');
ok(is_array($res) && isset($res['rows']),  'result shape OK');
ok((int)$res['total'] === 0,                'q with no match → total=0');

$resAll = $ac->myQueue(0, 'Administrator', '', '', 1, 25, '');
ok(is_array($resAll) && isset($resAll['total']), 'empty q returns full queue count');

echo "\n=== DONE ===\n";
