Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     // Determine what database backend is running, and set the skip flag.
     $this->skipTests = Database::getConnection()->databaseType() !== 'mysql';
     // Create some schemas so our export contains tables.
     $this->installSchema('system', ['key_value_expire', 'sessions']);
     $this->installSchema('dblog', ['watchdog']);
     $this->installEntitySchema('block_content');
     $this->installEntitySchema('user');
     $this->installEntitySchema('file');
     $this->installEntitySchema('menu_link_content');
     $this->installSchema('system', 'sequences');
     // Place some sample config to test for in the export.
     $this->data = ['foo' => $this->randomMachineName(), 'bar' => $this->randomMachineName()];
     $storage = new DatabaseStorage(Database::getConnection(), 'config');
     $storage->write('test_config', $this->data);
     // Create user account with some potential syntax issues.
     $account = User::create(['mail' => 'q\'uote$dollar@example.com', 'name' => '$dollar']);
     $account->save();
     // Create url_alias (this will create 'url_alias').
     $this->container->get('path.alias_storage')->save('/user/' . $account->id(), '/user/example');
     // Create a cache table (this will create 'cache_discovery').
     \Drupal::cache('discovery')->set('test', $this->data);
     // These are all the tables that should now be in place.
     $this->tables = ['block_content', 'block_content_field_data', 'block_content_field_revision', 'block_content_revision', 'cachetags', 'config', 'cache_bootstrap', 'cache_config', 'cache_data', 'cache_discovery', 'cache_entity', 'file_managed', 'key_value_expire', 'menu_link_content', 'menu_link_content_data', 'sequences', 'sessions', 'url_alias', 'user__roles', 'users', 'users_field_data', 'watchdog'];
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setUp();
     // Determine what database backend is running, and set the skip flag.
     $this->skipTests = Database::getConnection()->databaseType() !== 'mysql';
     // Create some schemas so our export contains tables.
     $this->installSchema('system', ['key_value_expire', 'semaphore', 'sessions', 'url_alias']);
     $this->installSchema('dblog', ['watchdog']);
     $this->installEntitySchema('block_content');
     $this->installEntitySchema('user');
     $this->installEntitySchema('file');
     $this->installEntitySchema('menu_link_content');
     // Place some sample config to test for in the export.
     $this->data = ['foo' => $this->randomMachineName(), 'bar' => $this->randomMachineName()];
     $storage = new DatabaseStorage(Database::getConnection(), 'config');
     $storage->write('test_config', $this->data);
     // Create a cache table (this will create 'cache_discovery').
     \Drupal::cache('discovery')->set('test', $this->data);
     // These are all the tables that should now be in place.
     $this->tables = ['block_content', 'block_content_field_data', 'block_content_field_revision', 'block_content_revision', 'cachetags', 'config', 'cache_discovery', 'cache_bootstrap', 'file_managed', 'key_value_expire', 'menu_link_content', 'menu_link_content_data', 'semaphore', 'sessions', 'url_alias', 'user__roles', 'users', 'users_field_data', 'watchdog'];
 }
Exemplo n.º 3
0
 /**
  * Tests data type handling.
  */
 public function testDataTypes()
 {
     \Drupal::service('module_installer')->install(array('config_test'));
     $storage = new DatabaseStorage($this->container->get('database'), 'config');
     $name = 'config_test.types';
     $config = $this->config($name);
     $original_content = file_get_contents(drupal_get_path('module', 'config_test') . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY . "/{$name}.yml");
     $this->verbose('<pre>' . $original_content . "\n" . var_export($storage->read($name), TRUE));
     // Verify variable data types are intact.
     $data = array('array' => array(), 'boolean' => TRUE, 'exp' => 1.2E+34, 'float' => 3.14159, 'float_as_integer' => (double) 1, 'hex' => 0xc, 'int' => 99, 'octal' => 0775, 'string' => 'string', 'string_int' => '1');
     $this->assertIdentical($config->get(), $data);
     // Re-set each key using Config::set().
     foreach ($data as $key => $value) {
         $config->set($key, $value);
     }
     $config->save();
     $this->assertIdentical($config->get(), $data);
     // Assert the data against the file storage.
     $this->assertIdentical($storage->read($name), $data);
     $this->verbose('<pre>' . $name . var_export($storage->read($name), TRUE));
     // Set data using config::setData().
     $config->setData($data)->save();
     $this->assertIdentical($config->get(), $data);
     $this->assertIdentical($storage->read($name), $data);
     // Test that setting an unsupported type for a config object with a schema
     // fails.
     try {
         $config->set('stream', fopen(__FILE__, 'r'))->save();
         $this->fail('No Exception thrown upon saving invalid data type.');
     } catch (UnsupportedDataTypeConfigException $e) {
         $this->pass(String::format('%class thrown upon saving invalid data type.', array('%class' => get_class($e))));
     }
     // Test that setting an unsupported type for a config object with no schema
     // also fails.
     $typed_config_manager = $this->container->get('config.typed');
     $config_name = 'config_test.no_schema';
     $config = $this->config($config_name);
     $this->assertFalse($typed_config_manager->hasConfigSchema($config_name));
     try {
         $config->set('stream', fopen(__FILE__, 'r'))->save();
         $this->fail('No Exception thrown upon saving invalid data type.');
     } catch (UnsupportedDataTypeConfigException $e) {
         $this->pass(String::format('%class thrown upon saving invalid data type.', array('%class' => get_class($e))));
     }
 }