Esempio n. 1
0
 public function testDeleteRole()
 {
     $role = Woodling::saved('Role');
     $response = $this->call('DELETE', '/api/roles/' . $role->id);
     $data = $this->assertResponse($response);
     $id = DB::table('roles')->where('id', $role->id)->pluck('id');
     $this->assertEmpty($id);
 }
 public function testAuthedUpdateOwnUserImageWithExistingImageSetToEmpty()
 {
     $user = $this->helperCreateUserAndLogin();
     $upload = Woodling::saved('Upload', ['user_id' => $user->id]);
     $user->image = $upload->id;
     $user->updateUniques();
     $response = $this->call('PUT', '/api/users/' . $user->id, ['image' => null]);
     $data = $this->assertResponse($response);
     $this->assertEmpty($data->image);
 }
Esempio n. 3
0
 public function testLogoutCurrentUserReturnsGuestUserObject()
 {
     $user = Woodling::saved('User');
     $response = $this->call('POST', '/api/auth', ['username' => $user->email, 'password' => 'password']);
     $response = $this->call('DELETE', '/api/auth/me');
     $data = $this->assertResponse($response);
     $response = $this->call('GET', '/api/auth/me');
     $data = $this->assertResponse($response);
     $this->assertEmpty($data->id);
     $this->assertEquals('guest', $data->username);
 }
Esempio n. 4
0
 public function helperCreateUserAndLogin($roleName = null)
 {
     // If role doesn't exist, create it
     if ($roleName && !($roleId = DB::table('roles')->where('name', $roleName)->pluck('id'))) {
         $role = new Role();
         $role->name = $roleName;
         $role->save();
         $roleId = $role->id;
     }
     // Create test user
     $user = Woodling::saved('User');
     if ($roleName) {
         $user->roles()->sync([$roleId]);
     }
     Auth::login($user);
     return $user;
 }
 public function testStaticSavedWithOverrides()
 {
     $name = 'User';
     $overrides = array('name' => 'Mindaugas Bujanauskas');
     $returnValue = 'Object';
     $coreMock = $this->getMock('Woodling\\Core', array('saved'));
     $coreMock->expects($this->once())->method('saved')->with($this->equalTo($name), $this->arrayHasKey('name'))->will($this->returnValue($returnValue));
     Woodling::core($coreMock);
     Woodling::saved($name, $overrides);
 }
 public function testAdminDeleteUserCleansAssignedRoles()
 {
     $admin = $this->helperCreateUserAndLogin('admin');
     $user = Woodling::saved('User');
     $roles = Woodling::savedList('Role', 3);
     $this->call('PUT', '/api/users/' . $user->id, ['roles' => $roles]);
     $response = $this->call('DELETE', '/api/users/' . $user->id);
     $assigned = DB::table('assigned_roles')->where('user_id', $user->id)->get();
     $this->assertEquals(0, count($assigned));
 }
Esempio n. 7
0
 public function testResetPasswordInvalidPassword()
 {
     $user = Woodling::saved('User');
     $response = $this->call('POST', '/api/users/forgot', ['email' => $user->email]);
     $data = $this->assertResponse($response);
     $token = DB::table('password_reminders')->where('email', $user->email)->pluck('token');
     $response = $this->call('POST', '/api/users/reset', ['token' => $token, 'password' => 'newpassword', 'password_confirmation' => 'foobar']);
     $data = $this->assertResponse($response, 400);
 }