You are here

public function AuthcacheP13nTestObjectFactoryCase::testRequireRequireClassProcessors in Authenticated User Page Caching (Authcache) 7.2

Cover AuthcacheP13nObjectFactory::defaultProcessors().

File

modules/authcache_p13n/tests/authcache_p13n.object-factory.test, line 482
Define test cases for object factory.

Class

AuthcacheP13nTestObjectFactoryCase
Tests for object factory.

Code

public function testRequireRequireClassProcessors() {
  $processors = AuthcacheP13nObjectFactory::defaultProcessors();
  $resources = array(
    'null' => array(
      '#type' => 'value',
      '#value' => NULL,
    ),
    'zero' => array(
      '#type' => 'value',
      '#value' => 0,
    ),
    'non_zero' => array(
      '#type' => 'value',
      '#value' => 42,
    ),
    'object_class' => array(
      '#type' => 'class',
      '#class' => 'AuthcacheP13nTestObjectFactoryDummyClass',
    ),
    'object_subclass' => array(
      '#type' => 'class',
      '#class' => 'AuthcacheP13nTestObjectFactoryDummySubClass',
    ),
    'object_other_class' => array(
      '#type' => 'class',
      '#class' => 'AuthcacheP13nTestObjectFactoryDisconnectedDummyClass',
    ),
    'require_object_null' => array(
      '#type' => 'value',
      '#value' => '@null[require_instance(AuthcacheP13nTestObjectFactoryDummyClass)]',
    ),
    'require_object_zero' => array(
      '#type' => 'value',
      '#value' => '@zero[require_instance(AuthcacheP13nTestObjectFactoryDummyClass)]',
    ),
    'require_object_non_zero' => array(
      '#type' => 'value',
      '#value' => '@non_zero[require_instance(AuthcacheP13nTestObjectFactoryDummyClass)]',
    ),
    'require_object_object_interface' => array(
      '#type' => 'value',
      '#value' => '@object_class[require_instance(AuthcacheP13nTestObjectFactoryDummySubInterface)]',
    ),
    'require_object_object_subinterface' => array(
      '#type' => 'value',
      '#value' => '@object_subclass[require_instance(AuthcacheP13nTestObjectFactoryDummySubInterface)]',
    ),
    'require_object_object_class' => array(
      '#type' => 'value',
      '#value' => '@object_class[require_instance(AuthcacheP13nTestObjectFactoryDummyClass)]',
    ),
    'require_object_object_subclass' => array(
      '#type' => 'value',
      '#value' => '@object_subclass[require_instance(AuthcacheP13nTestObjectFactoryDummyClass)]',
    ),
    'require_object_object_other_class' => array(
      '#type' => 'value',
      '#value' => '@object_other_class[require_instance(AuthcacheP13nTestObjectFactoryDummyClass)]',
    ),
  );
  $factory = new AuthcacheP13nObjectFactory($resources, $processors);
  $expectations = array(
    'require_object_null' => NULL,
    'require_object_zero' => NULL,
    'require_object_non_zero' => NULL,
    'require_object_object_interface' => NULL,
    'require_object_object_subinterface' => new AuthcacheP13nTestObjectFactoryDummySubClass(),
    'require_object_object_class' => new AuthcacheP13nTestObjectFactoryDummyClass(),
    'require_object_object_subclass' => new AuthcacheP13nTestObjectFactoryDummySubClass(),
    'require_object_object_other_class' => NULL,
  );
  foreach ($expectations as $resource_name => $expect) {
    if ($expect === NULL) {
      try {
        $result = $factory
          ->get($resource_name);
        $this
          ->fail(t('Should throw an exception when trying to resolve :resource_name', array(
          ':resource_name' => $resource_name,
        )));
      } catch (AuthcacheP13nObjectFactoryException $e) {
        unset($e);
        $this
          ->pass(t('Should throw an exception when trying to resolve :resource_name', array(
          ':resource_name' => $resource_name,
        )));
      }
    }
    else {
      $result = $factory
        ->get($resource_name);
      $this
        ->assertEqual($expect, $result);
    }
  }
}