PHP Classes

File: tests/test_delete_api.php

Recommend this page to a friend!
  Packages of Matthew Asham   Binkterm PHP   tests/test_delete_api.php   Download  
File: tests/test_delete_api.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Binkterm PHP
Bulletin board system based on the Web
Author: By
Last change:
Date: 5 days ago
Size: 1,256 bytes
 

Contents

Class file image Download
<?php

// Simple test for the delete API
$url = 'http://localhost:8080/api/messages/echomail/delete';

// Get a test message ID first
require_once __DIR__ . '/../vendor/autoload.php';
use
BinktermPHP\Database;

Database::getInstance();
$db = Database::getInstance()->getPdo();
$stmt = $db->query("SELECT id FROM echomail LIMIT 1");
$message = $stmt->fetch();

if (!
$message) {
    echo
"No messages found to test with\n";
    exit(
1);
}

$messageId = $message['id'];
echo
"Testing with message ID: $messageId\n";

// Prepare test data
$data = json_encode([
   
'messageIds' => [$messageId]
]);

echo
"Request data: $data\n";

// Make the API call
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
   
'Content-Type: application/json',
   
'Content-Length: ' . strlen($data)
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_COOKIE, 'binktermphp_session=' . ($_COOKIE['binktermphp_session'] ?? 'none'));

$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

echo
"HTTP Code: $httpCode\n";
echo
"Response: $response\n";