test : fini !

master
BelsethUwU 1 year ago
parent b1e79e1689
commit 0d189081ee

@ -69,7 +69,12 @@ class GatewayChapter
public function deleteChapter($id) public function deleteChapter($id)
{ {
$query = "DELETE FROM chapters WHERE id = :id;"; $query = "DELETE FROM chapters WHERE id = :id;";
$this->con->executeQuery($query, array(':id' => array($id, PDO::PARAM_INT))); $this->con->executeQuery(
$query,
array(
':id' => array($id, PDO::PARAM_INT)
)
);
return $this->con->getResults(); return $this->con->getResults();
} }

@ -12,6 +12,9 @@ class GatewayJouer
public function __construct() public function __construct()
{ {
global $dns, $user, $pass; global $dns, $user, $pass;
if ($dns == NULL || $user == NULL || $pass == NULL) {
require_once(__DIR__ . '/../usages/Config_DB.php');
}
$this->con = new Connection($dns, $user, $pass); $this->con = new Connection($dns, $user, $pass);
} }
@ -67,6 +70,9 @@ class GatewayJouer
) )
); );
$results = $this->con->getResults(); $results = $this->con->getResults();
if (count($results) == 0) {
return false;
}
return $results[0]; return $results[0];
} }
public function getMaxScoresWithChapter($player) public function getMaxScoresWithChapter($player)
@ -81,4 +87,15 @@ class GatewayJouer
$results = $this->con->getResults(); $results = $this->con->getResults();
return $results; return $results;
} }
public function deleteJouer($jouer)
{
$query = "DELETE FROM jouer WHERE jouer.idplayer = :idplayer AND jouer.idchapter = :idchapter;";
$this->con->executeQuery(
$query,
array(
':idchapter' => array($jouer['idchapter'], PDO::PARAM_INT),
':idplayer' => array($jouer['idplayer'], PDO::PARAM_INT)
)
);
}
} }

@ -12,19 +12,21 @@ class GatewayLobby
public function __construct() public function __construct()
{ {
global $dns, $user, $pass; global $dns, $user, $pass;
if ($dns == NULL || $user == NULL || $pass == NULL) {
require_once(__DIR__ . '/../usages/Config_DB.php');
}
$this->con = new Connection($dns, $user, $pass); $this->con = new Connection($dns, $user, $pass);
} }
public function addLobby($lobby) public function addLobby($lobby)
{ {
$query = "insert into Lobbies(id,name,password,nbPlayer) values (:id,:name,:password,:nbPlayer);"; $query = "insert into lobbies(id,name,password,nbplayers) values (:id,:name,:password,:nbplayers);";
$this->con->executeQuery( $this->con->executeQuery(
$query, $query,
array( array(
':id' => array($lobby->getId(), PDO::PARAM_INT), ':id' => array($lobby->getId(), PDO::PARAM_INT),
':name' => array($lobby->getName(), PDO::PARAM_STR), ':name' => array($lobby->getName(), PDO::PARAM_STR),
':password' => array($lobby->getPassword(), PDO::PARAM_STR), ':password' => array($lobby->getPassword(), PDO::PARAM_STR),
':nbPlayer' => array($lobby->getNbPlayer(), PDO::PARAM_INT) ':nbplayers' => array($lobby->getNbPlayers(), PDO::PARAM_INT)
) )
); );
} }
@ -40,7 +42,7 @@ class GatewayLobby
public function getLobbyByName($name) public function getLobbyByName($name)
{ {
$query = "SELECT * FROM Lobbies WHERE name = :name;"; $query = "SELECT * FROM lobbies WHERE name = :name;";
$this->con->executeQuery($query, array(':name' => array($name, PDO::PARAM_STR))); $this->con->executeQuery($query, array(':name' => array($name, PDO::PARAM_STR)));
$results = $this->con->getResults(); $results = $this->con->getResults();
if ($results == NULL) { if ($results == NULL) {
@ -52,7 +54,7 @@ class GatewayLobby
public function deleteLobby($id) public function deleteLobby($id)
{ {
$query = "DELETE FROM Lobbies WHERE id = :id;"; $query = "DELETE FROM lobbies WHERE id = :id;";
$this->con->executeQuery($query, array(':id' => array($id, PDO::PARAM_INT))); $this->con->executeQuery($query, array(':id' => array($id, PDO::PARAM_INT)));
} }

@ -12,12 +12,14 @@ class GatewayPlayer
public function __construct() public function __construct()
{ {
global $dns, $user, $pass; global $dns, $user, $pass;
if ($dns == NULL || $user == NULL || $pass == NULL) {
require_once(__DIR__ . '/../usages/Config_DB.php');
}
$this->con = new Connection($dns, $user, $pass); $this->con = new Connection($dns, $user, $pass);
} }
public function addPlayer($player) public function addPlayer($player)
{ {
var_dump($player);
$query = "insert into players(nickname,password) values (:nickname,:password);"; $query = "insert into players(nickname,password) values (:nickname,:password);";
$this->con->executeQuery( $this->con->executeQuery(
$query, $query,
@ -72,7 +74,7 @@ class GatewayPlayer
); );
} }
public function updatePlayerPassword($id,$password) public function updatePlayerPassword($id, $password)
{ {
$query = "UPDATE players SET password = :password WHERE id = :id;"; $query = "UPDATE players SET password = :password WHERE id = :id;";
$this->con->executeQuery( $this->con->executeQuery(

@ -12,6 +12,9 @@ class GatewayQuestion
public function __construct() public function __construct()
{ {
global $dns, $user, $pass; global $dns, $user, $pass;
if ($dns == NULL || $user == NULL || $pass == NULL) {
require_once(__DIR__ . '/../usages/Config_DB.php');
}
$this->con = new Connection($dns, $user, $pass); $this->con = new Connection($dns, $user, $pass);
} }
@ -36,7 +39,6 @@ class GatewayQuestion
$query = "SELECT * FROM questions WHERE id = :id;"; $query = "SELECT * FROM questions WHERE id = :id;";
$this->con->executeQuery($query, array(':id' => array($id, PDO::PARAM_INT))); $this->con->executeQuery($query, array(':id' => array($id, PDO::PARAM_INT)));
$results = $this->con->getResults(); $results = $this->con->getResults();
return $results[0]; return $results[0];
} }
@ -62,8 +64,8 @@ class GatewayQuestion
); );
} }
public function updateNbFails($question){ public function updateNbFails($question)
// var_dump($question); {
$query = "UPDATE questions SET nbfails = :nbfails WHERE id = :id;"; $query = "UPDATE questions SET nbfails = :nbfails WHERE id = :id;";
$this->con->executeQuery( $this->con->executeQuery(
$query, $query,
@ -74,7 +76,8 @@ class GatewayQuestion
); );
} }
public function updateDifficulty($question){ public function updateDifficulty($question)
{
$query = "UPDATE questions SET difficulty = :difficulty WHERE id = :id;"; $query = "UPDATE questions SET difficulty = :difficulty WHERE id = :id;";
$this->con->executeQuery( $this->con->executeQuery(
$query, $query,
@ -88,7 +91,12 @@ class GatewayQuestion
public function deleteQuestionByID($id) public function deleteQuestionByID($id)
{ {
$query = "DELETE FROM questions WHERE id = :id;"; $query = "DELETE FROM questions WHERE id = :id;";
$this->con->executeQuery($query, array(':id' => array($id, PDO::PARAM_INT))); $this->con->executeQuery(
$query,
array(
':id' => array($id, PDO::PARAM_INT)
)
);
} }
public function getQuestionsByChapterAndDifficulty($idChapter, $difficulty) public function getQuestionsByChapterAndDifficulty($idChapter, $difficulty)

@ -1,92 +0,0 @@
<?php
use PHPUnit\Framework\TestCase;
use controllers\ControllerAdminAdministrators;
final class testAdminAdministrators extends TestCase
{
public function testInstanciation()
{
$controller = new ControllerAdminAdministrators();
$this->expectOutputString('Location:/loginAdmin');
$this->assertInstanceOf(ControllerAdminAdministrators::class, $controller);
}
public function testDelete()
{
$controller = new ControllerAdminAdministrators();
$controller->delete(["id" => 1]);
//$this->expectOutputString('Location:/admin/administrators');
}
public function testAdd()
{
$controller = new ControllerAdminAdministrators();
$_SERVER['REQUEST_METHOD'] = 'POST';
$_POST['username'] = 'test';
$_POST['password'] = 'test';
$controller->add(["id" => 1]);
$this->expectOutputString('Location:/admin/administrators');
$_SERVER['REQUEST_METHOD'] = 'GET';
$controller->add(["id" => 1]);
$this->expectOutputString('Location:/admin/administrators');
$_SERVER['REQUEST_METHOD'] = 'POST';
$_POST['username'] = '';
$_POST['password'] = '';
$controller->add(["id" => 1]);
$this->expectOutputString('Location:/admin/administrators');
$_SERVER['REQUEST_METHOD'] = 'POST';
$_POST['username'] = 'test';
$_POST['password'] = '';
$controller->add(["id" => 1]);
$this->expectOutputString('Location:/admin/administrators');
$_SERVER['REQUEST_METHOD'] = 'POST';
$_POST['username'] = '';
$_POST['password'] = 'test';
$controller->add(["id" => 1]);
$this->expectOutputString('Location:/admin/administrators');
}
public function testUpdateModal()
{
$controller = new ControllerAdminAdministrators();
$controller->updateModal(["id" => 121]);
$this->expectOutputString('Location:/admin/administrators');
}
public function testUpdate()
{
$controller = new ControllerAdminAdministrators();
$_SERVER['REQUEST_METHOD'] = 'POST';
$_POST['username'] = 'test';
$_POST['password'] = 'test';
$controller->update(["id" => 1]);
$this->expectOutputString('Location:/admin/administrators');
$_SERVER['REQUEST_METHOD'] = 'GET';
$controller->update(["id" => 1]);
$this->expectOutputString('Location:/admin/administrators');
$_SERVER['REQUEST_METHOD'] = 'POST';
$_POST['username'] = '';
$_POST['password'] = '';
$controller->update(["id" => 1]);
$this->expectOutputString('Location:/admin/administrators');
$_SERVER['REQUEST_METHOD'] = 'POST';
$_POST['username'] = 'test';
$_POST['password'] = '';
$controller->update(["id" => 1]);
$this->expectOutputString('Location:/admin/administrators');
$_SERVER['REQUEST_METHOD'] = 'POST';
$_POST['username'] = '';
$_POST['password'] = 'test';
$controller->update(["id" => 1]);
$this->expectOutputString('Location:/admin/administrators');
}
}

@ -1,60 +0,0 @@
<?php
use PHPUnit\Framework\TestCase;
use controllers\ControllerAdminChapters;
final class testAdminChapters extends TestCase
{
public function instanciation()
{
$controller = new ControllerAdminChapters();
$this->expectOutputString('Location:/loginAdmin');
$this->assertInstanceOf(ControllerAdminChapters::class, $controller);
}
public function testDelete()
{
$controller = new ControllerAdminChapters();
$controller->delete(["id" => 1]);
$this->expectOutputString('Location:/admin/chapters');
}
public function testAdd()
{
$controller = new ControllerAdminChapters();
$_SERVER['REQUEST_METHOD'] = 'POST';
$_POST['title'] = 'test';
$_POST['content'] = 'test';
$controller->add(["id" => 1]);
$this->expectOutputString('Location:/admin/chapters');
$_SERVER['REQUEST_METHOD'] = 'GET';
$controller->add(["id" => 1]);
$this->expectOutputString('Location:/admin/chapters');
$_SERVER['REQUEST_METHOD'] = 'POST';
$_POST['title'] = '';
$_POST['content'] = '';
$controller->add(["id" => 1]);
$this->expectOutputString('Location:/admin/chapters');
$_SERVER['REQUEST_METHOD'] = 'POST';
$_POST['title'] = 'test';
$_POST['content'] = '';
$controller->add(["id" => 1]);
$this->expectOutputString('Location:/admin/chapters');
$_SERVER['REQUEST_METHOD'] = 'POST';
$_POST['title'] = '';
$_POST['content'] = 'test';
$controller->add(["id" => 1]);
$this->expectOutputString('Location:/admin/chapters');
}
public function testUpdateModal()
{
$controller = new ControllerAdminChapters();
$controller->updateModal(["id" => 121]);
$this->expectOutputString('Location:/admin/chapters');
}
}

@ -1,60 +0,0 @@
<?php
use PHPUnit\Framework\TestCase;
use controllers\ControllerAdminQuestions;
final class testAdminQuestions extends TestCase
{
public function instanciation()
{
$controller = new ControllerAdminQuestions();
$this->expectOutputString('Location:/loginAdmin');
$this->assertInstanceOf(ControllerAdminQuestions::class, $controller);
}
public function testDelete()
{
$controller = new ControllerAdminQuestions();
$controller->delete(["id" => 1]);
$this->expectOutputString('Location:/admin/questions');
}
public function testAdd()
{
$controller = new ControllerAdminQuestions();
$_SERVER['REQUEST_METHOD'] = 'POST';
$_POST['title'] = 'test';
$_POST['content'] = 'test';
$controller->add(["id" => 1]);
$this->expectOutputString('Location:/admin/questions');
$_SERVER['REQUEST_METHOD'] = 'GET';
$controller->add(["id" => 1]);
$this->expectOutputString('Location:/admin/questions');
$_SERVER['REQUEST_METHOD'] = 'POST';
$_POST['title'] = '';
$_POST['content'] = '';
$controller->add(["id" => 1]);
$this->expectOutputString('Location:/admin/questions');
$_SERVER['REQUEST_METHOD'] = 'POST';
$_POST['title'] = 'test';
$_POST['content'] = '';
$controller->add(["id" => 1]);
$this->expectOutputString('Location:/admin/questions');
$_SERVER['REQUEST_METHOD'] = 'POST';
$_POST['title'] = '';
$_POST['content'] = 'test';
$controller->add(["id" => 1]);
$this->expectOutputString('Location:/admin/questions');
}
public function testUpdateModal()
{
$controller = new ControllerAdminQuestions();
$controller->updateModal(["id" => 121]);
$this->expectOutputString('Location:/admin/questions');
}
}

@ -13,13 +13,14 @@ class testAnswers extends TestCase
$gateway = new GatewayAnswer(); $gateway = new GatewayAnswer();
$answer = array( $answer = array(
'content' => 'This is a test answer', 'content' => 'This is a test answer',
'idquestion' => 1 'idquestion' => 2
); );
$answerId = $gateway->addAnswer($answer); $answerId = $gateway->addAnswer($answer);
assertNotEquals($answerId, null); assertNotEquals($answerId, null);
$gateway->deleteAnswer($answerId); $gateway->deleteAnswer($answerId);
$answerId = $gateway->getAnswerByID($answerId); $answerId = $gateway->getAnswerByID($answerId);
assertEquals($answerId, null); assertEquals($answerId, null);
$gateway->deleteAnswer($answerId);
} }
public function testGetAnswerByID() public function testGetAnswerByID()
@ -32,11 +33,11 @@ class testAnswers extends TestCase
public function testGetAnswersByIDQuestions() public function testGetAnswersByIDQuestions()
{ {
$gateway = new GatewayAnswer(); $gateway = new GatewayAnswer();
$answers = $gateway->getAnswersByIDQuestions(1); $answers = $gateway->getAnswersByIDQuestions(2);
assertEquals($answers[0]['content'], '4log_2(1)'); assertEquals($answers[0]['content'], '4');
assertEquals($answers[1]['content'], '1 log_2(4)'); assertEquals($answers[1]['content'], '-4');
assertEquals($answers[2]['content'], '-2'); assertEquals($answers[2]['content'], 'on ne peut pas simplifier');
assertEquals($answers[3]['content'], '{log_2(1)}/{log_2(4)}'); assertEquals($answers[3]['content'], '1');
} }
public function testUpdateAnswer() public function testUpdateAnswer()
@ -44,13 +45,13 @@ class testAnswers extends TestCase
$gateway = new GatewayAnswer(); $gateway = new GatewayAnswer();
$answer = array( $answer = array(
'content' => 'This is a test answer', 'content' => 'This is a test answer',
'idquestion' => 1 'idquestion' => 2
); );
$answerId = $gateway->addAnswer($answer); $answerId = $gateway->addAnswer($answer);
$answer = array( $answer = array(
'id' => $answerId, 'id' => $answerId,
'content' => 'This is a test answer updated', 'content' => 'This is a test answer updated',
'idquestion' => 1 'idquestion' => 2
); );
$gateway->updateAnswer($answerId, $answer); $gateway->updateAnswer($answerId, $answer);
$answer = $gateway->getAnswerByID($answerId); $answer = $gateway->getAnswerByID($answerId);

@ -0,0 +1,105 @@
<?php
use PHPUnit\Framework\TestCase;
use gateways\GatewayJouer;
use gateways\GatewayPlayer;
use gateways\GatewayChapter;
use classes\Player;
use function PHPUnit\Framework\assertEquals;
use function PHPUnit\Framework\assertNotEquals;
class testJouer extends TestCase
{
public function testAddJouer()
{
$playerArray = [];
$playerArray['id'] = 1;
$playerArray['nickname'] = "testUnit";
$playerArray['password'] = "testUnit";
$chapterArray = [];
$chapterArray['id'] = 1;
$chapterArray['name'] = "testUnit";
$gwayChapter = new GatewayChapter();
$gwayPlayer = new GatewayPlayer();
$gatewayAnswer = $gwayPlayer->getPlayerByNickname("testUnit");
if ($gatewayAnswer) {
$gwayPlayer->deletePlayerByID($gatewayAnswer['id']);
}
$gatewayAnswer = $gwayChapter->verifyChapterByName("testUnit");
if ($gatewayAnswer) {
$gwayChapter->deleteChapter($gatewayAnswer['id']);
}
$gwayChapter->addChapter($chapterArray);
$gwayPlayer->addPlayer($playerArray);
$playerFromGWay = $gwayPlayer->getPlayerByNickname("testUnit");
$chapterFromGWay = $gwayChapter->verifyChapterByName("testUnit");
$gway = new GatewayJouer();
$gway->addJouer(
array(
'idchapter' => $chapterFromGWay['id'],
'idplayer' => $playerFromGWay['id'],
'maxscore' => 0
)
);
$maxScore = $gway->getMaxScoreByPlayerAndChapter(
array(
'idchapter' => $chapterFromGWay['id'],
'idplayer' => $playerFromGWay['id']
)
);
assertEquals(0, $maxScore['maxscore']);
$gway->updateJouer(
array(
'idchapter' => $chapterFromGWay['id'],
'idplayer' => $playerFromGWay['id'],
'maxscore' => 10
)
);
$maxScore = $gway->getMaxScoreByPlayerAndChapter(
array(
'idchapter' => $chapterFromGWay['id'],
'idplayer' => $playerFromGWay['id']
)
);
assertEquals(10, $maxScore['maxscore']);
$jouer = $gway->verifyJouer(
array(
'idchapter' => $chapterFromGWay['id'],
'idplayer' => $playerFromGWay['id']
)
);
assertEquals($chapterFromGWay['id'], $jouer['idchapter']);
assertEquals($playerFromGWay['id'], $jouer['idplayer']);
$player = new Player($playerFromGWay['id'], $playerFromGWay['nickname'], "testUnit");
$maxScoreAndChapter = $gway->getMaxScoresWithChapter($player);
assertEquals(10, $maxScoreAndChapter[0]['maxscore']);
assertEquals($chapterFromGWay['id'], $maxScoreAndChapter[0]['idchapter']);
$gway->deleteJouer(
array(
'idchapter' => $chapterFromGWay['id'],
'idplayer' => $playerFromGWay['id']
)
);
$jouer = $gway->verifyJouer(
array(
'idchapter' => $chapterFromGWay['id'],
'idplayer' => $playerFromGWay['id']
)
);
assertEquals(false, $jouer);
$gwayPlayer->deletePlayerByID($playerFromGWay['id']);
$gwayChapter->deleteChapter($chapterFromGWay['id']);
}
}

@ -0,0 +1,64 @@
<?php
use PHPUnit\Framework\TestCase;
use gateways\GatewayLobby;
use classes\Lobby;
use function PHPUnit\Framework\assertEquals;
use function PHPUnit\Framework\assertNotEquals;
class testLobby extends TestCase
{
public function testAddLobby()
{
$lobby = new Lobby(1, "testUnit", "testUnit", 1);
$gateway = new GatewayLobby();
$gateway->deleteLobby($gateway->getLobbyByName("testUnit"));
$gateway->addLobby($lobby);
$lobbyArray = $gateway->getLobbyByName("testUnit");
$lobby2 = new Lobby($lobbyArray['id'], $lobbyArray['name'], $lobbyArray['password'], $lobbyArray['nbplayers']);
assertEquals($lobby->getId(), $lobby2->getId());
assertEquals($lobby->getName(), $lobby2->getName());
assertEquals($lobby->getPassword(), $lobby2->getPassword());
assertEquals($lobby->getNbPlayers(), $lobby2->getNbPlayers());
$gateway->deleteLobby($lobby->getId());
}
public function testGetLobbies()
{
$gateway = new GatewayLobby();
$lobbies = $gateway->getLobbies();
assertNotEquals(0, count($lobbies));
}
public function testGetLobbyByName()
{
$lobby = new Lobby(1, "testUnit", "testUnit", 1);
$gateway = new GatewayLobby();
$gateway->deleteLobby($gateway->getLobbyByName("testUnit"));
$gateway->addLobby($lobby);
$lobbyArray = $gateway->getLobbyByName("testUnit");
$lobby2 = new Lobby(
$lobbyArray['id'],
$lobbyArray['name'],
$lobbyArray['password'],
$lobbyArray['nbplayers']
);
assertEquals($lobby->getId(), $lobby2->getId());
assertEquals($lobby->getName(), $lobby2->getName());
assertEquals($lobby->getPassword(), $lobby2->getPassword());
assertEquals($lobby->getNbPlayers(), $lobby2->getNbPlayers());
$gateway->deleteLobby($lobby->getId());
}
public function testDeleteLobby()
{
$lobby = new Lobby(1, "testUnit", "testUnit", 1);
$gateway = new GatewayLobby();
$gateway->deleteLobby($gateway->getLobbyByName("testUnit"));
$gateway->addLobby($lobby);
$gateway->deleteLobby($lobby->getId());
$lobby2 = $gateway->getLobbyByName("testUnit");
assertEquals(false, $lobby2);
}
}

@ -0,0 +1,72 @@
<?php
use PHPUnit\Framework\TestCase;
use gateways\GatewayPlayer;
use classes\Player;
use function PHPUnit\Framework\assertEquals;
use function PHPUnit\Framework\assertNotEquals;
class testPlayer extends TestCase
{
public function testAddPlayer()
{
$player = [];
$player['id'] = 1;
$player['nickname'] = "testUnit";
$player['password'] = "testUnit";
$gateway = new GatewayPlayer();
$gatewayAnswer = $gateway->getPlayerByNickname("testUnit");
if ($gatewayAnswer) {
$gateway->deletePlayerByID($gatewayAnswer['id']);
}
$gateway->addPlayer($player);
$player2 = $gateway->getPlayerByNickname("testUnit");
assertEquals($player['nickname'], $player2['nickname']);
$gateway->deletePlayerByID($player['id']);
}
public function testGetPlayers()
{
$gateway = new GatewayPlayer();
$players = $gateway->getPlayers();
assertNotEquals(0, count($players));
}
public function testGetPlayerByNickname()
{
$player = [];
$player['id'] = 1;
$player['nickname'] = "testUnit";
$player['password'] = "testUnit";
$gateway = new GatewayPlayer();
$gatewayAnswer = $gateway->getPlayerByNickname("testUnit");
if ($gatewayAnswer) {
$gateway->deletePlayerByID($gatewayAnswer['id']);
}
$gateway->addPlayer($player);
$player2 = $gateway->getPlayerByNickname("testUnit");
assertEquals($player['nickname'], $player2['nickname']);
$gateway->deletePlayerByID($player['id']);
}
public function testDeletePlayer()
{
$player = [];
$player['id'] = 1;
$player['nickname'] = "testUnit";
$player['password'] = "testUnit";
$gateway = new GatewayPlayer();
$gatewayAnswer = $gateway->getPlayerByNickname("testUnit");
if ($gatewayAnswer) {
$gateway->deletePlayerByID($gatewayAnswer['id']);
}
$gateway->addPlayer($player);
$gatewayAnswer = $gateway->getPlayerByNickname("testUnit");
if ($gatewayAnswer) {
$gateway->deletePlayerByID($gatewayAnswer['id']);
}
$player2 = $gateway->getPlayerByNickname("testUnit");
assertEquals(false, $player2);
}
}

@ -0,0 +1,98 @@
<?php
use PHPUnit\Framework\TestCase;
use gateways\GatewayQuestion;
use gateways\GatewayAnswer;
use classes\Question;
use function PHPUnit\Framework\assertEquals;
use function PHPUnit\Framework\assertNotEquals;
class testQuestion extends TestCase
{
public function testQuestions()
{
$question = [];
$question['id'] = 1;
$question['content'] = "test Unit_";
$question['idchapter'] = 1;
$question['difficulty'] = 1;
$question['nbfails'] = 0;
$gateway = new GatewayQuestion();
$lenght = count($gateway->getQuestions());
$lenght2 = count($gateway->getQuestionsByChapterAndDifficulty(1, 1));
$question['id'] = $gateway->addQuestion($question);
$gwayAnswer = new GatewayAnswer();
$answer = array(
'content' => 'This is a test answer',
'idquestion' => $question['id']
);
$answer2 = array(
'content' => 'This is a test answer 2',
'idquestion' => $question['id']
);
$answer3 = array(
'content' => 'This is a test answer 3',
'idquestion' => $question['id']
);
$answer4 = array(
'content' => 'This is a test answer 4',
'idquestion' => $question['id']
);
$answerId1 = $gwayAnswer->addAnswer($answer);
$answerId2 = $gwayAnswer->addAnswer($answer2);
$answerId3 = $gwayAnswer->addAnswer($answer3);
$answerId4 = $gwayAnswer->addAnswer($answer4);
$question['idanswergood'] = $answerId1;
$question2 = $gateway->getQuestionByID($question['id']);
assertEquals($question['content'], $question2['content']);
assertEquals($lenght + 1, count($gateway->getQuestions()));
assertEquals($lenght2 + 1, count($gateway->getQuestionsByChapterAndDifficulty(1, 1)));
$question['content'] = "test Unit 2_";
$gateway->updateQuestion($question['id'], $question);
$question2 = $gateway->getQuestionByID($question['id']);
assertEquals($question['content'], $question2['content']);
$question['difficulty'] = 2;
$questionInstance = new Question(
$question['id'],
$question['content'],
$question['idchapter'],
$question['difficulty'],
$question['nbfails']
);
$questionInstance->setDifficulty($question['difficulty']);
$gateway->updateDifficulty($questionInstance);
$question3 = $gateway->getQuestionByID($question['id']);
assertEquals($question['difficulty'], $question3['difficulty']);
$question['nbfails'] = 1;
$questionInstance = new Question(
$question['id'],
$question['content'],
$question['idchapter'],
$question['difficulty'],
$question['nbfails']
);
$questionInstance->setNbFails($question['nbfails']);
$gateway->updateNbFails($questionInstance);
$question2 = $gateway->getQuestionByID($question['id']);
assertEquals($question['nbfails'], $question2['nbfails']);
$gateway->deleteQuestionByID($question['id']);
assertEquals($lenght, count($gateway->getQuestions()));
$gwayAnswer->deleteAnswer($answerId1);
$gwayAnswer->deleteAnswer($answerId2);
$gwayAnswer->deleteAnswer($answerId3);
$gwayAnswer->deleteAnswer($answerId4);
}
}
Loading…
Cancel
Save