public function testEdit()
{
$user = $this->getService('users')->getUser(1);
$this->setSessionUser(new Entity\Users($user));
$this->setRequest(Request::create('/bolt/useredit/1'));
// This one should redirect because of permission failure
$response = $this->controller()->edit($this->getRequest(), 1);
$this->assertEquals('/bolt/users', $response->getTargetUrl());
// Now we allow the permsission check to return true
$perms = $this->getMockPermissions();
$perms->expects($this->any())->method('isAllowedToManipulate')->will($this->returnValue(true));
$this->setService('permissions', $perms);
$response = $this->controller()->edit($this->getRequest(), 1);
$context = $response->getContext();
$this->assertEquals('edit', $context['context']['kind']);
$this->assertInstanceOf('Symfony\\Component\\Form\\FormView', $context['context']['form']);
$this->assertEquals('Admin', $context['context']['displayname']);
// Test that an empty user gives a create form
$this->setRequest(Request::create('/bolt/useredit'));
$response = $this->controller()->edit($this->getRequest(), null);
$context = $response->getContext();
$this->assertEquals('create', $context['context']['kind']);
}