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); $this->expectExceptionCode(400); $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); $this->expectExceptionCode(400); $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()); } public function testUserLogin3() { $ctrl = static::getCtrl(); $loginDbo = new LuUsersLoginDbo(); $loginDbo->setUsername("azertyuiop"); $loginDbo->setPassword("azertyuiop"); $this->expectException(LuBusinessException::class); $this->expectExceptionCode(401); $ctrl->login($loginDbo); } public function testUserGetMe1() { $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()); /** * @var $user LuUsersDbo */ $user = LuUsersBusiness::getById($loginResult->getId()); $me = $ctrl->getMe($user); $this->assertSame("test.user1@example.com", $me->getEmail()); $this->assertSame("_test_user1", $user->getUsername()); } public function testUserGetById1() { $ctrl = static::getCtrl(); $user = LuUsersBusiness::getByUsernameOrEmail("test.user1@example.com"); $user = $ctrl->getById($user->getId()); $this->assertSame("test.user1@example.com", $user->getEmail()); $this->assertSame("_test_user1", $user->getUsername()); } public function testUserGetById2() { $ctrl = static::getCtrl(); $user = LuUsersBusiness::getByUsernameOrEmail("_test_user2"); $user = $ctrl->getById($user->getId()); $this->assertSame("test.user2@example.com", $user->getEmail()); $this->assertSame("_test_user2", $user->getUsername()); } public function testUserEditMe1() { $ctrl = static::getCtrl(); $user = LuUsersBusiness::getByUsernameOrEmail("_test_user2"); $edited = new LuUsersEditDbo(); $edited->setEmail("test.user2+edited@example.com"); $edited->setFirstname("test-edited"); $edited->setLastname("user2-edited"); $ctrl->editMe($user, $edited); $editedUser = $ctrl->getById($user->getId()); $this->assertSame("test.user2+edited@example.com", $editedUser->getEmail()); $this->assertSame("test-edited", $editedUser->getFirstname()); $this->assertSame("user2-edited", $editedUser->getLastname()); } public function testUserEdit1() { $ctrl = static::getCtrl(); $user = LuUsersBusiness::getByUsernameOrEmail("_test_user2"); $edited = new LuUsersEditDbo(); $edited->setEmail("test.user2@example.com"); $edited->setFirstname("test"); $edited->setLastname("user2"); $ctrl->edit($user->getId(), $edited); $editedUser = $ctrl->getById($user->getId()); $this->assertSame("test.user2@example.com", $editedUser->getEmail()); $this->assertSame("test", $editedUser->getFirstname()); $this->assertSame("user2", $editedUser->getLastname()); } public function testUserDelete1() { //TODO // $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()); // // $user = LuUsersBusiness::getByUsernameOrEmail("test.user2@example.com"); // // $user = $ctrl->getById($user->getId()); // // $this->assertSame("test.user2@example.com", $user->getEmail()); // $this->assertSame("_test_user2", $user->getUsername()); } }