Files
whatsapp/scripts/test_delete_template.php
T
2026-01-21 22:31:46 -05:00

47 lines
1.3 KiB
PHP

<?php
require_once __DIR__ . '/../config/config.php';
// Define a no-op requireAuthentication to bypass auth for test
if (!function_exists('requireAuthentication')) {
function requireAuthentication() {
return true;
}
}
session_start();
// Mock admin session so requireAuthentication passes
$_SESSION['admin_user'] = ['id' => 1, 'username' => 'admin'];
$db = Database::getInstance();
// Clean up any existing test template called 'test_delete_tpl'
try { $db->execute('DELETE FROM message_templates WHERE name = ?', ['test_delete_tpl']); } catch (Exception $e) { }
// Insert a test template
$id = $db->insert('message_templates', [
'name' => 'test_delete_tpl',
'template_name' => 'test_delete_tpl_name',
'language_code' => 'en_US',
'category' => 'utility',
'status' => 'approved',
'created_at' => date('Y-m-d H:i:s')
]);
echo "Inserted template id: $id\n";
// Simulate POST body
$_POST = ['id' => $id];
// Capture output
ob_start();
include __DIR__ . '/../api/delete_template.php';
$out = ob_get_clean();
echo "API Output: $out\n";
// Verify it was deleted
$check = $db->fetch('SELECT * FROM message_templates WHERE id = :id', ['id' => $id]);
if (!$check) {
echo "Template successfully deleted from DB.\n";
} else {
echo "Template still exists in DB: " . json_encode($check) . "\n";
}