public function RenderStackTest::test_getsetRecursionStorage in Render cache 7.2
@covers ::getRecursionStorage() @covers ::setRecursionStorage() @covers ::addRecursionStorage()
File
- tests/
src/ Cache/ RenderStackTest.php, line 90 - Contains \Drupal\render_cache\Tests\Cache\RenderStackTest
Class
- RenderStackTest
- @coversDefaultClass \Drupal\render_cache\Cache\RenderStack @group cache
Namespace
Drupal\render_cache\Tests\CacheCode
public function test_getsetRecursionStorage() {
$attached = array();
$attached['css'][] = 'foo.css';
$attached['js'][] = 'bar.js';
$attached['library'][] = array(
'baz_module',
'lama',
);
$attached2 = array();
$attached2['css'][] = 'lama2.css';
$attached_combined = $attached;
$attached_combined['css'][] = 'lama2.css';
$recursion_storage_test_1_set = array(
'#cache' => array(
'tags' => array(
'node:1',
'rendered',
),
'#tags' => array(
'invalid',
),
),
'#attached' => $attached,
);
$recursion_storage_test_1 = $recursion_storage_test_1_set;
unset($recursion_storage_test_1['#cache']['#tags']);
$recursion_storage_test_2 = array(
'#cache' => array(
'tags' => array(
'foo:42',
'zoo:1',
),
),
'#attached' => $attached2,
);
$recursion_storage_test_combined = array(
'#cache' => array(
'tags' => array(
'foo:42',
'node:1',
'rendered',
'zoo:1',
),
),
'#attached' => $attached_combined,
);
$this->renderStack
->shouldReceive('collectAttached')
->times(8)
->andReturnUsing(function ($render) use ($attached_combined) {
if (!empty($render['#attached']) && !empty($render[0]['#attached'])) {
return $attached_combined;
}
if (!empty($render['#attached'])) {
return $render['#attached'];
}
if (!empty($render[0]['#attached'])) {
return $render[0]['#attached'];
}
return array();
});
$this
->assertEmpty($this->renderStack
->getRecursionStorage(), 'getRecursionStorage() is empty() at the beginning.');
$this->renderStack
->increaseRecursion();
$this
->assertEmpty($this->renderStack
->getRecursionStorage(), 'getRecursionStorage() is empty() at the beginning for level 1.');
$this
->assertEquals(1, $this->renderStack
->getRecursionLevel(), 'Recursion Level is 1 after increase.');
$this->renderStack
->setRecursionStorage($recursion_storage_test_1_set);
$this
->assertEquals($recursion_storage_test_1, $this->renderStack
->getRecursionStorage(), 'getRecursionStorage() matches what was set.');
$this->renderStack
->increaseRecursion();
$this
->assertEmpty($this->renderStack
->getRecursionStorage(), 'getRecursionStorage() is empty() at the beginning for level 2.');
$copy = $recursion_storage_test_2;
$this->renderStack
->addRecursionStorage($copy, TRUE);
unset($copy['#attached']);
$this
->assertEmpty($copy, 'addRecursionStorage() makes argument empty() after adding of storage (except for attached).');
$this
->assertEquals($recursion_storage_test_2, $this->renderStack
->getRecursionStorage(), 'getRecursionStorage() matches what was added.');
$storage = $this->renderStack
->decreaseRecursion();
$this
->assertEquals($recursion_storage_test_2, $storage, 'decreaseRecursion() matches what was added.');
$this
->assertEquals($recursion_storage_test_1, $this->renderStack
->getRecursionStorage(), 'getRecursionStorage() matches what was set.');
$this->renderStack
->addRecursionStorage($storage, TRUE);
$storage2 = $this->renderStack
->getRecursionStorage();
$storage = $this->renderStack
->decreaseRecursion();
$this
->assertEquals($recursion_storage_test_combined, $storage, 'decreaseRecursion() matches what was added combined.');
$this
->assertEmpty($this->renderStack
->getRecursionStorage(), 'getRecursionStorage() is empty() at the end.');
}