public function RenderCachePlaceholderTest::setUp in Render cache 7.2
File
- tests/
src/ Cache/ RenderCachePlaceholderTest.php, line 31 - Contains \Drupal\render_cache\Tests\Cache\RenderCachePlaceholderTest
Class
- RenderCachePlaceholderTest
- @coversDefaultClass \Drupal\render_cache\Cache\RenderCachePlaceholder @group cache
Namespace
Drupal\render_cache\Tests\CacheCode
public function setUp() {
$this->staticClass = RenderCachePlaceholderMock::helper_getClass();
$this->testClass = get_class($this);
$this->placeholderArgFunc = '%' . $this->testClass . '::foo';
$this->placeholderArgLoad = $this->testClass . '::foo_load';
$data = array(
'single' => array(
'func' => 'postRenderCacheCallback',
'token' => 'n6lnoFtakTea+1C4Ox28YJ9GX/YA33x18RTw46nOOb+42Qofut1EvArYqECraJzlypf7DAR9MA==',
'callback' => $this->testClass . '::singleCallback',
'args' => array(
$this->placeholderArgFunc => 'foo',
'bar',
),
'return' => 'Foobar',
),
'multi_1' => array(
'func' => 'postRenderCacheMultiCallback',
'token' => 'M41Dgx+Cep02ViLzyRydUNgba8xMNdBjxn7Iu4dXNIXX+6L9RkNsXNfh8msI9mVFgd8yuQLlew==',
'callback' => $this->testClass . '::multiCallback',
'args' => array(
1,
'foo' => 'foo',
),
'return' => 'bar_1_foo',
),
'multi_2' => array(
'func' => 'postRenderCacheMultiCallback',
'token' => '5jOFkKm/lxLXBzraoHNGi8Aa5KxTZ9sDRTu7doVgxHACDxU2va7N2OpysutTffjDGupAGFpNRg==',
'callback' => $this->testClass . '::multiCallback',
'args' => array(
2,
'foo' => 'foo',
),
'return' => 'bar_2_foo',
),
);
foreach ($data as $key => $info) {
$data[$key]['placeholder'] = $this
->getPlaceholderArray($info['token'], $info['callback'], $info['args'], $info['func']);
}
$this->data = $data;
$test_class = $this->testClass;
$mock = Mockery::mock('\\Drupal\\render_cache\\Tests\\Cache\\RenderCachePlaceholderHelper');
$mock
->shouldReceive('generatePlaceholder')
->with(Mockery::any(), Mockery::on(function (array &$context) use ($data, $test_class) {
if ($context['function'] == $test_class . '::singleCallback') {
$context['token'] = $data['single']['token'];
return TRUE;
}
if ($context['function'] != $test_class . '::multiCallback') {
return FALSE;
}
$key = 'multi_' . $context['args'][0];
$context['token'] = $data[$key]['token'];
return TRUE;
}))
->andReturnUsing(function ($callback, $context) use ($data, $test_class) {
if ($context['function'] == $test_class . '::singleCallback') {
return $data['single']['placeholder']['#markup'];
}
$key = 'multi_' . $context['args'][0];
return $data[$key]['placeholder']['#markup'];
});
$mock
->shouldReceive('drupalRender')
->andReturnUsing(function ($elements) {
return $elements['#markup'];
});
$class_name = $this->staticClass;
$class_name::$mock = $mock;
}