You are here

public function AuthcacheP13nTestFragmentBuilder::testFragmentBuilderValidation in Authenticated User Page Caching (Authcache) 7.2

Test request with validator.

File

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

Class

AuthcacheP13nTestFragmentBuilder
Tests fragment builder.

Code

public function testFragmentBuilderValidation() {
  $builder = new AuthcacheP13nFragmentBuilder($this->fragmentRenderer, $this->fragmentValidator, NULL, NULL);

  // Setup expectations.
  $validator = $this->stubObserver
    ->method($this->fragmentValidator, 'validate', array(
    'some_key' => 'valid value',
  ))
    ->expect(AuthcacheP13nTestStubVerifyer::once())
    ->expect(AuthcacheP13nTestStubVerifyer::args(array(
    array(
      'some_key' => 'some_key',
    ),
  )));

  // Run validator.
  $result = $builder
    ->validate(array(
    'a' => 'some_key',
  ));

  // Verify stub.
  $this
    ->assertEqual(array(
    'a' => array(
      'some_key' => 'valid value',
    ),
  ), $result);
  $this
    ->assert($validator
    ->verify($message), $message);

  // Setup expectations.
  $validator = $this->stubObserver
    ->method($this->fragmentValidator, 'validate', new AuthcacheP13nRequestInvalidInput())
    ->expect(AuthcacheP13nTestStubVerifyer::once());

  // Run validator.
  $input = array(
    'a' => 'invalid',
  );
  try {
    $builder
      ->validate($input);
    $this
      ->fail('AuthcacheP13nFragmentBuilder should throw an AuthcacheP13nRequestInvalidInput when validation fails');
  } catch (AuthcacheP13nRequestInvalidInput $e) {
    unset($e);
    $this
      ->pass('AuthcacheP13nFragmentBuilder should throw an AuthcacheP13nRequestInvalidInput when validation fails');
  }

  // Verify stub.
  $this
    ->assert($validator
    ->verify($message), $message);
}