/** * @covers ::rename */ public function testRename() { $old = new Config($this->randomMachineName(), $this->storage, $this->eventDispatcher, $this->typedConfig); $new = new Config($this->randomMachineName(), $this->storage, $this->eventDispatcher, $this->typedConfig); $this->storage->expects($this->exactly(2))->method('readMultiple')->willReturnMap([[[$old->getName()], $old->getRawData()], [[$new->getName()], $new->getRawData()]]); $this->cacheTagsInvalidator->expects($this->once())->method('invalidateTags')->with($old->getCacheTags()); $this->storage->expects($this->once())->method('rename')->with($old->getName(), $new->getName()); $this->configFactory->rename($old->getName(), $new->getName()); }
/** * @covers ::delete * @covers ::doDelete */ public function testDeleteNothing() { $this->moduleHandler->expects($this->never())->method($this->anything()); $this->configFactory->expects($this->never())->method('get'); $this->cacheTagsInvalidator->expects($this->never())->method('invalidateTags'); $this->entityStorage->delete(array()); }
/** * @covers ::delete * @dataProvider overrideDataProvider */ public function testDelete($data, $module_data) { $this->cacheTagsInvalidator->expects($this->once())->method('invalidateTags')->with(['config:config.test']); // Set initial data. foreach ($data as $key => $value) { $this->config->set($key, $value); } // Set overrides. $this->config->setModuleOverride($module_data); // Save. $this->config->save(); // Check that original data is still correct. $this->assertOriginalConfigDataEquals($data, FALSE); // Check overrides have been set. $this->assertConfigDataEquals($module_data); $this->assertOriginalConfigDataEquals($module_data, TRUE); // Check that config is new. $this->assertFalse($this->config->isNew()); // Delete. $this->config->delete(); // Check object properties have been reset. $this->assertTrue($this->config->isNew()); foreach ($data as $key => $value) { $this->assertEmpty($this->config->getOriginal($key, FALSE)); } // Check that overrides have persisted. foreach ($module_data as $key => $value) { $this->assertConfigDataEquals($module_data); $this->assertOriginalConfigDataEquals($module_data, TRUE); } }
/** * @covers ::disable * @depends testSetStatus */ public function testDisable() { $this->cacheTagsInvalidator->expects($this->once())->method('invalidateTags')->with(array('config:test_provider.' . $this->entityTypeId . '.' . $this->id)); $this->entity->setStatus(TRUE); $this->assertSame($this->entity, $this->entity->disable()); $this->assertFalse($this->entity->status()); }
/** * @covers ::postDelete */ public function testPostDelete() { $this->cacheTagsInvalidator->expects($this->once())->method('invalidateTags')->with(array($this->entityTypeId . ':' . $this->values['id'], $this->entityTypeId . '_list')); $storage = $this->getMock('\\Drupal\\Core\\Entity\\EntityStorageInterface'); $storage->expects($this->once())->method('getEntityType')->willReturn($this->entityType); $entities = array($this->values['id'] => $this->entity); $this->entity->postDelete($storage, $entities); }
/** * Tests a clear of the cache collector using tags. */ public function testUpdateCacheClearTags() { $key = $this->randomMachineName(); $value = $this->randomMachineName(); $tags = array($this->randomMachineName()); $this->collector = new CacheCollectorHelper($this->cid, $this->cacheBackend, $this->lock, $tags); // Set the data and request it. $this->collector->setCacheMissData($key, $value); $this->assertEquals($value, $this->collector->get($key)); $this->assertEquals($value, $this->collector->get($key)); // Should have been added to the storage and only be requested once. $this->assertEquals(1, $this->collector->getCacheMisses()); // Clear the collected cache using the tags, should call it again. $this->cacheBackend->expects($this->never())->method('delete'); $this->cacheTagsInvalidator->expects($this->once())->method('invalidateTags')->with($tags); $this->collector->clear(); $this->assertEquals($value, $this->collector->get($key)); $this->assertEquals(2, $this->collector->getCacheMisses()); }
/** * Tests the cache of the full and single table data. */ public function testFullAndTableGetCache() { $expected_views_data = $this->viewsDataWithProvider(); $table_name = 'views_test_data'; $table_name_2 = 'views_test_data_2'; $random_table_name = $this->randomMachineName(); // Views data should be invoked twice due to the clear call. $this->moduleHandler->expects($this->at(0))->method('getImplementations')->with('views_data')->willReturn(array('views_test_data')); $this->moduleHandler->expects($this->at(1))->method('invoke')->with('views_test_data', 'views_data')->willReturn($this->viewsData()); $this->moduleHandler->expects($this->at(2))->method('alter')->with('views_data', $expected_views_data); $this->moduleHandler->expects($this->at(3))->method('getImplementations')->with('views_data')->willReturn(array('views_test_data')); $this->moduleHandler->expects($this->at(4))->method('invoke')->with('views_test_data', 'views_data')->willReturn($this->viewsData()); $this->moduleHandler->expects($this->at(5))->method('alter')->with('views_data', $expected_views_data); // The cache should only be called once (before the clear() call) as get // will get all table data in the first get(). $this->cacheBackend->expects($this->at(0))->method('get')->with("views_data:en")->will($this->returnValue(FALSE)); $this->cacheBackend->expects($this->at(1))->method('set')->with("views_data:en", $expected_views_data); $this->cacheBackend->expects($this->at(2))->method('get')->with("views_data:{$random_table_name}:en")->will($this->returnValue(FALSE)); $this->cacheBackend->expects($this->at(3))->method('set')->with("views_data:{$random_table_name}:en", array()); $this->cacheTagsInvalidator->expects($this->once())->method('invalidateTags')->with(['views_data']); $this->cacheBackend->expects($this->at(4))->method('get')->with("views_data:en")->will($this->returnValue(FALSE)); $this->cacheBackend->expects($this->at(5))->method('set')->with("views_data:en", $expected_views_data); $this->cacheBackend->expects($this->at(6))->method('get')->with("views_data:{$random_table_name}:en")->will($this->returnValue(FALSE)); $this->cacheBackend->expects($this->at(7))->method('set')->with("views_data:{$random_table_name}:en", array()); $views_data = $this->viewsData->get(); $this->assertSame($expected_views_data, $views_data); // Request a specific table should be static cached. $views_data = $this->viewsData->get($table_name); $this->assertSame($expected_views_data[$table_name], $views_data); // Another table being requested should also come from the static cache. $views_data = $this->viewsData->get($table_name_2); $this->assertSame($expected_views_data[$table_name_2], $views_data); $views_data = $this->viewsData->get($random_table_name); $this->assertSame(array(), $views_data); $this->viewsData->clear(); // Get the views data again. $this->viewsData->get(); $this->viewsData->get($table_name); $this->viewsData->get($table_name_2); $this->viewsData->get($random_table_name); }
/** * Tests the getAllBundleInfo() method. * * @covers ::getAllBundleInfo */ public function testGetAllBundleInfo() { $apple = $this->getMock('Drupal\\Core\\Entity\\EntityTypeInterface'); $apple->expects($this->once())->method('getLabel')->will($this->returnValue('Apple')); $banana = $this->getMock('Drupal\\Core\\Entity\\EntityTypeInterface'); $banana->expects($this->once())->method('getLabel')->will($this->returnValue('Banana')); $this->setUpEntityManager(array('apple' => $apple, 'banana' => $banana)); $this->cacheBackend->expects($this->at(0))->method('get')->with("entity_bundle_info:en", FALSE)->will($this->returnValue(FALSE)); $this->cacheBackend->expects($this->at(1))->method('get')->with("entity_type", FALSE)->will($this->returnValue(FALSE)); $this->cacheBackend->expects($this->at(2))->method('set')->with("entity_type"); $this->cacheBackend->expects($this->at(3))->method('set')->with("entity_bundle_info:en"); $this->cacheTagsInvalidator->expects($this->at(0))->method('invalidateTags')->with(array('entity_types')); $this->cacheTagsInvalidator->expects($this->at(1))->method('invalidateTags')->with(array('entity_bundles')); $this->cacheTagsInvalidator->expects($this->at(2))->method('invalidateTags')->with(array('entity_field_info')); $this->cacheBackend->expects($this->at(4))->method('get')->with("entity_bundle_info:en", FALSE)->will($this->returnValue((object) array('data' => 'cached data'))); $expected = array('apple' => array('apple' => array('label' => 'Apple')), 'banana' => array('banana' => array('label' => 'Banana'))); $bundle_info = $this->entityManager->getAllBundleInfo(); $this->assertSame($expected, $bundle_info); $bundle_info = $this->entityManager->getAllBundleInfo(); $this->assertSame($expected, $bundle_info); $this->entityManager->clearCachedDefinitions(); $bundle_info = $this->entityManager->getAllBundleInfo(); $this->assertSame('cached data', $bundle_info); }
/** * @covers ::delete */ public function testDelete() { $this->cacheTagsInvalidator->expects($this->once())->method('invalidateTags')->with(['config:config.test']); $this->configTranslation->initWithData([]); $this->configTranslation->delete(); }
/** * @covers ::resetInfo */ public function testResetInfo() { $this->cacheTagsInvalidator->expects($this->once())->method('invalidateTags')->with(['token_info']); $this->token->resetInfo(); }