Add a regression test script and fix bug
parent
7388868678
commit
b1dbd94b00
16
Script.php
16
Script.php
|
@ -170,8 +170,8 @@ if (!empty($_POST["form_signup"])) {
|
|||
|
||||
// apply password_hash()
|
||||
$password_hash = password_hash($password, PASSWORD_DEFAULT);
|
||||
$sql = "INSERT INTO `users_table`(`Email`, `Password`, `Full_Name`, `UserType`, `Student_ID`) VALUES "
|
||||
. "('$email','$password_hash','$fullname','Student','$student_id')";
|
||||
$sql = "INSERT INTO `users_table`(`Email`, `Password`, `HashPassword`, `Full_Name`, `UserType`, `Student_ID`) VALUES "
|
||||
. "('$email','$password_hash','','$fullname','Student','$student_id')";
|
||||
|
||||
|
||||
$_SESSION['user_fullname'] =$_SESSION['user_fullname_temp'];
|
||||
|
@ -356,17 +356,15 @@ if (!empty($_POST["form_createlecturrer"])){
|
|||
exit;
|
||||
}
|
||||
$password_hash = password_hash("$password", PASSWORD_DEFAULT);
|
||||
$sql = "INSERT INTO `users_table`(`Email`, `Password`, `Full_Name`, `UserType`) VALUES "
|
||||
. "('$email','$password_hash','$fullname','$type')";
|
||||
$sql = "INSERT INTO `users_table`(`Email`, `Password`, `HashPassword`, `Full_Name`, `UserType`) VALUES ('$email','$password_hash','','$fullname','$type')";
|
||||
|
||||
if ($con->query($sql) === TRUE) {
|
||||
try {
|
||||
$result = mysqli_query($con, $sql);
|
||||
$_SESSION["info_Admin_Users"] = $type . " user created successfully. Use email " . $email . " as account name and ". $password ." as password.";
|
||||
header("Location: Admin.php");
|
||||
|
||||
} else {
|
||||
alert("Error: " . $sql . "<br>" . $con->error);
|
||||
} catch (Exception $ex) {
|
||||
echo "$ex";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ### FUNCTION TO GENERATE INITIAL PASSWORDS ###//
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.support.ui import WebDriverWait
|
||||
from selenium.webdriver.support import expected_conditions as EC
|
||||
from selenium.common.exceptions import NoSuchElementException, UnexpectedAlertPresentException
|
||||
|
||||
|
||||
def login(driver, url, username, password):
|
||||
try:
|
||||
driver.get(url)
|
||||
|
||||
# Fill in the login form
|
||||
user_input = WebDriverWait(driver, 10).until(
|
||||
EC.element_to_be_clickable((By.ID, "user_name"))
|
||||
)
|
||||
user_input.send_keys(username)
|
||||
|
||||
password_input = WebDriverWait(driver, 10).until(
|
||||
EC.element_to_be_clickable((By.ID, "user_password"))
|
||||
)
|
||||
password_input.send_keys(password)
|
||||
|
||||
# Click the login button
|
||||
login_button = WebDriverWait(driver, 10).until(
|
||||
EC.element_to_be_clickable((By.ID, "login_btn"))
|
||||
)
|
||||
login_button.click()
|
||||
|
||||
# Wait for the admin_tab to become clickable
|
||||
admin_tab = WebDriverWait(driver, 10).until(
|
||||
EC.element_to_be_clickable((By.ID, "admin_tab"))
|
||||
)
|
||||
except (NoSuchElementException, UnexpectedAlertPresentException) as e:
|
||||
return f"Error: {str(e)}"
|
|
@ -0,0 +1,73 @@
|
|||
from helper import login
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.support.wait import WebDriverWait
|
||||
from selenium.webdriver.support import expected_conditions as EC
|
||||
import time
|
||||
|
||||
def test_admin_can_create_lecturer_account(driver, url, admin_username, admin_password, restore_database):
|
||||
# Administrator (admin@qq.com, password 123) logs in
|
||||
driver.maximize_window()
|
||||
login(driver, url, admin_username, admin_password)
|
||||
|
||||
# Create a Lecture account for mrlan@qq.com, password [123Abc!]
|
||||
tab = driver.find_element(By.ID, 'tab_ins_accounts')
|
||||
tab.click()
|
||||
elem = driver.find_element(By.NAME, 'fullname')
|
||||
elem.send_keys('Mr Lan')
|
||||
elem = driver.find_element(By.NAME, 'email')
|
||||
elem.send_keys('mrlan@qq.com')
|
||||
elem = driver.find_element(By.NAME, 'password')
|
||||
elem.send_keys('123Abc!!')
|
||||
radio_button = driver.find_element(By.NAME, 'type')
|
||||
radio_button.click()
|
||||
button = driver.find_element(By.NAME, 'create_btn')
|
||||
button.click()
|
||||
time.sleep(1)
|
||||
|
||||
# Log out Admin
|
||||
logout_button = WebDriverWait(driver, 10).until(
|
||||
EC.element_to_be_clickable(
|
||||
(By.XPATH, "//a[contains(@class, 'nav-link') and contains(@href, 'logout.php')]"))
|
||||
)
|
||||
logout_button.click()
|
||||
time.sleep(1)
|
||||
|
||||
# Log in Lecture account
|
||||
login(driver, url, 'mrlan@qq.com', '123Abc!!')
|
||||
elems = driver.find_elements(By.CLASS_NAME, 'nav-link')
|
||||
assert '(Lecturer)' in elems[0].text
|
||||
driver.quit()
|
||||
|
||||
|
||||
|
||||
def test_lecturer_can_create_course():
|
||||
# Lecturer mrlan@qq.com logs in
|
||||
# Create a course called CSC1001 Advanced Software Engineering, 2024
|
||||
assert True
|
||||
|
||||
|
||||
def test_lecturer_can_post_assignment():
|
||||
# Lecturer mrlan@qq.com logs in
|
||||
# Create an assignment called Take-home quiz 1 for course CSC1001
|
||||
assert True
|
||||
|
||||
|
||||
def test_lecturer_can_add_student_numbers():
|
||||
# Lecturer mrlan@qq.com logs in
|
||||
# Add 6 ASE student numbers
|
||||
assert True
|
||||
|
||||
|
||||
def test_student_can_sign_up():
|
||||
# Student with recognizable student number can sign up an account
|
||||
assert True
|
||||
|
||||
|
||||
def test_student_can_join_course():
|
||||
# Student can join CSC1001 Advanced Software Engineering
|
||||
assert True
|
||||
|
||||
|
||||
def test_student_can_submit_assignment():
|
||||
# Student can submit Take-home quiz 1 for CSC1001
|
||||
assert True
|
Loading…
Reference in New Issue