public function setUp() { parent::setUp(); $this->imageService = new ImageService(); $this->userService = new UserService(); $this->commentService = new CommentService(); for ($i = 0; $i < 5; $i++) { $this->commentUserPool[] = $this->userService->createUser($this->faker->userName, $this->faker->name(), $this->faker->password, $this->faker->safeEmail); } }
public function testRegisterRejectUserExists() { $userService = new UserService(); $name = $this->faker->userName; $password = $this->faker->password; $collisionUser = $userService->createUser($name, $name, $name, "{$name}@example.org"); $registerDo = $this->doRequest("POST", "/register", ["username" => $name, "realname" => $this->faker->name(), "password" => $password, "password2" => $password, "email" => $this->faker->safeEmail]); $collisionUser->delete(); $this->assertEquals(302, $registerDo->getStatus()); $this->assertEquals("/register?failed=Username+in+use.", $registerDo->header("location")); }
public function doRegister() { if ($this->slim->request()->post('password') !== $this->slim->request()->post('password2')) { $this->slim->response()->redirect("/register?failed=" . urlencode("Passwords do not match")); } elseif (Models\User::search()->where('username', $this->slim->request()->post('username'))->count() > 0) { $this->slim->response()->redirect("/register?failed=" . urlencode("Username in use.")); } elseif (strlen($this->slim->request()->post('password')) < 6) { $this->slim->response()->redirect("/register?failed=" . urlencode("Password has to be atleast 6 characters")); } elseif (!filter_var($this->slim->request()->post('email'), FILTER_VALIDATE_EMAIL)) { $this->slim->response()->redirect("/register?failed=" . urlencode("Email address invalid")); } else { $userService = new UserService(); $user = $userService->createUser($this->slim->request()->post('username'), $this->slim->request()->post('realname'), $this->slim->request()->post('password'), $this->slim->request()->post('email')); Session::set("user", $user); $this->slim->response()->redirect("/dashboard"); } }
public function testDoLogin() { $this->assertTrue($this->userService->doLogin($this->testUser->username, $this->testUserPassword)); $this->assertTrue($this->userService->doLogin($this->testUser->email, $this->testUserPassword)); $this->assertFalse($this->userService->doLogin($this->testUser->username, "bogus")); $this->assertFalse($this->userService->doLogin($this->testUser->email, "bogus")); $this->assertFalse($this->userService->doLogin("bogus", $this->testUserPassword)); }
public function testImageUserRelation() { $userService = new UserService(); $user = $userService->createUser("test", "test", "test", "*****@*****.**"); /** * @var Image $image */ $image = new Image(); $image->user_id = $user->user_id; $this->assertTrue($image->getUser() instanceof User); $this->assertEquals($image->user_id, $image->getUser()->user_id); $user->delete(); }
public function testImageUserRelation() { $userService = new UserService(); $user = $userService->createUser($this->faker->userName, $this->faker->name(), "passwordlonger", "{$this->faker->userName}@example.com"); /** * @var Image $image */ $image = new Image(); $image->user_id = $user->user_id; $this->assertTrue($image->getUser() instanceof User); $this->assertEquals($image->user_id, $image->getUser()->user_id); $user->delete(); }
/** * @expectedException \TigerKit\TigerException * @expectedExceptionMessage notvalid is not a valid email address. */ public function testEmailInValid() { $this->assertTrue($this->userService->createUser($this->faker->userName, $this->faker->name(), $this->faker->password, "notvalid") instanceof Models\User); }