function CacheableMetadataTest::testAddCacheTags

This delegates to Cache::mergeTags(), so just a basic test.

@covers ::addCacheTags

File

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

Class

CacheableMetadataTest
@coversDefaultClass \Drupal\Core\Cache\CacheableMetadata[[api-linebreak]] @group Cache

Namespace

Drupal\Tests\Core\Cache

Code

public function testAddCacheTags() {
  $metadata = new CacheableMetadata();
  $add_expected = [
    [
      [],
      [],
    ],
    [
      [
        'foo:bar',
      ],
      [
        'foo:bar',
      ],
    ],
    [
      [
        'foo:baz',
      ],
      [
        'foo:bar',
        'foo:baz',
      ],
    ],
    [
      [
        'axx:first',
        'foo:baz',
      ],
      [
        'axx:first',
        'foo:bar',
        'foo:baz',
      ],
    ],
    [
      [],
      [
        'axx:first',
        'foo:bar',
        'foo:baz',
      ],
    ],
    [
      [
        'axx:first',
      ],
      [
        'axx:first',
        'foo:bar',
        'foo:baz',
      ],
    ],
  ];
  foreach ($add_expected as $data) {
    list($add, $expected) = $data;
    $metadata->addCacheTags($add);
    $this->assertEquals($expected, $metadata->getCacheTags());
  }
}

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