You are here

protected function IntegrationTest::configureSearch in Search API Autocomplete 8

Configures the test search via the UI.

1 call to IntegrationTest::configureSearch()
IntegrationTest::testModule in tests/src/FunctionalJavascript/IntegrationTest.php
Tests the complete functionality of the module via the UI.

File

tests/src/FunctionalJavascript/IntegrationTest.php, line 124

Class

IntegrationTest
Tests the functionality of the whole module from a user's perspective.

Namespace

Drupal\Tests\search_api_autocomplete\FunctionalJavascript

Code

protected function configureSearch() {
  $assert_session = $this
    ->assertSession();
  $this
    ->click('.dropbutton-action a[href$="/edit"]');
  $this
    ->logPageChange();
  $assert_session
    ->addressEquals($this
    ->getAdminPath('edit'));

  // The "Server" suggester shouldn't be available at that point.
  $assert_session
    ->elementExists('css', 'input[name="suggesters[enabled][search_api_autocomplete_test]"]');
  $assert_session
    ->elementNotExists('css', 'input[name="suggesters[enabled][server]"]');
  $assert_session
    ->elementNotExists('css', 'input[name="suggesters[enabled][custom_script]"]');

  // Make the test backend support autocomplete so that the "Server" suggester
  // becomes available.
  $callback = [
    TestsHelper::class,
    'getSupportedFeatures',
  ];
  $this
    ->setMethodOverride('backend', 'getSupportedFeatures', $callback);
  $callback = [
    TestsHelper::class,
    'getAutocompleteSuggestions',
  ];
  $this
    ->setMethodOverride('backend', 'getAutocompleteSuggestions', $callback);

  // After refreshing, the "Server" suggester should now be available. But by
  // default, it should not be checked (one of the others should be the only
  // one). The "Custom scripts" suggester should not be available.
  $this
    ->getSession()
    ->reload();
  $this
    ->logPageChange();
  $assert_session
    ->checkboxNotChecked('suggesters[enabled][server]');
  $assert_session
    ->elementNotExists('css', 'input[name="suggesters[enabled][custom_script]"]');

  // The "Server" suggester's config form is hidden by default, but displayed
  // once we check its "Enabled" checkbox.
  $this
    ->assertNotVisible('css', 'details[data-drupal-selector="edit-suggesters-settings-server"]');
  $this
    ->click('input[name="suggesters[enabled][server]"]');
  $this
    ->assertVisible('css', 'details[data-drupal-selector="edit-suggesters-settings-server"]');
  $page = $this
    ->getSession()
    ->getPage();
  $page
    ->findButton('Show row weights')
    ->click();
  $page
    ->find('css', 'details[data-drupal-selector="edit-suggesters-settings-server"] > summary')
    ->click();

  // Submit the form with some values for all fields.
  $edit = [
    'suggesters[enabled][live_results]' => FALSE,
    'suggesters[enabled][search_api_autocomplete_test]' => TRUE,
    'suggesters[weights][search_api_autocomplete_test][limit]' => '3',
    'suggesters[weights][server][limit]' => '3',
    'suggesters[weights][search_api_autocomplete_test][weight]' => '0',
    'suggesters[weights][server][weight]' => '10',
    'suggesters[settings][server][fields][name]' => FALSE,
    'suggesters[settings][server][fields][body]' => TRUE,
    'search_settings[displays][selected][default]' => FALSE,
    'options[limit]' => '5',
    'options[min_length]' => '2',
    'options[show_count]' => TRUE,
    'options[delay]' => '1000',
  ];
  $this
    ->submitForm($edit, 'Save');
}