FieldUpdateTest.php in Zircon Profile 8
File
core/modules/field/src/Tests/Update/FieldUpdateTest.php
View source
<?php
namespace Drupal\field\Tests\Update;
use Drupal\Core\Config\Config;
use Drupal\field\Entity\FieldConfig;
use Drupal\node\Entity\Node;
use Drupal\system\Tests\Update\UpdatePathTestBase;
class FieldUpdateTest extends UpdatePathTestBase {
protected $configFactory;
protected function setUp() {
parent::setUp();
$this->configFactory = $this->container
->get('config.factory');
}
protected function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
__DIR__ . '/../../../tests/fixtures/update/drupal-8.views_entity_reference_plugins-2429191.php',
];
}
public function testFieldUpdate8001() {
$config = $this->configFactory
->get('field.storage.node.field_image');
$settings = $config
->get('settings');
$this
->assertTrue(array_key_exists('target_bundle', $settings));
$this
->runUpdates();
$config = $this->configFactory
->get('field.storage.node.field_image');
$settings = $config
->get('settings');
$this
->assertFalse(array_key_exists('target_bundle', $settings));
}
public function testFieldUpdate8002() {
$field_storage = $this->configFactory
->get('field.storage.node.field_ref_views_select_2429191');
$this
->assertIdentical($field_storage
->get('module'), 'entity_reference');
$this
->assertEntityRefDependency($field_storage, TRUE);
$field = $this->configFactory
->get('field.field.node.article.field_ref_views_select_2429191');
$this
->assertEntityRefDependency($field, TRUE);
$view = $this->configFactory
->get('views.view.entity_reference_plugins_2429191');
$this
->assertEntityRefDependency($view, TRUE);
$this
->runUpdates();
$field_storage = $this->configFactory
->get('field.storage.node.field_ref_views_select_2429191');
$this
->assertIdentical($field_storage
->get('module'), 'core');
$this
->assertEntityRefDependency($field_storage, FALSE);
$field = $this->configFactory
->get('field.field.node.article.field_ref_views_select_2429191');
$this
->assertEntityRefDependency($field, FALSE);
$view = $this->configFactory
->get('views.view.entity_reference_plugins_2429191');
$this
->assertEntityRefDependency($view, FALSE);
$node_1 = Node::create([
'type' => 'article',
'title' => 'foobar',
]);
$node_1
->save();
$node_2 = Node::create([
'type' => 'article',
'title' => 'barbaz',
]);
$node_2
->save();
$field = FieldConfig::load('node.article.field_ref_views_select_2429191');
$selection = \Drupal::service('plugin.manager.entity_reference_selection')
->getSelectionHandler($field);
$referencable = $selection
->getReferenceableEntities();
$this
->assertEqual(array_keys($referencable['article']), [
$node_1
->id(),
]);
}
protected function assertEntityRefDependency(Config $config, $present) {
$dependencies = $config
->get('dependencies');
$dependencies += [
'module' => [],
];
$this
->assertEqual(in_array('entity_reference', $dependencies['module']), $present);
}
}
Classes
Name |
Description |
FieldUpdateTest |
Tests that field settings are properly updated during database updates. |