/** * @covers ::initWithData * @dataProvider nestedDataProvider */ public function testInitWithData($data) { $config = $this->config->initWithData($data); // Should return the Config object. $this->assertInstanceOf('\\Drupal\\Core\\Config\\Config', $config); // Check config is not new. $this->assertEquals(FALSE, $this->config->isNew()); // Check that data value was set correctly. $this->assertConfigDataEquals($data); // Check that original data was set. $this->assertOriginalConfigDataEquals($data, TRUE); // Check without applying overrides. $this->assertOriginalConfigDataEquals($data, FALSE); }
/** * @covers ::setData * @covers ::set * @covers ::initWithData */ public function testSafeStringHandling() { // Safe strings are cast when using ::set(). $safe_string = Markup::create('bar'); $this->config->set('foo', $safe_string); $this->assertSame('bar', $this->config->get('foo')); $this->config->set('foo', ['bar' => $safe_string]); $this->assertSame('bar', $this->config->get('foo.bar')); // Safe strings are cast when using ::setData(). $this->config->setData(['bar' => $safe_string]); $this->assertSame('bar', $this->config->get('bar')); // Safe strings are not cast when using ::initWithData(). $this->config->initWithData(['bar' => $safe_string]); $this->assertSame($safe_string, $this->config->get('bar')); }
/** * Imports a configuration entity rename. * * @param string $collection * The configuration collection. * @param string $rename_name * The rename configuration name, as provided by * \Drupal\Core\Config\StorageComparer::createRenameName(). * * @throws \Drupal\Core\Entity\EntityStorageException * Thrown if the data is owned by an entity type, but the entity storage * does not support imports. * * @return bool * TRUE if the configuration was imported as a configuration entity. FALSE * otherwise. * * @see \Drupal\Core\Config\ConfigImporter::createRenameName() */ protected function importInvokeRename($collection, $rename_name) { $names = $this->storageComparer->extractRenameNames($rename_name); $entity_type_id = $this->configManager->getEntityTypeIdByName($names['old_name']); $old_config = new Config($names['old_name'], $this->storageComparer->getTargetStorage($collection), $this->eventDispatcher, $this->typedConfigManager); if ($old_data = $this->storageComparer->getTargetStorage($collection)->read($names['old_name'])) { $old_config->initWithData($old_data); } $data = $this->storageComparer->getSourceStorage($collection)->read($names['new_name']); $new_config = new Config($names['new_name'], $this->storageComparer->getTargetStorage($collection), $this->eventDispatcher, $this->typedConfigManager); if ($data !== FALSE) { $new_config->setData($data); } $entity_storage = $this->configManager->getEntityManager()->getStorage($entity_type_id); // Call to the configuration entity's storage to handle the configuration // change. if (!$entity_storage instanceof ImportableEntityStorageInterface) { throw new EntityStorageException(SafeMarkup::format('The entity storage "@storage" for the "@entity_type" entity type does not support imports', array('@storage' => get_class($entity_storage), '@entity_type' => $entity_type_id))); } $entity_storage->importRename($names['old_name'], $new_config, $old_config); $this->setProcessedConfiguration($collection, 'rename', $rename_name); return TRUE; }