You are here

public function AuthcacheP13nTestObjectResourcePreprocessorCase::testOverrideResource in Authenticated User Page Caching (Authcache) 7.2

Covers AuthcacheP13nObjectResourcePreprocessor::preprocess().

File

modules/authcache_p13n/tests/authcache_p13n.object-resource-preprocessor.test, line 267
Define test cases for object factory.

Class

AuthcacheP13nTestObjectResourcePreprocessorCase
Tests for object factory.

Code

public function testOverrideResource() {
  $definition = array(
    'r1' => array(
      '#type' => 'class',
      '#class' => 'DummyClass1',
    ),
    'r2' => array(
      '#custom_type' => 'test',
    ),
  );
  $additional_definition = array(
    '#type' => 'class',
    '#class' => 'Overridden',
  );
  $additional_definitions = array(
    'r1' => $additional_definition,
    'default' => $additional_definition,
  );
  $expect_resources = array(
    'r1' => $additional_definition,
    'r2' => array(
      '#type' => 'value',
      '#value' => array(
        '#custom_type' => 'test',
      ),
    ),
    'default' => $additional_definition,
  );
  $expect_invocations = array(
    array(
      $definition['r1'],
      0,
      'r1',
      TRUE,
    ),
    array(
      $definition['r2'],
      0,
      'r2',
      TRUE,
    ),
    array(
      $additional_definitions['r1'],
      1,
      'r1',
      TRUE,
    ),
    array(
      $additional_definitions['default'],
      1,
      'default',
      TRUE,
    ),
  );
  $preproc = new AuthcacheP13nObjectResourcePreprocessor(array(
    'record_invocation' => array(
      $this,
      'recordPreprocessorInvocation',
    ),
    'add_definitions' => function ($definition, $priority, $key, $enqueue) use ($additional_definitions) {
      if (is_array($definition) && isset($definition['#custom_type'])) {

        // Enqueue additional definitions with lower priority.
        $enqueue($additional_definitions, $priority + 1);
      }
    },
  ));
  $resources = $preproc
    ->preprocess($definition);
  $this
    ->assertEqual($expect_resources, $resources);
  $this
    ->assertPreprocessorInvocations($expect_invocations);
}