You are here

public function AuthcacheP13nTestDefaultRequestHandler::testDefaultRequestHandler in Authenticated User Page Caching (Authcache) 7.2

Test default configuration.

File

modules/authcache_p13n/tests/authcache_p13n.request-handler.test, line 51
Define unit tests for request handler.

Class

AuthcacheP13nTestDefaultRequestHandler
Test cases for default request handler.

Code

public function testDefaultRequestHandler() {
  $filters = array();
  $context_providers = array();
  $params = array(
    'some' => 'args',
  );

  // Setup expectations.
  $validate = $this->stubObserver
    ->method($this->requestValidator, 'validate', $params + array(
    'valid' => TRUE,
  ))
    ->expect(AuthcacheP13nTestStubVerifyer::once())
    ->expect(AuthcacheP13nTestStubVerifyer::args(array(
    $params,
  )));
  $build = $this->stubObserver
    ->method($this->contentBuilder, 'build', 'output built successfully')
    ->expect(AuthcacheP13nTestStubVerifyer::once())
    ->expect(AuthcacheP13nTestStubVerifyer::args(array(
    $params + array(
      'valid' => TRUE,
    ),
    array(),
  )));
  $content_type = $this->stubObserver
    ->method($this->contentEncoder, 'contentType', 'application/test')
    ->expect(AuthcacheP13nTestStubVerifyer::once())
    ->expect(AuthcacheP13nTestStubVerifyer::args());
  $encode = $this->stubObserver
    ->method($this->contentEncoder, 'encode', 'encoded successfully')
    ->expect(AuthcacheP13nTestStubVerifyer::once())
    ->expect(AuthcacheP13nTestStubVerifyer::args(array(
    'output built successfully',
  )));
  $add_header = $this->stubObserver
    ->method($this->coreService, 'drupalAddHttpHeader')
    ->expect(AuthcacheP13nTestStubVerifyer::once())
    ->expect(AuthcacheP13nTestStubVerifyer::args(array(
    'Content-Type',
    'application/test',
  )));

  // Run handler, test full sequence without filters / context providers /
  $handler = new AuthcacheP13nDefaultRequestHandler($this->coreService, $this->requestValidator, $this->contentBuilder, $this->contentEncoder, $filters, $context_providers);
  ob_start();
  $handler
    ->handle($params);
  $result = ob_get_clean();
  $this
    ->assertEqual('encoded successfully', $result);

  // Verify stubs.
  $this
    ->assert($add_header
    ->verify($message), $message);
  $this
    ->assert($validate
    ->verify($message), $message);
  $this
    ->assert($build
    ->verify($message), $message);
  $this
    ->assert($content_type
    ->verify($message), $message);
  $this
    ->assert($encode
    ->verify($message), $message);
}