From 7e971c514dffe04bce09be8c6891060a0cc95e8c Mon Sep 17 00:00:00 2001 From: "damien.nortier" Date: Fri, 17 Nov 2023 14:14:02 +0100 Subject: [PATCH] tests unitaires (pour les classes uniquement) --- Website/class/Administrator.php | 0 Website/class/Answer.php | 12 +++- Website/class/Chapter.php | 8 ++- Website/class/Lobby.php | 16 +++++ Website/class/Player.php | 0 Website/class/Question.php | 0 testUnit/testUnitaireAdministrator.php | 19 ++++++ testUnit/testUnitaireAnswer.php | 34 +++++++++++ testUnit/testUnitaireChapter.php | 19 ++++++ testUnit/testUnitaireLobby.php | 85 ++++++++++++++++++++++++++ testUnit/testUnitairePlayer.php | 19 ++++++ testUnit/testUnitaireQuestion.php | 72 ++++++++++++++++++++++ testUnit/testsUnitaires.php | 8 +++ 13 files changed, 288 insertions(+), 4 deletions(-) mode change 100644 => 100755 Website/class/Administrator.php mode change 100644 => 100755 Website/class/Answer.php mode change 100644 => 100755 Website/class/Chapter.php mode change 100644 => 100755 Website/class/Player.php mode change 100644 => 100755 Website/class/Question.php create mode 100755 testUnit/testUnitaireAdministrator.php create mode 100755 testUnit/testUnitaireAnswer.php create mode 100755 testUnit/testUnitaireChapter.php create mode 100755 testUnit/testUnitaireLobby.php create mode 100755 testUnit/testUnitairePlayer.php create mode 100755 testUnit/testUnitaireQuestion.php create mode 100755 testUnit/testsUnitaires.php diff --git a/Website/class/Administrator.php b/Website/class/Administrator.php old mode 100644 new mode 100755 diff --git a/Website/class/Answer.php b/Website/class/Answer.php old mode 100644 new mode 100755 index 518beba..927cdad --- a/Website/class/Answer.php +++ b/Website/class/Answer.php @@ -6,15 +6,16 @@ class Answer private string $content; private int $idQuestion; - public function __construct(string $content, int $idQuestion) + public function __construct(int $id, string $content, int $idQuestion) { + $this->id = $id; $this->content = $content; $this->idQuestion = $idQuestion; } - public function getContent() + public function getId() { - return $this->content; + return $this->id; } public function getIdQuestion() @@ -22,6 +23,11 @@ class Answer return $this->idQuestion; } + public function getContent() + { + return $this->content; + } + public function setContent(string $content) { $this->content = $content; diff --git a/Website/class/Chapter.php b/Website/class/Chapter.php old mode 100644 new mode 100755 index ac2dec0..f936a68 --- a/Website/class/Chapter.php +++ b/Website/class/Chapter.php @@ -5,8 +5,9 @@ class Chapter private int $id; private string $name; - public function __construct(string $name) + public function __construct(int $id, string $name) { + $this->id = $id; $this->name = $name; } @@ -14,4 +15,9 @@ class Chapter { return $this->name; } + + public function idEqual(int $id) + { + return $this->id == $id ; + } } diff --git a/Website/class/Lobby.php b/Website/class/Lobby.php index 66736e8..e384718 100755 --- a/Website/class/Lobby.php +++ b/Website/class/Lobby.php @@ -24,11 +24,27 @@ class Lobby { return $this->nbPlayer; } + public function setNbplayer(int $nbPlayer) { $this->nbPlayer = $nbPlayer; } + public function addPlayer(int $number) + { + $this->nbPlayer = $this->nbPlayer + $number ; + } + + public function removePlayer(int $number) + { + $this->nbPlayer = $this->nbPlayer - $number ; + } + + public function getPassword() + { + return $this->password; + } + public function idEqual($idTest) { return $this->id == $idTest ; diff --git a/Website/class/Player.php b/Website/class/Player.php old mode 100644 new mode 100755 diff --git a/Website/class/Question.php b/Website/class/Question.php old mode 100644 new mode 100755 diff --git a/testUnit/testUnitaireAdministrator.php b/testUnit/testUnitaireAdministrator.php new file mode 100755 index 0000000..35c55ae --- /dev/null +++ b/testUnit/testUnitaireAdministrator.php @@ -0,0 +1,19 @@ +test administrator
") ; + $player = new Administrator("Damien", "Nortier") ; + print("test getUsername.. ") ; + if($player->getUsername() == "Damien"){ + print("OK
") ; + } + else{ + print("ERREUR
") ; + } + print("test getHashedPassword.. ") ; + if($player->getHashedPassword() == md5("Nortier")){ + print("OK
") ; + } + else{ + print("ERREUR
") ; + } +?> diff --git a/testUnit/testUnitaireAnswer.php b/testUnit/testUnitaireAnswer.php new file mode 100755 index 0000000..08db97c --- /dev/null +++ b/testUnit/testUnitaireAnswer.php @@ -0,0 +1,34 @@ +test answer
") ; + $answer = new Answer(2, "Damien", 5) ; + print("test getId.. ") ; + if($answer->getId() == 2){ + print("OK
") ; + } + else{ + print("ERREUR
") ; + } + print("test getContent.. ") ; + if($answer->getContent() == "Damien"){ + print("OK
") ; + } + else{ + print("ERREUR
") ; + } + print("test setContent.. ") ; + $answer->setContent("Nortier") ; + if($answer->getContent() == "Nortier"){ + print("OK
") ; + } + else{ + print("ERREUR
") ; + } + print("test getidQuestion.. ") ; + if($answer->getidQuestion() == 5){ + print("OK
") ; + } + else{ + print("ERREUR
") ; + } +?> \ No newline at end of file diff --git a/testUnit/testUnitaireChapter.php b/testUnit/testUnitaireChapter.php new file mode 100755 index 0000000..ebe9237 --- /dev/null +++ b/testUnit/testUnitaireChapter.php @@ -0,0 +1,19 @@ +test chapter
") ; + $chapter = new Chapter(2, "Damien") ; + print("test getName.. ") ; + if($chapter->getName() == "Damien"){ + print("OK
") ; + } + else{ + print("ERREUR
") ; + } + print("test idEqual.. ") ; + if($chapter->idEqual(2) && !$chapter->idEqual(5)){ + print("OK
") ; + } + else{ + print("ERREUR
") ; + } +?> diff --git a/testUnit/testUnitaireLobby.php b/testUnit/testUnitaireLobby.php new file mode 100755 index 0000000..e78e219 --- /dev/null +++ b/testUnit/testUnitaireLobby.php @@ -0,0 +1,85 @@ +test lobby
") ; + $lobby = new Lobby(2, "Damien", "Nortier", 5) ; + print("test getName.. ") ; + if($lobby->getName() == "Damien"){ + print("OK
") ; + } + else{ + print("ERREUR
") ; + } + print("test getPassword.. ") ; + if($lobby->getPassword() == "Nortier"){ + print("OK
") ; + } + else{ + print("ERREUR
") ; + } + print("test idEqual.. ") ; + if($lobby->idEqual(2) && !$lobby->idEqual(1)){ + print("OK
") ; + } + else{ + print("ERREUR
") ; + } + print("test getNbPlayer.. ") ; + if($lobby->getNbPlayer() == 5){ + print("OK
") ; + } + else{ + print("ERREUR
") ; + } + print("test setNbPlayer.. ") ; + $lobby->setNbPlayer(3) ; + if($lobby->getNbPlayer() == 3){ + print("OK
") ; + } + else{ + print("ERREUR
") ; + } + print("test addPlayer... ") ; + $lobby->addPlayer(3) ; + if($lobby->getNbPlayer() == 6){ + print("1) OK ") ; + } + else{ + print("1) ERREUR ") ; + } + $lobby->addPlayer(1) ; + if($lobby->getNbPlayer() == 7){ + print("2) OK
") ; + } + else{ + print("2) ERREUR
") ; + } + print("test removePlayer... ") ; + $lobby->removePlayer(2) ; + if($lobby->getNbPlayer() == 5){ + print("1) OK ") ; + } + else{ + print("1) ERREUR ") ; + } + $lobby->removePlayer(4) ; + if($lobby->getNbPlayer() == 1){ + print("2) OK
") ; + } + else{ + print("2) ERREUR
") ; + } + print("test getPassword... ") ; + if($lobby->getPassword() == "Nortier"){ + print("OK
") ; + } + else{ + print("ERREUR
") ; + } + print("test getPassword... ") ; + if($lobby->idEqual(2) && !$lobby->idEqual(4)){ + print("OK
") ; + } + else{ + print("ERREUR
") ; + } +?> diff --git a/testUnit/testUnitairePlayer.php b/testUnit/testUnitairePlayer.php new file mode 100755 index 0000000..daf25db --- /dev/null +++ b/testUnit/testUnitairePlayer.php @@ -0,0 +1,19 @@ +test player
") ; + $player = new Player(2, "Damien", "Nortier") ; + print("test getNickname.. ") ; + if($player->getNickname() == "Damien"){ + print("OK
") ; + } + else{ + print("ERREUR
") ; + } + print("test getHashedPassword.. ") ; + if($player->getHashedPassword() == md5("Nortier")){ + print("OK
") ; + } + else{ + print("ERREUR
") ; + } +?> diff --git a/testUnit/testUnitaireQuestion.php b/testUnit/testUnitaireQuestion.php new file mode 100755 index 0000000..1a4551e --- /dev/null +++ b/testUnit/testUnitaireQuestion.php @@ -0,0 +1,72 @@ +test question
") ; + $question = new Question("Damien Nortier", 24, 12, 3, 1) ; + print("test getContent.. ") ; + if($question->getContent() == "Damien Nortier"){ + print("OK
") ; + } + else{ + print("ERREUR
") ; + } + print("test getIdChapter.. ") ; + if($question->getIdChapter() == 24){ + print("OK
") ; + } + else{ + print("ERREUR
") ; + } + print("test getIdAnswerGood.. ") ; + if($question->getIdAnswerGood() == 12){ + print("OK
") ; + } + else{ + print("ERREUR
") ; + } + print("test setContent.. ") ; + $question->setContent("contenu") ; + if($question->getContent() == "contenu"){ + print("OK
") ; + } + else{ + print("ERREUR
") ; + } + print("test setIdAnswerGood.. ") ; + $question->setIdAnswerGood(1) ; + if($question->getIdAnswerGood() == 1){ + print("OK
") ; + } + else{ + print("ERREUR
") ; + } + print("test getDifficulty.. ") ; + if($question->getDifficulty() == 3){ + print("OK
") ; + } + else{ + print("ERREUR
") ; + } + print("test setDifficulty.. ") ; + $question->setDifficulty(24) ; + if($question->getDifficulty() == 24){ + print("OK
") ; + } + else{ + print("ERREUR
") ; + } + print("test getNbFails.. ") ; + if($question->getNbFails() == 1){ + print("OK
") ; + } + else{ + print("ERREUR
") ; + } + print("test setNbFails.. ") ; + $question->setNbFails(13) ; + if($question->getNbFails() == 13){ + print("OK
") ; + } + else{ + print("ERREUR
") ; + } +?> diff --git a/testUnit/testsUnitaires.php b/testUnit/testsUnitaires.php new file mode 100755 index 0000000..449d057 --- /dev/null +++ b/testUnit/testsUnitaires.php @@ -0,0 +1,8 @@ +