You are here

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

Covers $factory->get().

File

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

Class

AuthcacheP13nTestObjectFactoryCase
Tests for object factory.

Code

public function testFactoryCollectionGet() {
  $resources = array(
    'fourty two' => array(
      '#type' => 'value',
      '#value' => 42,
    ),
    'last instance' => array(
      '#type' => 'class',
      '#class' => 'AuthcacheP13nTestObjectFactoryDummyClass',
      '#arguments' => array(
        '@fourty two',
      ),
      '#member_of' => 'a collection',
      '#weight' => 10,
      '#key' => 'key of last instance',
    ),
    'strlen of four' => array(
      '#type' => 'func',
      '#func' => 'strlen',
      '#arguments' => array(
        'four',
      ),
      '#member_of' => 'a collection',
    ),
    'first instance' => array(
      '#type' => 'class',
      '#class' => 'AuthcacheP13nTestObjectFactoryDummyClass',
      '#arguments' => array(
        'param of first instance',
      ),
      '#member_of' => 'a collection',
      '#weight' => -1,
    ),
    'a collection' => array(
      '#type' => 'collection',
      '#collection' => 'a collection',
    ),
  );
  $factory = new AuthcacheP13nObjectFactory($resources);
  $expect = array(
    'first instance' => new AuthcacheP13nTestObjectFactoryDummyClass('param of first instance'),
    'strlen of four' => 4,
    'key of last instance' => new AuthcacheP13nTestObjectFactoryDummyClass(42),
  );
  $result = $factory
    ->get('a collection');
  $this
    ->assertEqual($expect, $result);

  // Test the #processor attribute of collections.
  $resources['a collection']['#processor'] = 'accept_instance(AuthcacheP13nTestObjectFactoryDummyClass)';
  $processors = AuthcacheP13nObjectFactory::defaultProcessors();
  $factory = new AuthcacheP13nObjectFactory($resources, $processors);
  $expect = array(
    'first instance' => new AuthcacheP13nTestObjectFactoryDummyClass('param of first instance'),
    'strlen of four' => NULL,
    'key of last instance' => new AuthcacheP13nTestObjectFactoryDummyClass(42),
  );
  $result = $factory
    ->get('a collection');
  $this
    ->assertEqual($expect, $result);
  unset($resources['a collection']['#processor']);

  // Test the #processors attribute of collections.
  $resources['a collection']['#processors'] = array(
    'first instance' => 'accept_instance(AuthcacheP13nTestObjectFactoryDummyClass)',
    'key of last instance' => 'accept_instance(AuthcacheP13nTestObjectFactoryDisconnectedDummyClass)',
  );
  $processors = AuthcacheP13nObjectFactory::defaultProcessors();
  $factory = new AuthcacheP13nObjectFactory($resources, $processors);
  $expect = array(
    'first instance' => new AuthcacheP13nTestObjectFactoryDummyClass('param of first instance'),
    'strlen of four' => 4,
    'key of last instance' => NULL,
  );
  $result = $factory
    ->get('a collection');
  $this
    ->assertEqual($expect, $result);
}