Compare commits
2 Commits
281672739a
...
494133a76c
Author | SHA1 | Date |
---|---|---|
![]() |
494133a76c | 1 year ago |
![]() |
0d189081ee | 1 year ago |
@ -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');
|
||||
}
|
||||
}
|
@ -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…
Reference in new issue