public function testModifyFailures()
{
// We add a new user that isn't the current user and now perform operations.
$this->addNewUser($this->getApp(), 'editor', 'Editor', 'editor');
// Now we mock the CSRF token to validate
$csrf = $this->getMockCsrfTokenManager();
$csrf->expects($this->any())->method('isTokenValid')->will($this->returnValue(true));
$this->setService('csrf', $csrf);
$users = $this->getMockUsers(['setEnabled', 'deleteUser']);
$users->expects($this->any())->method('setEnabled')->will($this->returnValue(false));
$users->expects($this->any())->method('deleteUser')->will($this->returnValue(false));
$this->setService('users', $users);
// Setup the current user
$user = $this->getService('users')->getUser(1);
$this->setSessionUser(new Entity\Users($user));
// This mocks a failure and ensures the error is reported
$this->setRequest(Request::create('/bolt/user/disable/2'));
$response = $this->controller()->modify('disable', 2);
$info = $this->getFlashBag()->get('info');
$this->assertRegExp('/could not be disabled/', $info[0]);
$this->assertEquals('/bolt/users', $response->getTargetUrl());
$this->setRequest(Request::create('/bolt/user/enable/2'));
$response = $this->controller()->modify('enable', 2);
$info = $this->getFlashBag()->get('info');
$this->assertRegExp('/could not be enabled/', $info[0]);
$this->assertEquals('/bolt/users', $response->getTargetUrl());
$this->setRequest(Request::create('/bolt/user/delete/2'));
$response = $this->controller()->modify('delete', 2);
$info = $this->getFlashBag()->get('info');
$this->assertRegExp('/could not be deleted/', $info[0]);
$this->assertEquals('/bolt/users', $response->getTargetUrl());
}