You are here

protected function IntegrationTest::editFacet in Facets 8

Tests editing of a facet through the UI.

Parameters

string $facet_name: The name of the facet.

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

File

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

Class

IntegrationTest
Tests the overall functionality of the Facets admin UI.

Namespace

Drupal\Tests\facets\Functional

Code

protected function editFacet($facet_name) {
  $facet_id = $this
    ->convertNameToMachineName($facet_name);
  $facet_edit_page = '/admin/config/search/facets/' . $facet_id . '/settings';

  // Go to the facet edit page and make sure "edit facet %facet" is present.
  $this
    ->drupalGet($facet_edit_page);
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->responseContains('Facet settings for ' . $facet_name . ' facet');

  // Check if it's possible to change the machine name.
  $elements = $this
    ->xpath('//form[@id="facets-facet-settings-form"]/div[contains(@class, "form-item-id")]/input[@disabled]');
  $this
    ->assertEquals(count($elements), 1, 'Machine name cannot be changed.');

  // Change the facet name to add in "-2" to test editing of a facet works.
  $form_values = [
    'name' => $facet_name . ' - 2',
  ];
  $this
    ->drupalPostForm($facet_edit_page, $form_values, 'Save');

  // Make sure that the redirection back to the overview was successful and
  // the edited facet is shown on the overview page.
  $this
    ->assertSession()
    ->pageTextContains('Facet ' . $facet_name . ' - 2 has been updated.');

  // Make sure the "-2" suffix is still on the facet when editing a facet.
  $this
    ->drupalGet($facet_edit_page);
  $this
    ->assertSession()
    ->responseContains('Facet settings for ' . $facet_name . ' - 2 facet');

  // Edit the form and change the facet's name back to the initial name.
  $form_values = [
    'name' => $facet_name,
  ];
  $this
    ->drupalPostForm($facet_edit_page, $form_values, 'Save');

  // Make sure that the redirection back to the overview was successful and
  // the edited facet is shown on the overview page.
  $this
    ->assertSession()
    ->pageTextContains('Facet ' . $facet_name . ' has been updated.');
  $facet_edit_page = '/admin/config/search/facets/' . $facet_id . '/edit';
  $this
    ->drupalGet($facet_edit_page);
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->pageTextContains('View Search API Test Fulltext search view, display Page');
}