function TextWidgetTest::testSingleValueField

Same name in other branches
  1. 8.x-1.x field_example/tests/src/Functional/TextWidgetTest.php \Drupal\Tests\field_example\Functional\TextWidgetTest::testSingleValueField()
  2. 4.0.x modules/field_example/tests/src/Functional/TextWidgetTest.php \Drupal\Tests\field_example\Functional\TextWidgetTest::testSingleValueField()

Test basic functionality of the example field.

  • Creates a content type.
  • Adds a single-valued field_example_rgb to it.
  • Adds a multivalued field_example_rgb to it.
  • Creates a node of the new type.
  • Populates the single-valued field.
  • Populates the multivalued field with two items.
  • Tests the result.

File

modules/field_example/tests/src/Functional/TextWidgetTest.php, line 31

Class

TextWidgetTest
Test basic functionality of the widgets.

Namespace

Drupal\Tests\field_example\Functional

Code

public function testSingleValueField() {
    $assert = $this->assertSession();
    // Add a single field as administrator user.
    $this->drupalLogin($this->administratorAccount);
    $this->fieldName = $this->createField('field_example_rgb', 'field_example_text', '1');
    // Now that we have a content type with the desired field, switch to the
    // author user to create content with it.
    $this->drupalLogin($this->authorAccount);
    $this->drupalGet('node/add/' . $this->contentTypeName);
    // Add a node.
    $title = $this->randomMachineName(20);
    $edit = [
        'title[0][value]' => $title,
        'field_' . $this->fieldName . '[0][value]' => '#000001',
    ];
    // Create the content.
    $this->submitForm($edit, 'Save');
    $assert->pageTextContains("{$this->contentTypeName} {$title} has been created");
    // Verify the value is shown when viewing this node.
    $assert->pageTextContains('The color code in this field is #000001');
}