You are here

protected function CoreViewsIntegrationTest::editFacet in Core Views Facets 8

Tests editing of a facet through the UI.

Parameters

string $facet_name: The name of the facet.

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

File

tests/src/Functional/CoreViewsIntegrationTest.php, line 317

Class

CoreViewsIntegrationTest
Tests the overall functionality of the Facets admin UI.

Namespace

Drupal\Tests\core_views_facets\Functional

Code

protected function editFacet($facet_name) {
  $facet_id = $this
    ->convertNameToMachineName($facet_name);
  $facet_edit_page = Url::fromRoute('entity.facets_facet.settings_form', [
    'facets_facet' => $facet_id,
  ]);

  // 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.');
}