updating database code and testscripts
This commit is contained in:
parent
5148406147
commit
e815ac9777
@ -10,10 +10,19 @@ class DBBoard extends Database{
|
||||
$query->execute();
|
||||
$boardArray = [];
|
||||
while($result = $query->fetch(PDO::FETCH_BOTH)){
|
||||
$board = new Board($result['ID'],$result['name'],$result['permLevel']);
|
||||
$board = new Board($result['ID'], $result['name'], $result['description'], $result['permLevel']);
|
||||
array_push($boardArray, $board);
|
||||
}
|
||||
return $boardArray;
|
||||
}
|
||||
static function registerBoard(Board $board)
|
||||
{
|
||||
$con = self::connectToDB();
|
||||
$query = $con->prepare("INSERT INTO `board` ( `name`, `description`, `permLevel`) VALUES (':name', ':description', :permLevel)");
|
||||
$query->bindParam(":name", $board->getName());
|
||||
$query->bindParam(":description", $board->description());
|
||||
$query->bindParam(":permLevel", $board->permLevel());
|
||||
$query->execute();
|
||||
}
|
||||
|
||||
}
|
||||
@ -3,10 +3,24 @@ namespace model\forum;
|
||||
class Board {
|
||||
public $id;
|
||||
public $name;
|
||||
public $description;
|
||||
public $permLevel;
|
||||
function __construct($id, $name, $permLevel){
|
||||
function __construct($id, $name, $description, $permLevel){
|
||||
$this->id = $id;
|
||||
$this->name = $name;
|
||||
$this->description = $description;
|
||||
$this->permLevel = $permLevel;
|
||||
}
|
||||
function setId($id){
|
||||
$this->id = $id;
|
||||
}
|
||||
function setName($name){
|
||||
$this->name = $name;
|
||||
}
|
||||
function setDescription($description){
|
||||
$this->description = $description;
|
||||
}
|
||||
function setPermLevel($permLevel){
|
||||
$this->permLevel = $permLevel;
|
||||
}
|
||||
function getId(){
|
||||
@ -15,6 +29,9 @@ class Board {
|
||||
function getName(){
|
||||
return $this->name;
|
||||
}
|
||||
function getDescription(){
|
||||
return $this->description;
|
||||
}
|
||||
function getPermLevel(){
|
||||
return $this->permLevel;
|
||||
}
|
||||
|
||||
@ -1,12 +1,23 @@
|
||||
<?php
|
||||
namespace model\testactions;
|
||||
use controller\db\Database;
|
||||
use controller\db\DBBoard;
|
||||
use controller\db\DBUser;
|
||||
use model\forum\Board;
|
||||
use PDO;
|
||||
use PDOException;
|
||||
class TA_PopulateDB extends TestAction{
|
||||
function TA_PopulateDB(){
|
||||
parent::__construct();
|
||||
}
|
||||
function registerUser($email, $password, $username){
|
||||
DBUser::registerUser($email,$password,$username);
|
||||
$user = DBUser::getUserByEmail($email);
|
||||
Database::registerActivationKey($user->getId(), $username);
|
||||
Database::activateUser($username);
|
||||
}
|
||||
|
||||
|
||||
function execute(){
|
||||
try{
|
||||
//connect to sql server
|
||||
@ -14,12 +25,20 @@ class TA_PopulateDB extends TestAction{
|
||||
|
||||
|
||||
self::logMessage('table doesnt exist', "OK");
|
||||
$query = $con->query("INSERT INTO users ( `username`, `email`, `password`, `login_date`, `reg_ip`, `active`) VALUES
|
||||
( 'andreas', 'andreas@andreas.nl', 'jenk', '2019-01-01 14:35:33', '192.168.0.2', 1),
|
||||
( 'bram', 'bram@bram.nl', 'jenk', '2019-01-01 14:35:33', '192.168.0.1', 1)");
|
||||
|
||||
|
||||
$this->registerUser('andreas@andreas.nl','jenk', 'andreas');
|
||||
$this->registerUser('bram@bram.nl','jenk', 'bram');
|
||||
|
||||
|
||||
self::logMessage("created test users", "OK");
|
||||
$query = $con->query("INSERT INTO `board` ( `name`, `description`, `permLevel`) VALUES ('General Discussion', 'Plek om algemene discussie te voeren.', '0'),
|
||||
('Off Topic', 'Voor alle irrelevante zooi.', '0')");
|
||||
|
||||
DBBoard::registerBoard(new Board(-1, 'General Discussion', 'Plek om algemene discussie te voeren.', '0'));
|
||||
DBBoard::registerBoard(new Board(-1, 'Off Topic', 'Voor alle irrelevante zooi.', '0'));
|
||||
|
||||
|
||||
|
||||
|
||||
self::logMessage("created test boards", "OK");
|
||||
$query = $con->query("INSERT INTO `thread` ( `users_ID`, `board_ID`, `title`, `text`, `date_created`) VALUES ('1', '1', 'Test thread', 'Deze thread is een test.', '2019-06-20 13:55:37'),
|
||||
('1', '2', 'Waa', 'Frist niffo', '2019-06-20 13:56:42')");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user