public function TMGMTUiJavascriptTest::testSourceUpdate

Tests update the source and show the diff of the source.

File

tests/src/FunctionalJavascript/TMGMTUiJavascriptTest.php, line 516

Class

TMGMTUiJavascriptTest
Verifies the UI of the review form.

Namespace

Drupal\Tests\tmgmt\FunctionalJavascript

Code

public function testSourceUpdate() {
  $page = $this
    ->getSession()
    ->getPage();
  $assert_session = $this
    ->assertSession();

  // Create the original data items.
  $job = $this
    ->createJob('en', 'de');
  $job->translator = $this->default_translator;
  $job
    ->save();
  \Drupal::state()
    ->set('tmgmt.test_source_data', [
    'title' => [
      '#label' => 'Example text 1',
      'deep_nesting' => [
        '#text' => 'Text for job item with type test and id 1.',
        '#label' => 'Example text 1',
        '#translate' => TRUE,
      ],
    ],
    'sayonara_text' => [
      '#label' => 'Example text 2',
      'deep_nesting' => [
        '#text' => 'This text will end badly.',
        '#label' => 'Example text 2',
        '#translate' => TRUE,
      ],
    ],
  ]);
  $job
    ->addItem('test_source', 'test', '1');
  $job
    ->save();
  $this
    ->drupalGet($job
    ->toUrl());
  $edit = array(
    'target_language' => 'de',
    'settings[action]' => 'submit',
  );
  $this
    ->submitForm($edit, 'Submit to provider');
  $job
    ->requestTranslation();

  // Modify the source.
  \Drupal::state()
    ->set('tmgmt.test_source_data', array(
    'title' => array(
      '#label' => 'Example text modified',
      'deep_nesting' => array(
        '#text' => 'This source has been changed.',
        '#label' => 'Example text modified',
        '#translate' => TRUE,
      ),
    ),
  ));

  // Show a message informing of the conflicts in the sources.
  $this
    ->drupalGet('admin/tmgmt/items/1');
  $assert_session
    ->pageTextContains('The source has changed.');
  $assert_session
    ->pageTextContains('This data item has been removed from the source.');

  // Show changes as diff.
  $page
    ->pressButton('diff-button-title|deep_nesting');
  $assert_session
    ->assertWaitOnAjaxRequest();
  $assert_session
    ->pageTextNotContains('The source has changed.');
  $assert_session
    ->pageTextContains('Text for job item with type test and id 1.');
  $assert_session
    ->pageTextContains('This source has been changed.');
  $assert_session
    ->pageTextContains('This data item has been removed from the source.');

  // Resolve the first data item.
  $page
    ->pressButton('resolve-diff-title|deep_nesting');
  $assert_session
    ->assertWaitOnAjaxRequest();
  $assert_session
    ->pageTextContains('The conflict in the data item source "Example text modified" has been resolved.');
  $assert_session
    ->pageTextNotContains('The source has changed.');
  $xpath = $this
    ->xpath('//*[@name="title|deep_nesting[source]"]')[0];
  $this
    ->assertEquals('This source has been changed.', $xpath
    ->getHtml());

  // Check the other data item was not modified.
  $assert_session
    ->pageTextContains('This data item has been removed from the source.');
  $assert_session
    ->pageTextContains('This text will end badly.');
}