up
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
<?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";
|
||||
}
|
||||
Reference in New Issue
Block a user