/** * @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); } }
/** * Tests configuration events. */ function testConfigEvents() { $name = 'config_events_test.test'; $config = new Config($name, \Drupal::service('config.storage'), \Drupal::service('event_dispatcher'), \Drupal::service('config.typed')); $config->set('key', 'initial'); \Drupal::state()->get('config_events_test.event', FALSE); $this->assertIdentical(\Drupal::state()->get('config_events_test.event', array()), array(), 'No events fired by creating a new configuration object'); $config->save(); $event = \Drupal::state()->get('config_events_test.event', array()); $this->assertIdentical($event['event_name'], ConfigEvents::SAVE); $this->assertIdentical($event['current_config_data'], array('key' => 'initial')); $this->assertIdentical($event['raw_config_data'], array('key' => 'initial')); $this->assertIdentical($event['original_config_data'], array()); $config->set('key', 'updated')->save(); $event = \Drupal::state()->get('config_events_test.event', array()); $this->assertIdentical($event['event_name'], ConfigEvents::SAVE); $this->assertIdentical($event['current_config_data'], array('key' => 'updated')); $this->assertIdentical($event['raw_config_data'], array('key' => 'updated')); $this->assertIdentical($event['original_config_data'], array('key' => 'initial')); $config->delete(); $event = \Drupal::state()->get('config_events_test.event', array()); $this->assertIdentical($event['event_name'], ConfigEvents::DELETE); $this->assertIdentical($event['current_config_data'], array()); $this->assertIdentical($event['raw_config_data'], array()); $this->assertIdentical($event['original_config_data'], array('key' => 'updated')); }
/** * Writes a configuration change from the source to the target storage. * * @param string $collection * The configuration collection. * @param string $op * The change operation. * @param string $name * The name of the configuration to process. */ protected function importConfig($collection, $op, $name) { // Allow config factory overriders to use a custom configuration object if // they are responsible for the collection. $overrider = $this->configManager->getConfigCollectionInfo()->getOverrideService($collection); if ($overrider) { $config = $overrider->createConfigObject($name, $collection); } else { $config = new Config($name, $this->storageComparer->getTargetStorage($collection), $this->eventDispatcher, $this->typedConfigManager); } if ($op == 'delete') { $config->delete(); } else { $data = $this->storageComparer->getSourceStorage($collection)->read($name); $config->setData($data ? $data : array()); $config->save(); } $this->setProcessedConfiguration($collection, $op, $name); }