function CacheableMetadataTest::testMerge

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Cache/CacheableMetadataTest.php \Drupal\Tests\Core\Cache\CacheableMetadataTest::testMerge()
  2. 8.9.x core/tests/Drupal/Tests/Core/Cache/CacheableMetadataTest.php \Drupal\Tests\Core\Cache\CacheableMetadataTest::testMerge()
  3. 10 core/tests/Drupal/Tests/Core/Cache/CacheableMetadataTest.php \Drupal\Tests\Core\Cache\CacheableMetadataTest::testMerge()

Tests merge().

This only tests at a high level, because it reuses existing logic. Detailed tests exist for the existing logic:

@covers ::merge @dataProvider providerTestMerge

See also

\Drupal\Tests\Core\Cache\CacheTest::testMergeTags()

\Drupal\Tests\Core\Cache\CacheTest::testMergeMaxAges()

\Drupal\Tests\Core\Cache\CacheContextsTest

File

core/tests/Drupal/Tests/Core/Cache/CacheableMetadataTest.php, line 32

Class

CacheableMetadataTest
@coversDefaultClass \Drupal\Core\Cache\CacheableMetadata @group Cache

Namespace

Drupal\Tests\Core\Cache

Code

public function testMerge(CacheableMetadata $a, CacheableMetadata $b, CacheableMetadata $expected) : void {
    $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);
    $this->assertEqualsCanonicalizing($expected, $a->merge($b));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.