View source
<?php
namespace Drupal\options\Tests;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Tests\FieldTestBase;
class OptionsFloatFieldImportTest extends FieldTestBase {
public static $modules = array(
'node',
'options',
'field_ui',
'config',
'options_config_install_test',
);
protected function setUp() {
parent::setUp();
$admin_user = $this
->drupalCreateUser(array(
'synchronize configuration',
'access content',
'access administration pages',
'administer site configuration',
'administer content types',
'administer nodes',
'bypass node access',
'administer node fields',
'administer node display',
));
$this
->drupalLogin($admin_user);
}
public function testImport() {
$field_name = 'field_options_float';
$type = 'options_install_test';
$field_storage = FieldStorageConfig::loadByName('node', $field_name);
$this
->assertIdentical($field_storage
->getSetting('allowed_values'), $array = array(
'0' => 'Zero',
'0.5' => 'Point five',
));
$admin_path = 'admin/structure/types/manage/' . $type . '/fields/node.' . $type . '.' . $field_name . '/storage';
$this
->copyConfig($this->container
->get('config.storage'), $this->container
->get('config.storage.sync'));
$edit = array(
'settings[allowed_values]' => "0|Zero\n1|One",
);
$this
->drupalPostForm($admin_path, $edit, t('Save field settings'));
$field_storage = FieldStorageConfig::loadByName('node', $field_name);
$this
->assertIdentical($field_storage
->getSetting('allowed_values'), $array = array(
'0' => 'Zero',
'1' => 'One',
));
$this
->drupalGet('admin/config/development/configuration');
$this
->drupalPostForm(NULL, array(), t('Import all'));
$field_storage = FieldStorageConfig::loadByName('node', $field_name);
$this
->assertIdentical($field_storage
->getSetting('allowed_values'), $array = array(
'0' => 'Zero',
'0.5' => 'Point five',
));
FieldConfig::loadByName('node', $type, $field_name)
->delete();
$this
->drupalGet('admin/config/development/configuration');
$this
->drupalPostForm(NULL, array(), t('Import all'));
$field_storage = FieldStorageConfig::loadByName('node', $field_name);
$this
->assertIdentical($field_storage
->getSetting('allowed_values'), $array = array(
'0' => 'Zero',
'0.5' => 'Point five',
));
}
}