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.
virt/web/tests/TicketTelegramBoundaryTest.php

35 lines
2.2 KiB
PHP

<?php
require dirname(__DIR__) . '/app/Services/TicketTelegramNotifier.php';
use App\Services\TicketTelegramNotifier as Notifications;
function check($value, string $label): void
{
if (!$value) {
throw new RuntimeException($label);
}
}
$message = ['chat' => ['type' => 'private', 'id' => 123], 'from' => ['id' => 123], 'text' => '/start ' . str_repeat('a', 48)];
check(Notifications::bindingCommand(['message' => $message]) !== null, 'Private one-time code command rejected');
foreach ([['text' => '/reply 1 hello'], ['chat' => ['type' => 'group', 'id' => 123]], ['from' => ['id' => 124]], ['forward_origin' => ['type' => 'user']], ['from' => ['id' => 123, 'is_bot' => true]], ['text' => '/start bad']] as $change) {
check(Notifications::bindingCommand(['message' => array_replace($message, $change)]) === null, 'Unexpected bot capability accepted');
}
$config = file_get_contents(dirname(__DIR__) . '/config/.config.php.example');
foreach (['enable_telegram', 'telegram_token', 'telegram_request_token', 'tgUrl'] as $legacy) {
check(!str_contains($config, $legacy), 'Legacy Telegram config.php setting remains: ' . $legacy);
}
$service = file_get_contents(dirname(__DIR__) . '/app/Services/TicketTelegramConfig.php');
check(str_contains($service, 'ticket_telegram_webhook_base_url'), 'Database Telegram communication origin is missing');
$notifier = file_get_contents(dirname(__DIR__) . '/app/Services/TicketTelegramNotifier.php');
$transport = file_get_contents(dirname(__DIR__) . '/app/Services/Ticket/TicketNotificationTransportAdapter.php');
check(str_contains($notifier, "->where('telegram_message_id', \$command['reply_to_message_id'])")
&& str_contains($notifier, "'.update.' . \$command['update_id']")
&& !str_contains($notifier, "preg_match('/^\\/reply"),
'Telegram ticket replies are not restricted to durable reply-to-message mappings.');
check(str_contains($transport, 'TicketTelegramNotificationResult::Failed')
&& str_contains($transport, "throw new \\RuntimeException('Telegram ticket delivery failed')"),
'Telegram transport still reports failed remote delivery as success.');
echo "Administrator-only Telegram command and database configuration boundaries passed.\n";