You are here

public function AuthcacheP13nTestFragmentAssemblyBuilder::testFragmentAssemblyBuilderValidation in Authenticated User Page Caching (Authcache) 7.2

Test request with validator.

File

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

Class

AuthcacheP13nTestFragmentAssemblyBuilder
Tests update functionality unrelated to the database.

Code

public function testFragmentAssemblyBuilderValidation() {
  $partials = array(
    'param_1' => array(
      'renderer' => new AuthcacheP13nTestEchoPartial(),
      'validator' => new AuthcacheP13nTestEchoFragmentValidator(),
    ),
  );
  $builder = new AuthcacheP13nFragmentAssemblyBuilder($partials);
  $input = array(
    'a' => array(
      'param_1' => array(
        'valid',
      ),
    ),
  );
  try {
    $builder
      ->validate($input, array());
    $this
      ->pass('AuthcacheP13nFragmentAssemblyBuilder should not throw an AuthcacheP13nRequestInvalidInput when validation succeeds');
  } catch (AuthcacheP13nRequestInvalidInput $e) {
    unset($e);
    $this
      ->fail('AuthcacheP13nFragmentAssemblyBuilder should not throw an AuthcacheP13nRequestInvalidInput when validation succeeds');
  }
  $input = array(
    'a' => array(
      'param_1' => array(
        'invalid',
      ),
    ),
  );
  try {
    $builder
      ->validate($input, array());
    $this
      ->fail('AuthcacheP13nFragmentAssemblyBuilder should throw an AuthcacheP13nRequestInvalidInput when validation fails');
  } catch (AuthcacheP13nRequestInvalidInput $e) {
    unset($e);
    $this
      ->pass('AuthcacheP13nFragmentAssemblyBuilder should throw an AuthcacheP13nRequestInvalidInput when validation fails');
  }
}