From 3c8594d73c9a66cc22c0857aeb6bd97f26605774 Mon Sep 17 00:00:00 2001 From: Paul Date: Tue, 21 Nov 2023 15:31:52 +0100 Subject: [PATCH] Ajout tests user --- Sources/tests/units/model/UserTest.php | 115 +++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 Sources/tests/units/model/UserTest.php diff --git a/Sources/tests/units/model/UserTest.php b/Sources/tests/units/model/UserTest.php new file mode 100644 index 00000000..9ddfb11a --- /dev/null +++ b/Sources/tests/units/model/UserTest.php @@ -0,0 +1,115 @@ +assertSame(1, $user->getId()); + $this->assertSame('John', $user->getNom()); + $this->assertSame('Doe', $user->getPrenom()); + $this->assertSame('john@example.com', $user->getEmail()); + $this->assertSame('hashed_password', $user->getMotDePasse()); + $this->assertSame('M', $user->getSexe()); + $this->assertSame(1.80, $user->getTaille()); + $this->assertSame(75.0, $user->getPoids()); + $this->assertInstanceOf(\DateTime::class, $user->getDateNaissance()); + $this->assertSame($role, $user->getRole()); + + // Test setters + $user->setId(2); + $this->assertSame(2, $user->getId()); + + $user->setNom('Jane'); + $this->assertSame('Jane', $user->getNom()); + + $user->setPrenom('Doe'); + $this->assertSame('Doe', $user->getPrenom()); + + $user->setEmail('jane@example.com'); + $this->assertSame('jane@example.com', $user->getEmail()); + + $user->setMotDePasse('new_hashed_password'); + $this->assertSame('new_hashed_password', $user->getMotDePasse()); + + $user->setSexe('F'); + $this->assertSame('F', $user->getSexe()); + + $user->setTaille(1.60); + $this->assertSame(1.60, $user->getTaille()); + + $user->setPoids(60.0); + $this->assertSame(60.0, $user->getPoids()); + + $newDateNaissance = new \DateTime('1995-01-01'); + $user->setDateNaissance($newDateNaissance); + $this->assertSame($newDateNaissance, $user->getDateNaissance()); + + $newRole = new Athlete(); + $user->setRole($newRole); + $this->assertSame($newRole, $user->getRole()); + } + + public function testIsValidPassword() + { + $role = new Coach(); + + $user = new User( + 1, + 'John', + 'Doe', + 'john@example.com', + 'test123', + 'H', + 1.80, + 75.0, + new \DateTime('1990-01-01'), + $role + ); + + // Assuming the hashed password is 'hashed_password' + $this->assertTrue($user->isValidPassword('test123')); + $this->assertFalse($user->isValidPassword('test1234')); + } + + public function testToString() + { + $role = new Coach(); + + $user = new User( + 1, + 'John', + 'Doe', + 'john@example.com', + 'hashed_password', + 'M', + 1.80, + 75.0, + new \DateTime('1990-01-01'), + $role + ); + + $expectedString = "Athlete [ID: 1, Nom: John, Prénom: Doe, Email: john@example.com]"; + $this->assertSame($expectedString, (string)$user); + } +}