You are here

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

Covers AuthcacheP13nObjectResourcePreprocessor::preprocess().

File

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

Class

AuthcacheP13nTestObjectResourcePreprocessorCase
Tests for object factory.

Code

public function testPreprocessorSequence() {
  $definition = array(
    'r1' => array(
      '#type' => 'class',
      '#class' => 'DummyClass1',
    ),
  );
  $substitute_1 = array(
    '#type' => 'func',
    '#func' => 'intval',
  );
  $substitute_2 = array(
    '#type' => 'class',
    '#class' => 'Final',
  );
  $expect_resources = array(
    'r1' => array(
      '#type' => 'class',
      '#class' => 'Final',
    ),
  );
  $expect_invocations = array(
    array(
      $definition['r1'],
      0,
      'r1',
      TRUE,
    ),
    array(
      $substitute_1,
      0,
      'r1',
      TRUE,
    ),
    array(
      $substitute_2,
      0,
      'r1',
      TRUE,
    ),
  );

  // Ensure that each preprocessor operates on the resource returned from its
  // predecessor.
  $preproc = new AuthcacheP13nObjectResourcePreprocessor(array(
    'record_invocation_1' => array(
      $this,
      'recordPreprocessorInvocation',
    ),
    'substitute_1' => function ($definition, $priority, $key, $enqueue) use ($substitute_1) {
      return $substitute_1;
    },
    'record_invocation_2' => array(
      $this,
      'recordPreprocessorInvocation',
    ),
    'substitute_2' => function ($definition, $priority, $key, $enqueue) use ($substitute_2) {
      return $substitute_2;
    },
    'record_invocation_3' => array(
      $this,
      'recordPreprocessorInvocation',
    ),
  ));
  $resources = $preproc
    ->preprocess($definition);
  $this
    ->assertEqual($expect_resources, $resources);
  $this
    ->assertPreprocessorInvocations($expect_invocations);
}