You are here

public function MultipleSelectsWidgetUiTest::testCardinality in Multiple Selects 8

Test widget with a fixed cardinality.

File

tests/src/Functional/MultipleSelectsWidgetUiTest.php, line 179

Class

MultipleSelectsWidgetUiTest
Tests the multiple select widget.

Namespace

Drupal\Tests\multiple_selects\Functional

Code

public function testCardinality() {
  $field_storage_config = FieldStorageConfig::loadByName('node', 'field_tags');
  $field_storage_config
    ->setCardinality(3);
  $field_storage_config
    ->save();
  $this
    ->drupalGet('node/add/page');
  $this
    ->assertSession()
    ->selectExists('field_tags[0][target_id]');
  $this
    ->assertSession()
    ->selectExists('field_tags[1][target_id]');
  $this
    ->assertSession()
    ->selectExists('field_tags[2][target_id]');
  $this
    ->assertSession()
    ->fieldNotExists('field_tags[4][target_id]');
  $this
    ->assertSession()
    ->buttonNotExists('Add another item');
}