You are here

public function SerialFieldTest::testSerialField in Serial Field 8

Helper function for testSerialField().

File

tests/src/Functional/SerialFieldTest.php, line 126

Class

SerialFieldTest
Tests the creation of serial fields.

Namespace

Drupal\Tests\serial\Functional

Code

public function testSerialField() {

  // Test the entity creation form.
  $this
    ->drupalGet('entity_test/add');

  // Make sure the "serial_default_widget" widget is on the markup.
  $fields = $this
    ->xpath('//div[contains(@class, "field--widget-serial-default-widget") and @id="edit-field-serial-wrapper"]');
  $this
    ->assertEquals(1, count($fields));

  // Make sure that the widget is hidden on the entity creation form.
  $this
    ->assertSession()
    ->fieldNotExists('field_serial[0][value]');

  // Test basic definition of serial field on entity save.
  $edit = [];
  $this
    ->drupalPostForm(NULL, $edit, t('Save'));

  // Make sure the entity was saved.
  preg_match('|entity_test/manage/(\\d+)|', $this
    ->getSession()
    ->getCurrentUrl(), $match);
  $id = $match[1];
  $this
    ->assertSession()
    ->pageTextContains(sprintf('entity_test %s has been created.', $id));

  // Make sure the serial id is in the output.
  $this->serialId = 1;
  $this
    ->drupalGet('entity_test/' . $id);
  $serial = $this
    ->xpath('//div[contains(@class, "field__item") and text()="' . $this->serialId . '"]');
  $this
    ->assertEquals(1, count($serial));
}