public function AuthcacheP13nTestObjectResourcePreprocessorCase::testSubstituteResource in Authenticated User Page Caching (Authcache) 7.2
Covers AuthcacheP13nObjectResourcePreprocessor::preprocess().
File
- modules/
authcache_p13n/ tests/ authcache_p13n.object-resource-preprocessor.test, line 166 - Define test cases for object factory.
Class
- AuthcacheP13nTestObjectResourcePreprocessorCase
- Tests for object factory.
Code
public function testSubstituteResource() {
$definition = array(
'r1' => array(
'#type' => 'class',
'#class' => 'DummyClass1',
),
'r2' => array(
'#custom_type' => 'test',
),
);
$substitute_resource = array(
'#type' => 'class',
'#class' => 'Generated',
);
$expect_resources = array(
'r1' => array(
'#type' => 'class',
'#class' => 'DummyClass1',
),
'r2' => $substitute_resource,
);
$expect_invocations = array(
array(
$definition['r1'],
0,
'r1',
TRUE,
),
array(
$definition['r2'],
0,
'r2',
TRUE,
),
);
$preproc = new AuthcacheP13nObjectResourcePreprocessor(array(
'record_invocation' => array(
$this,
'recordPreprocessorInvocation',
),
'substitute_custom_type' => function ($definition, $priority, $key, $enqueue) use ($substitute_resource) {
if (is_array($definition) && isset($definition['#custom_type'])) {
return $substitute_resource;
}
},
));
$resources = $preproc
->preprocess($definition);
$this
->assertEqual($expect_resources, $resources);
$this
->assertPreprocessorInvocations($expect_invocations);
}