class WebformBubbleableMetadataTest in Webform 8.5
Same name and namespace in other branches
- 6.x tests/src/Unit/Cache/WebformBubbleableMetadataTest.php \Drupal\Tests\webform\Unit\Cache\WebformBubbleableMetadataTest
Tests webform bubbleable metadata.
@coversDefaultClass \Drupal\webform\Cache\WebformBubbleableMetadata @group Cache
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\webform\Unit\Cache\WebformBubbleableMetadataTest
Expanded class hierarchy of WebformBubbleableMetadataTest
File
- tests/
src/ Unit/ Cache/ WebformBubbleableMetadataTest.php, line 16
Namespace
Drupal\Tests\webform\Unit\CacheView source
class WebformBubbleableMetadataTest extends UnitTestCase {
/**
* Tests appendTo renderable array.
*
* @param \Drupal\webform\Cache\WebformBubbleableMetadata $bubbleable_metadata
* Bubbleable metadata.
* @param array $build
* A render array.
* @param array $expected
* The expected render array.
* @covers ::appendTo
*
* @dataProvider providerTestAppendTo
*
* @see \Drupal\Tests\Core\Cache\CacheableMetadataTest
*/
public function testAppendTo(WebformBubbleableMetadata $bubbleable_metadata, array $build, array $expected) {
// Mock CacheContextsManager::assertValidTokens
// @see \Drupal\Core\Cache\Cache::mergeContexts
$cache_contexts_manager = $this
->getMockBuilder('Drupal\\Core\\Cache\\Context\\CacheContextsManager')
->disableOriginalConstructor()
->getMock();
$cache_contexts_manager
->method('assertValidTokens')
->willReturn(TRUE);
$container = new ContainerBuilder();
$container
->set('cache_contexts_manager', $cache_contexts_manager);
\Drupal::setContainer($container);
/**************************************************************************/
$bubbleable_metadata
->appendTo($build);
$this
->assertEquals($expected, $build);
}
/**
* Provides test data for testAppendTo().
*
* @return array
*/
public function providerTestAppendTo() {
return [
[
(new WebformBubbleableMetadata())
->setCacheContexts([
'bar',
]),
[],
[
'#cache' => [
'contexts' => [
'bar',
],
'tags' => [],
'max-age' => Cache::PERMANENT,
],
'#attached' => [],
],
],
[
(new WebformBubbleableMetadata())
->setCacheContexts([
'bar',
]),
[
'#cache' => [
'contexts' => [
'bar',
],
],
],
[
'#cache' => [
'contexts' => [
'bar',
],
'tags' => [],
'max-age' => Cache::PERMANENT,
],
'#attached' => [],
],
],
[
(new WebformBubbleableMetadata())
->setCacheContexts([
'bar',
'foo',
]),
[
'#cache' => [
'contexts' => [
'bar',
],
],
],
[
'#cache' => [
'contexts' => [
'bar',
'foo',
],
'tags' => [],
'max-age' => Cache::PERMANENT,
],
'#attached' => [],
],
],
[
(new WebformBubbleableMetadata())
->setCacheMaxAge(99),
[],
[
'#cache' => [
'contexts' => [],
'tags' => [],
'max-age' => 99,
],
'#attached' => [],
],
],
[
(new WebformBubbleableMetadata())
->setCacheContexts([
'bar',
]),
[
'#cache' => [
'max-age' => 99,
],
],
[
'#cache' => [
'contexts' => [
'bar',
],
'tags' => [],
'max-age' => 99,
],
'#attached' => [],
],
],
];
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 340 | |
WebformBubbleableMetadataTest:: |
public | function | Provides test data for testAppendTo(). | |
WebformBubbleableMetadataTest:: |
public | function | Tests appendTo renderable array. |