function DefaultValueWidgetTest::testDefaultValueOptionsForChangingBundles

Same name in other branches
  1. 10 core/modules/field_ui/tests/src/FunctionalJavascript/DefaultValueWidgetTest.php \Drupal\Tests\field_ui\FunctionalJavascript\DefaultValueWidgetTest::testDefaultValueOptionsForChangingBundles()

Tests default value options on field config change.

File

core/modules/field_ui/tests/src/FunctionalJavascript/DefaultValueWidgetTest.php, line 55

Class

DefaultValueWidgetTest
Tests the default value widget in Field UI.

Namespace

Drupal\Tests\field_ui\FunctionalJavascript

Code

public function testDefaultValueOptionsForChangingBundles() : void {
    $vocab_1 = $this->createVocabulary([
        'name' => 'Colors',
    ]);
    $this->createTerm($vocab_1, [
        'name' => 'red',
    ]);
    $this->createTerm($vocab_1, [
        'name' => 'green',
    ]);
    $vocab_2 = $this->createVocabulary([
        'name' => 'Tags',
    ]);
    $this->createTerm($vocab_2, [
        'name' => 'random tag 1',
    ]);
    $this->createTerm($vocab_2, [
        'name' => 'random tag 2',
    ]);
    $field_name = 'test_field';
    $this->fieldUIAddNewFieldJS('admin/structure/types/manage/test_content', $field_name, $field_name, 'entity_reference', FALSE);
    $page = $this->getSession()
        ->getPage();
    $page->findField('field_storage[subform][settings][target_type]')
        ->selectOption('taxonomy_term');
    $this->assertSession()
        ->assertWaitOnAjaxRequest();
    $page->findField('settings[handler_settings][target_bundles][' . $vocab_1->id() . ']')
        ->check();
    $this->assertSession()
        ->assertWaitOnAjaxRequest();
    $page->findField('set_default_value')
        ->check();
    $default_value_field = $page->findField('default_value_input[field_' . $field_name . '][0][target_id]');
    $default_value_field->setValue('r');
    $this->getSession()
        ->getDriver()
        ->keyDown($default_value_field->getXpath(), ' ');
    $this->assertSession()
        ->waitOnAutocomplete();
    // Check the autocomplete results.
    $results = $page->findAll('css', '.ui-autocomplete li');
    $this->assertCount(2, $results);
    $this->assertSession()
        ->elementTextNotContains('css', '.ui-autocomplete li', 'random tag 1');
    $this->assertSession()
        ->elementTextContains('css', '.ui-autocomplete li', 'green');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.