You are here

public function UnicityConfigTest::testUniqueId in Search Autocomplete 2.x

Same name and namespace in other branches
  1. 8 src/Tests/Entity/UnicityConfigTest.php \Drupal\search_autocomplete\Tests\Entity\UnicityConfigTest::testUniqueId()

Configuration creation should fail if ID is not unique.

File

src/Tests/Entity/UnicityConfigTest.php, line 39

Class

UnicityConfigTest
Test uniticity when creation configurations.

Namespace

Drupal\search_autocomplete\Tests\Entity

Code

public function testUniqueId() {

  // ----------------------------------------------------------------------
  // 1) Create the configuration.
  // Add new configurations.
  $this
    ->drupalGet('admin/config/search/search_autocomplete/add');

  // Default values.
  $config_name = "testing";
  $config = [
    'label' => 'test-label',
    'selector' => 'input#edit',
  ];

  // Click Add new button.
  $this
    ->drupalPostForm(NULL, [
    'label' => $config['label'],
    'id' => $config_name,
    'selector' => $config['selector'],
  ], 'Create Autocompletion Configuration');

  // ----------------------------------------------------------------------
  // 2) Create the configuration again.
  // Add new configurations.
  $this
    ->drupalGet('admin/config/search/search_autocomplete/add');

  // Default values.
  $config_name = "testing";
  $config = [
    'label' => 'test-another',
    'selector' => 'another',
  ];

  // Click Add new button.
  $this
    ->drupalPostForm(NULL, [
    'label' => $config['label'],
    'id' => $config_name,
    'selector' => $config['selector'],
  ], 'Create Autocompletion Configuration');
  $this
    ->assertRaw(t('The machine-readable name is already in use. It must be unique.'));
}