You are here

protected function IntegrationTest::addFacetDuplicate in Facets 8

Tests creating a facet with an existing machine name.

Parameters

string $facet_name: The name of the facet.

string $facet_type: The type of facet to create.

1 call to IntegrationTest::addFacetDuplicate()
IntegrationTest::testFramework in tests/src/Functional/IntegrationTest.php
Tests various operations via the Facets' admin UI.

File

tests/src/Functional/IntegrationTest.php, line 1003

Class

IntegrationTest
Tests the overall functionality of the Facets admin UI.

Namespace

Drupal\Tests\facets\Functional

Code

protected function addFacetDuplicate($facet_name, $facet_type = 'type') {
  $facet_id = $this
    ->convertNameToMachineName($facet_name);
  $facet_add_page = '/admin/config/search/facets/add-facet';
  $this
    ->drupalGet($facet_add_page);
  $form_values = [
    'name' => $facet_name,
    'id' => $facet_id,
    'facet_source_id' => 'search_api:views_page__search_api_test_view__page_1',
  ];
  $facet_source_configs['facet_source_configs[search_api:views_page__search_api_test_view__page_1][field_identifier]'] = $facet_type;

  // Try to submit a facet with a duplicate machine name after form rebuilding
  // via facet source submit.
  $this
    ->drupalPostForm(NULL, $form_values, 'Configure facet source');
  $this
    ->drupalPostForm(NULL, $form_values + $facet_source_configs, 'Save');
  $this
    ->assertSession()
    ->pageTextContains('The machine-readable name is already in use. It must be unique.');

  // Try to submit a facet with a duplicate machine name after form rebuilding
  // via facet source submit using AJAX.
  $this
    ->submitForm($form_values, 'Configure facet source');
  $this
    ->submitForm($form_values + $facet_source_configs, 'Save');
  $this
    ->assertSession()
    ->pageTextContains('The machine-readable name is already in use. It must be unique.');
}