You are here

public function SerialFieldTest::testSerialEntityCreation in Serial Field 8

Creates N entities and and checks the serial id for each.

Parameters

int $entities: Number of entities for creation.

File

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

Class

SerialFieldTest
Tests the creation of serial fields.

Namespace

Drupal\Tests\serial\Functional

Code

public function testSerialEntityCreation($entities = 15) {

  // Create N entities.
  $i = 0;
  while ($i < $entities) {
    $this
      ->drupalGet('entity_test/add');
    $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++;
    $this
      ->drupalGet('entity_test/' . $id);
    $serial = $this
      ->xpath('//div[contains(@class, "field__item") and text()="' . $this->serialId . '"]');
    $this
      ->assertEquals(1, count($serial));
    $i++;
  }
}