public function FieldUpdateTest::testFieldUpdate8002 in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/field/src/Tests/Update/FieldUpdateTest.php \Drupal\field\Tests\Update\FieldUpdateTest::testFieldUpdate8002()
Tests field_update_8002().
See also
File
- core/
modules/ field/ src/ Tests/ Update/ FieldUpdateTest.php, line 74 - Contains \Drupal\field\Tests\Update\FieldUpdateTest.
Class
- FieldUpdateTest
- Tests that field settings are properly updated during database updates.
Namespace
Drupal\field\Tests\UpdateCode
public function testFieldUpdate8002() {
// Check that 'entity_reference' is the provider and a dependency of the
// test field storage .
$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);
// Check that 'entity_reference' is a dependency of the test field.
$field = $this->configFactory
->get('field.field.node.article.field_ref_views_select_2429191');
$this
->assertEntityRefDependency($field, TRUE);
// Check that 'entity_reference' is a dependency of the test view.
$view = $this->configFactory
->get('views.view.entity_reference_plugins_2429191');
$this
->assertEntityRefDependency($view, TRUE);
// Run updates.
$this
->runUpdates();
// Check that 'entity_reference' is no longer a dependency of the test field
// and view.
$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);
// Check that field selection, based on the view, still works. It only
// selects nodes whose title contains 'foo'.
$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(),
]);
}