public function TMGMTUiTest::testSuggestions

Tests the UI of suggestions.

File

tests/src/Functional/TMGMTUiTest.php, line 424

Class

TMGMTUiTest
Verifies basic functionality of the user interface

Namespace

Drupal\Tests\tmgmt\Functional

Code

public function testSuggestions() {

  // Prepare a job and a node for testing.
  $job = $this
    ->createJob();
  $job
    ->addItem('test_source', 'test', 1);
  $job
    ->addItem('test_source', 'test', 7);

  // Go to checkout form.
  $this
    ->drupalGet($job
    ->toUrl());
  $this
    ->assertSession()
    ->responseContains('20');

  // Verify that suggestions are immediately visible.
  $this
    ->assertSession()
    ->pageTextContains('test_source:test_suggestion:1');
  $this
    ->assertSession()
    ->pageTextContains('test_source:test_suggestion:7');
  $this
    ->assertSession()
    ->pageTextContains('Test suggestion for test source 1');
  $this
    ->assertSession()
    ->pageTextContains('Test suggestion for test source 7');

  // Add the second suggestion.
  $edit = array(
    'suggestions_table[2]' => TRUE,
  );
  $this
    ->submitForm($edit, 'Add suggestions');

  // Total word count should now include the added job.
  $this
    ->assertSession()
    ->responseContains('31');

  // The suggestion for 7 was added, so there should now be a suggestion
  // for the suggestion instead.
  $this
    ->assertSession()
    ->pageTextNotContains('Test suggestion for test source 7');
  $this
    ->assertSession()
    ->pageTextContains('test_source:test_suggestion_suggestion:7');

  // The HTML test source does not provide suggestions, ensure that the
  // suggestions UI does not show up if there are none.
  $job = $this
    ->createJob();
  $job
    ->addItem('test_html_source', 'test', 1);
  $this
    ->drupalGet($job
    ->toUrl());
  $this
    ->assertSession()
    ->pageTextNotContains('Suggestions');
}