-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_test_tasks.php
More file actions
48 lines (40 loc) · 1.69 KB
/
Copy path_test_tasks.php
File metadata and controls
48 lines (40 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
require 'php/connect.php';
session_start();
// Mock session for testing
$accRes = $conn->query("SELECT AccountID FROM usraccount_tbl WHERE role='user' LIMIT 1");
if ($accRes->num_rows == 0) die("No user account found to test with.\n");
$accId = $accRes->fetch_assoc()['AccountID'];
$_SESSION['account_id'] = $accId;
echo "Testing with AccountID: $accId\n";
// 1. Create Task
$title = "Test Task " . rand(100,999);
$desc = "Description for test task";
$priority = "High";
$deadline = date('Y-m-d', strtotime('+7 days'));
echo "Creating task: $title... ";
$stmt = $conn->prepare("INSERT INTO tasks_tbl (AccountID, Title, Description, Priority, Deadline, Status) VALUES (?, ?, ?, ?, ?, 'Pending')");
$stmt->bind_param("issss", $accId, $title, $desc, $priority, $deadline);
if (!$stmt->execute()) die("FAIL: " . $stmt->error . "\n");
$taskId = $stmt->insert_id;
echo "OK (ID: $taskId)\n";
// 2. Read Task
echo "Reading task... ";
$res = $conn->query("SELECT * FROM tasks_tbl WHERE TaskID=$taskId");
if ($res->num_rows === 0) die("FAIL: Task not found\n");
$task = $res->fetch_assoc();
echo "OK ({$task['Title']})\n";
// 3. Update Task
echo "Updating task status... ";
$conn->query("UPDATE tasks_tbl SET Status='Completed' WHERE TaskID=$taskId");
$res = $conn->query("SELECT Status FROM tasks_tbl WHERE TaskID=$taskId");
$status = $res->fetch_assoc()['Status'];
if ($status !== 'Completed') die("FAIL: Status not updated (got $status)\n");
echo "OK\n";
// 4. Delete Task
echo "Deleting task... ";
$conn->query("DELETE FROM tasks_tbl WHERE TaskID=$taskId");
$res = $conn->query("SELECT * FROM tasks_tbl WHERE TaskID=$taskId");
if ($res->num_rows > 0) die("FAIL: Task not deleted\n");
echo "OK\n";
echo "\nALL TESTS PASSED.\n";