コード例 #1
0
 public function testRegistration()
 {
     $auth = $this->di->get('auth');
     /* Test successful registration */
     $result = $auth->registerUser(array('username' => 'test_1', 'email' => '*****@*****.**', 'password' => 'test_test_test', 'password_confirm' => 'test_test_test'));
     $this->assertEquals(count($result), 0, 'Failures when registering user');
     $user = TestUser::findFirst(array('username = :username:'******'bind' => array('username' => 'test_1')));
     $this->assertNotEquals($user, FALSE, 'Registered user not found in database');
     /* End test */
     /* Test invalid email registration */
     $result = $auth->registerUser(array('username' => 'test_2', 'email' => 'test', 'password' => 'test_test_test', 'password_confirm' => 'test_test_test'));
     $this->assertNotEquals(count($result), 0, 'No failures when registering user, failures expected');
     $user = TestUser::findFirst(array('username = :username:'******'bind' => array('username' => 'test_2')));
     $this->assertEquals($user, FALSE, 'User found in database that should have failed');
     /* End test */
     /* Test different password registration */
     $result = $auth->registerUser(array('username' => 'test_3', 'email' => '*****@*****.**', 'password' => 'some_pass', 'password_confirm' => 'some_other_pass'));
     $this->assertNotEquals(count($result), 0, 'No failures when registering user, failures expected');
     $user = TestUser::findFirst(array('username = :username:'******'bind' => array('username' => 'test_3')));
     $this->assertEquals($user, FALSE, 'User found in database that should have failed');
     /* End test */
     /* Test invalid password registration */
     $result = $auth->registerUser(array('username' => 'test_4', 'email' => '*****@*****.**', 'password' => 'short', 'password_confirm' => 'short'));
     $this->assertNotEquals(count($result), 0, 'No failures when registering user, failures expected');
     $user = TestUser::findFirst(array('username = :username:'******'bind' => array('username' => 'test_4')));
     $this->assertEquals($user, FALSE, 'User found in database that should have failed');
     /* End test */
     /* Test register empty user */
     $result = $auth->registerUser(array('username' => '', 'email' => '', 'password' => '', 'password_confirm' => ''));
     $this->assertNotEquals(count($result), 0, 'No failures when registering, failures expected');
     $user = TestUser::findFirst(array('username = :username:'******'bind' => array('username' => '')));
     $this->assertEquals($user, FALSE, 'User found in database that should have failed');
     /* End test */
 }