You are here

protected function IntegrationTest::addFacet in Facets 8

Tests adding a facet trough the interface.

Parameters

string $facet_name: The name of the facet.

string $facet_type: The field of the facet.

string $source_id: The facet source id.

4 calls to IntegrationTest::addFacet()
IntegrationTest::testBlockView in tests/src/Functional/IntegrationTest.php
Tests that a block view also works.
IntegrationTest::testFacetCountCalculations in tests/src/Functional/IntegrationTest.php
Tests calculations of facet count.
IntegrationTest::testFacetDependencies in tests/src/Functional/IntegrationTest.php
Tests facet dependencies.
IntegrationTest::testFramework in tests/src/Functional/IntegrationTest.php
Tests various operations via the Facets' admin UI.

File

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

Class

IntegrationTest
Tests the overall functionality of the Facets admin UI.

Namespace

Drupal\Tests\facets\Functional

Code

protected function addFacet($facet_name, $facet_type = 'type', $source_id = 'search_api:views_page__search_api_test_view__page_1') {
  $facet_id = $this
    ->convertNameToMachineName($facet_name);

  // Go to the Add facet page and make sure that returns a 200.
  $facet_add_page = '/admin/config/search/facets/add-facet';
  $this
    ->drupalGet($facet_add_page);
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $form_values = [
    'name' => '',
    'id' => $facet_id,
  ];

  // Try filling out the form, but without having filled in a name for the
  // facet to test for form errors.
  $this
    ->drupalPostForm($facet_add_page, $form_values, 'Save');
  $this
    ->assertSession()
    ->pageTextContains('Name field is required.');
  $this
    ->assertSession()
    ->pageTextContains('Facet source field is required.');

  // Make sure that when filling out the name, the form error disappears.
  $form_values['name'] = $facet_name;
  $this
    ->drupalPostForm(NULL, $form_values, 'Save');
  $this
    ->assertSession()
    ->pageTextNotContains('Name field is required.');

  // Configure the facet source by selecting one of the Search API views.
  $this
    ->drupalGet($facet_add_page);
  $this
    ->drupalPostForm(NULL, [
    'facet_source_id' => '' . $source_id . '',
  ], 'Configure facet source');

  // The field is still required.
  $this
    ->drupalPostForm(NULL, $form_values, 'Save');
  $this
    ->assertSession()
    ->pageTextContains('Field field is required.');

  // Fill in all fields and make sure the 'field is required' message is no
  // longer shown.
  $facet_source_form = [
    'facet_source_id' => $source_id,
    'facet_source_configs[' . $source_id . '][field_identifier]' => $facet_type,
  ];
  $this
    ->drupalPostForm(NULL, $form_values + $facet_source_form, 'Save');
  $this
    ->assertSession()
    ->pageTextNotContains('field is required.');

  // Make sure that the redirection to the display page is correct.
  $this
    ->assertSession()
    ->pageTextContains('Facet ' . $facet_name . ' has been created.');
  $this
    ->assertSession()
    ->addressEquals('admin/config/search/facets/' . $facet_id . '/edit');
  $this
    ->drupalGet('admin/config/search/facets');
}