eZ\Publish\Core\REST\Server\Authenticator\IntegrationTest::authenticate PHP Method

authenticate() public method

Performs an authentication based on the given $request and sets the authenticated user into the $repository. Returns true on success, false of authentication was not possible or did not succeed.
public authenticate ( Qafoo\RMF\Request $request ) : boolean
$request Qafoo\RMF\Request
return boolean
    public function authenticate(RMF\Request $request)
    {
        try {
            $this->repository->setCurrentUser($this->repository->getUserService()->loadUser($request->testUser));
        } catch (InvalidArgumentException $e) {
            throw new RuntimeException('The Integration Test Authenticator requires a test user ID to be set using the HTTP Header X-Test-User.');
        }
    }

Usage Example

 public function testAuthenticate()
 {
     $auth = new IntegrationTest($this->getRepositoryMock());
     $this->getUserServiceMock()->expects($this->once())->method('loadUser')->with(23)->will($this->returnValue($user = $this->getMock('eZ\\Publish\\API\\Repository\\Values\\User\\User')));
     $this->getRepositoryMock()->expects($this->once())->method('setCurrentUser')->with($user);
     $request = new RMF\Request();
     $request->testUser = 23;
     $auth->authenticate($request);
 }