You are here

public function GoogleTranslatorTest::testGoogleUi in TMGMT Translator Google 8

Tests the UI of the plugin.

File

tests/src/Functional/GoogleTranslatorTest.php, line 155

Class

GoogleTranslatorTest
Basic tests for the google translator.

Namespace

Drupal\Tests\tmgmt_google\Functional

Code

public function testGoogleUi() {
  $url = Url::fromRoute('entity.tmgmt_translator.edit_form', [
    'tmgmt_translator' => $this->translator
      ->id(),
  ]);
  $this
    ->loginAsAdmin();

  // Try to connect with invalid credentials.
  $edit = [
    'settings[api_key]' => 'wrong key',
  ];
  $this
    ->drupalPostForm($url, $edit, t('Connect'));
  $this
    ->assertText(t('The "Google API key" is not correct.'));

  // Test connection with valid credentials.
  $edit = [
    'settings[api_key]' => 'correct key',
  ];
  $this
    ->drupalPostForm($url, $edit, t('Connect'));
  $this
    ->assertText('Successfully connected!');

  // Assert that default remote languages mappings were updated.
  $this
    ->assertOptionSelected('edit-remote-languages-mappings-en', 'en');
  $this
    ->assertOptionSelected('edit-remote-languages-mappings-de', 'de');
  $this
    ->drupalPostForm(NULL, [], t('Save'));
  $this
    ->assertText(t('@label configuration has been updated.', [
    '@label' => $this->translator
      ->label(),
  ]));
}