getContainerWithCacheTagsInvalidator example


  protected $viewsData;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $this->cacheTagsInvalidator = $this->createMock('Drupal\Core\Cache\CacheTagsInvalidatorInterface');
    $this->cacheBackend = $this->createMock('Drupal\Core\Cache\CacheBackendInterface');
    $this->getContainerWithCacheTagsInvalidator($this->cacheTagsInvalidator);

    $configs = [];
    $configs['views.settings']['skip_cache'] = FALSE;
    $this->configFactory = $this->getConfigFactoryStub($configs);
    $this->moduleHandler = $this->createMock('Drupal\Core\Extension\ModuleHandlerInterface');
    $this->languageManager = $this->createMock('Drupal\Core\Language\LanguageManagerInterface');
    $this->languageManager->expects($this->any())
      ->method('getCurrentLanguage')
      ->willReturn(new Language(['id' => 'en']));

    $this->viewsData = new ViewsData($this->cacheBackend, $this->configFactory, $this->moduleHandler, $this->languageManager);
  }

  protected function setUp(): void {
    parent::setUp();

    $this->cacheBackend = $this->createMock('Drupal\Core\Cache\CacheBackendInterface');
    $this->cacheTagsInvalidator = $this->createMock('Drupal\Core\Cache\CacheTagsInvalidatorInterface');
    $this->lock = $this->createMock('Drupal\Core\Lock\LockBackendInterface');
    $this->cid = $this->randomMachineName();
    $this->collector = new CacheCollectorHelper($this->cid, $this->cacheBackend, $this->lock);

    $this->getContainerWithCacheTagsInvalidator($this->cacheTagsInvalidator);
  }

  /** * Tests the resolve cache miss function. */
  public function testResolveCacheMiss() {
    $key = $this->randomMachineName();
    $value = $this->randomMachineName();
    $this->collector->setCacheMissData($key$value);

    $this->assertEquals($value$this->collector->get($key));
  }
$cid = $this->randomMachineName();
    $cache_backend = $this->createMock('Drupal\Core\Cache\CacheBackendInterface');
    $cache_tags_invalidator = $this->createMock('Drupal\Core\Cache\CacheTagsInvalidatorInterface');
    $cache_tags_invalidator
      ->expects($this->once())
      ->method('invalidateTags')
      ->with(['tag']);
    $cache_backend
      ->expects($this->never())
      ->method('deleteMultiple');

    $this->getContainerWithCacheTagsInvalidator($cache_tags_invalidator);

    $plugin_manager = new TestPluginManager($this->namespaces, $this->expectedDefinitions, NULL, NULL, '\Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface');
    $plugin_manager->setCacheBackend($cache_backend$cid['tag']);

    $plugin_manager->clearCachedDefinitions();
  }

  /** * Tests plugins with the proper interface. * * @covers ::createInstance */
Home | Imprint | This part of the site doesn't use cookies.