Mantis-v0.0.2

This commit is contained in:
Flatlogic Bot 2026-01-15 17:23:02 +00:00
parent 19a618c6e5
commit bb70c85b30
3 changed files with 162 additions and 0 deletions

86
add_test_case.php Normal file
View File

@ -0,0 +1,86 @@
<?php
require_once 'db/config.php';
$title = $description = $precondition = $steps_to_execute = $expected_result = '';
$errors = [];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$title = trim($_POST['title'] ?? '');
$description = trim($_POST['description'] ?? '');
$precondition = trim($_POST['precondition'] ?? '');
$steps_to_execute = trim($_POST['steps_to_execute'] ?? '');
$expected_result = trim($_POST['expected_result'] ?? '');
if (empty($title)) {
$errors[] = 'Title is required.';
}
if (empty($errors)) {
try {
$pdo = db();
$stmt = $pdo->prepare('INSERT INTO test_cases (title, description, precondition, steps_to_execute, expected_result) VALUES (?, ?, ?, ?, ?)');
$stmt->execute([$title, $description, $precondition, $steps_to_execute, $expected_result]);
header('Location: test_cases.php');
exit;
} catch (PDOException $e) {
$errors[] = 'Database error: ' . $e->getMessage();
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Add New Test Case</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
body { background-color: #f8fafc; }
</style>
</head>
<body>
<div class="container py-5">
<h1 class="h3 mb-4">Add New Test Case</h1>
<?php if (!empty($errors)): ?>
<div class="alert alert-danger">
<?php foreach ($errors as $error): ?>
<p class="mb-0"><?php echo $error; ?></p>
<?php endforeach; ?>
</div>
<?php endif; ?>
<div class="card">
<div class="card-body">
<form action="add_test_case.php" method="POST">
<div class="mb-3">
<label for="title" class="form-label">Title</label>
<input type="text" class="form-control" id="title" name="title" value="<?php echo htmlspecialchars($title); ?>" required>
</div>
<div class="mb-3">
<label for="description" class="form-label">Description</label>
<textarea class="form-control" id="description" name="description" rows="3"><?php echo htmlspecialchars($description); ?></textarea>
</div>
<div class="mb-3">
<label for="precondition" class="form-label">Precondition</label>
<textarea class="form-control" id="precondition" name="precondition" rows="3"><?php echo htmlspecialchars($precondition); ?></textarea>
</div>
<div class="mb-3">
<label for="steps_to_execute" class="form-label">Steps to Execute</label>
<textarea class="form-control" id="steps_to_execute" name="steps_to_execute" rows="5"><?php echo htmlspecialchars($steps_to_execute); ?></textarea>
</div>
<div class="mb-3">
<label for="expected_result" class="form-label">Expected Result</label>
<textarea class="form-control" id="expected_result" name="expected_result" rows="3"><?php echo htmlspecialchars($expected_result); ?></textarea>
</div>
<div class="d-flex justify-content-end">
<a href="test_cases.php" class="btn btn-secondary me-2">Cancel</a>
<button type="submit" class="btn btn-primary">Submit Test Case</button>
</div>
</form>
</div>
</div>
</div>
</body>
</html>

View File

@ -48,6 +48,7 @@ $projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
<h1 class="display-4">Welcome to Your Bug Tracker</h1>
<p class="lead">A simple application to track bugs and test cases.</p>
<a href="bugs.php" class="btn btn-primary btn-lg mt-3">Go to Bug Dashboard</a>
<a href="test_cases.php" class="btn btn-secondary btn-lg mt-3">Go to Test Case Dashboard</a>
</main>
<footer class="text-center mt-5">
<p class="text-muted">Runtime: PHP <code><?= htmlspecialchars($phpVersion) ?></code> — UTC <code><?= htmlspecialchars($now) ?></code></p>

75
test_cases.php Normal file
View File

@ -0,0 +1,75 @@
<?php
require_once 'db/config.php';
$pdo = db();
$stmt = $pdo->query('SELECT * FROM test_cases ORDER BY created_at DESC');
$test_cases = $stmt->fetchAll();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test Case Dashboard</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
<style>
body { background-color: #f8fafc; }
.card { border: 1px solid #e2e8f0; }
</style>
</head>
<body>
<div class="container py-5">
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="h3">Test Case Dashboard</h1>
<a href="add_test_case.php" class="btn btn-primary d-inline-flex align-items-center">
<i data-feather="plus" class="me-2"></i>Add New Test Case
</a>
</div>
<div class="card">
<div class="card-body">
<?php if (empty($test_cases)): ?>
<div class="text-center py-5">
<p class="mb-0">No test cases found.</p>
</div>
<?php else: ?>
<div class="table-responsive">
<table class="table table-hover">
<thead class="table-light">
<tr>
<th scope="col">Title</th>
<th scope="col">Status</th>
<th scope="col">Created At</th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($test_cases as $test_case): ?>
<tr>
<td><?php echo htmlspecialchars($test_case['title']); ?></td>
<td><span class="badge bg-secondary"><?php echo htmlspecialchars($test_case['status']); ?></span></td>
<td><?php echo htmlspecialchars($test_case['created_at']); ?></td>
<td>
<a href="#" class="btn btn-sm btn-outline-secondary d-inline-flex align-items-center">
<i data-feather="eye" class="me-2"></i>View
</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?>
</div>
</div>
<div class="text-center mt-4">
<a href="index.php">Back to Home</a>
</div>
</div>
<script>
feather.replace()
</script>
</body>
</html>