87 lines
3.8 KiB
PHP
87 lines
3.8 KiB
PHP
<?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>
|