public function CacheDecoratorTest::testClearCachedDefinitions

Tests CacheDecorator::clearCachedDefinitions().

File

drupal/core/modules/system/lib/Drupal/system/Tests/Plugin/CacheDecoratorTest.php, line 114
Contains \Drupal\system\Tests\Plugin\CacheDecoratorTest.

Class

CacheDecoratorTest
Tests \Drupal\Core\Plugin\Discovery\CacheDecorator behavior.

Namespace

Drupal\system\Tests\Plugin

Code

public function testClearCachedDefinitions() {
  $cache = cache($this->cacheBin);

  // Populate the caches by collecting definitions once.
  $this->discovery
    ->getDefinitions();

  // Add a new definition.
  $this->expectedDefinitions['banana'] = array(
    'label' => 'Banana',
    'color' => 'yellow',
  );
  $this->discovery
    ->setDefinition('banana', $this->expectedDefinitions['banana']);

  // Check that the new definition is not found.
  $definition = $this->discovery
    ->getDefinition('banana');
  $this
    ->assertNull($definition, 'Newly added definition is not found.');

  // Clear cached definitions, and check that the new definition is found.
  $this->discovery
    ->clearCachedDefinitions();
  $cached = $cache
    ->get($this->cacheKey);
  $this
    ->assertIdentical($cached, FALSE, 'Cache is empty.');
  $definitions = $this->discovery
    ->getDefinitions();
  $this
    ->assertIdentical($definitions, $this->expectedDefinitions, 'Newly added definition is found.');
}