query("DELETE FROM lu_users WHERE username LIKE '_test_%'"); } public static function tearDownAfterClass() { static::setUpBeforeClass(); } public function testUserAdd1() { $ctrl = static::getCtrl(); $newUser = new LuUsersAddDbo(); $newUser->setUsername("_test_user1"); $newUser->setPassword("test42"); $newUser->setFirstname("Test"); $newUser->setLastname("user1"); $newUser->setEmail("test.user1@example.com"); $newUser->setExternalAuth(null); $newUser->setProfileId(null); $user = $ctrl->add($newUser); $this->assertNotNull($user); $this->assertNotNull($user->getId()); $this->assertSame("_test_user1", $user->getUsername()); $this->assertSame("Test", $user->getFirstname()); $this->assertSame("user1", $user->getLastname()); $this->assertSame("test.user1@example.com", $user->getEmail()); $this->assertNull($user->getExternalAuth()); $this->assertNull($user->getProfileId()); } public function testUserAdd2() { $ctrl = static::getCtrl(); $newUser = new LuUsersAddDbo(); $newUser->setUsername("_test_user1"); $newUser->setPassword("test42"); $newUser->setFirstname("Test"); $newUser->setLastname("user1"); $newUser->setEmail("test.user1@example.com"); $newUser->setExternalAuth(null); $newUser->setProfileId(null); $this->expectException(LuBusinessException::class); $ctrl->add($newUser); } public function testUserAdd3() { $ctrl = static::getCtrl(); $newUser = new LuUsersAddDbo(); $newUser->setUsername("_test_user2"); $newUser->setPassword("test42"); $newUser->setFirstname("Test"); $newUser->setLastname("user1"); $newUser->setEmail("test.user1@example.com"); $newUser->setExternalAuth(null); $newUser->setProfileId(null); $this->expectException(LuBusinessException::class); $ctrl->add($newUser); } public function testUserAdd4() { $ctrl = static::getCtrl(); $newUser = new LuUsersAddDbo(); $newUser->setUsername("_test_user2"); $newUser->setPassword("test24"); $newUser->setFirstname("Test"); $newUser->setLastname("user2"); $newUser->setEmail("test.user2@example.com"); $newUser->setExternalAuth(null); $newUser->setProfileId(null); $user = $ctrl->add($newUser); $this->assertNotNull($user); $this->assertNotNull($user->getId()); $this->assertSame("_test_user2", $user->getUsername()); $this->assertSame("Test", $user->getFirstname()); $this->assertSame("user2", $user->getLastname()); $this->assertSame("test.user2@example.com", $user->getEmail()); $this->assertNull($user->getExternalAuth()); $this->assertNull($user->getProfileId()); } public function testUserLogin1() { $ctrl = static::getCtrl(); $loginDbo = new LuUsersLoginDbo(); $loginDbo->setUsername("_test_user1"); $loginDbo->setPassword("test42"); $loginResult = $ctrl->login($loginDbo); $this->assertNotNull($loginResult); $this->assertSame("test.user1@example.com", $loginResult->getEmail()); $loggedUser = LuUsersBusiness::getUserFromToken($loginResult->getToken()); $this->assertSame("test.user1@example.com", $loggedUser->getEmail()); } public function testUserLogin2() { $ctrl = static::getCtrl(); $loginDbo = new LuUsersLoginDbo(); $loginDbo->setUsername("_test_user2"); $loginDbo->setPassword("test24"); $loginResult = $ctrl->login($loginDbo); $this->assertNotNull($loginResult); $this->assertSame("test.user2@example.com", $loginResult->getEmail()); $loggedUser = LuUsersBusiness::getUserFromToken($loginResult->getToken()); $this->assertSame("test.user2@example.com", $loggedUser->getEmail()); } }