You are here

public function AuthcacheP13nTestSettingBuilder::testSettingBuilderValidation in Authenticated User Page Caching (Authcache) 7.2

Test request with validator.

File

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

Class

AuthcacheP13nTestSettingBuilder
Tests update functionality unrelated to the database.

Code

public function testSettingBuilderValidation() {
  $settings = array(
    's1' => array(
      'renderer' => new AuthcacheP13nTestEchoSetting(),
      'target' => 'targetSetting',
      'validator' => new AuthcacheP13nTestEchoSettingValidator(),
      'access' => NULL,
    ),
  );
  $builder = new AuthcacheP13nSettingBuilder($settings);
  $input = array(
    'a' => array(
      's1' => array(
        'valid' => TRUE,
      ),
    ),
  );
  try {
    $builder
      ->validate($input);
    $this
      ->pass('AuthcacheP13nSettingBuilder should not throw an AuthcacheP13nRequestInvalidInput when validation succeeds');
  } catch (AuthcacheP13nRequestInvalidInput $e) {
    unset($e);
    $this
      ->fail('AuthcacheP13nSettingBuilder should not throw an AuthcacheP13nRequestInvalidInput when validation succeeds');
  }
  $input = array(
    'a' => array(
      's1' => array(
        'valid' => FALSE,
      ),
    ),
  );
  try {
    $builder
      ->validate($input);
    $this
      ->fail('AuthcacheP13nSettingBuilder should throw an AuthcacheP13nRequestInvalidInput when validation fails');
  } catch (AuthcacheP13nRequestInvalidInput $e) {
    unset($e);
    $this
      ->pass('AuthcacheP13nSettingBuilder should throw an AuthcacheP13nRequestInvalidInput when validation fails');
  }
}