You are here

public function LingotekProfileFormTest::testProfileSettingsOverride in Lingotek Translation 8

Test profiles language settings override.

File

src/Tests/Form/LingotekProfileFormTest.php, line 285

Class

LingotekProfileFormTest
Tests the Lingotek profile form.

Namespace

Drupal\lingotek\Tests\Form

Code

public function testProfileSettingsOverride() {

  // Add a language.
  ConfigurableLanguage::createFromLangcode('es')
    ->setThirdPartySetting('lingotek', 'locale', 'es_MX')
    ->save();
  ConfigurableLanguage::createFromLangcode('de')
    ->setThirdPartySetting('lingotek', 'locale', 'de_DE')
    ->save();

  /** @var LingotekProfileInterface $profile */
  $profile = LingotekProfile::create([
    'id' => strtolower($this
      ->randomMachineName()),
    'label' => $this
      ->randomString(),
  ]);
  $profile
    ->save();
  $profile_id = $profile
    ->id();
  $this
    ->drupalGet("/admin/lingotek/settings/profile/{$profile_id}/edit");
  $this
    ->assertOptionSelected('edit-language-overrides-es-overrides', 'default');
  $this
    ->assertOptionSelected('edit-language-overrides-en-overrides', 'default');
  $edit = [
    'auto_upload' => FALSE,
    'auto_download' => 1,
    'project' => 'default',
    'vault' => 'default',
    'workflow' => 'another_workflow',
    'language_overrides[es][overrides]' => 'custom',
    'language_overrides[es][custom][auto_download]' => FALSE,
    'language_overrides[es][custom][workflow]' => 'test_workflow',
    'language_overrides[de][overrides]' => 'custom',
    'language_overrides[de][custom][auto_download]' => FALSE,
    'language_overrides[de][custom][workflow]' => 'default',
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Save'));

  /** @var LingotekProfileInterface $profile */
  $profile = LingotekProfile::load($profile_id);
  $this
    ->assertFalse($profile
    ->hasAutomaticUpload());
  $this
    ->assertTrue($profile
    ->hasAutomaticDownload());
  $this
    ->assertIdentical('default', $profile
    ->getProject());
  $this
    ->assertIdentical('default', $profile
    ->getVault());
  $this
    ->assertIdentical('another_workflow', $profile
    ->getWorkflow());
  $this
    ->assertIdentical('test_workflow', $profile
    ->getWorkflowForTarget('es'));
  $this
    ->assertIdentical('default', $profile
    ->getWorkflowForTarget('de'));
  $this
    ->assertFalse($profile
    ->hasAutomaticDownloadForTarget('es'));
  $this
    ->assertFalse($profile
    ->hasAutomaticDownloadForTarget('de'));
  $this
    ->drupalGet("/admin/lingotek/settings/profile/{$profile_id}/edit");
  $this
    ->assertNoFieldChecked("edit-auto-upload");
  $this
    ->assertFieldChecked("edit-auto-download");
  $this
    ->assertOptionSelected('edit-project', 'default');
  $this
    ->assertOptionSelected('edit-vault', 'default');
  $this
    ->assertOptionSelected('edit-workflow', 'another_workflow');
  $this
    ->assertOptionSelected('edit-language-overrides-es-overrides', 'custom');
  $this
    ->assertOptionSelected('edit-language-overrides-de-overrides', 'custom');
  $this
    ->assertOptionSelected('edit-language-overrides-en-overrides', 'default');
  $this
    ->assertNoFieldChecked('edit-language-overrides-es-custom-auto-download');
  $this
    ->assertNoFieldChecked('edit-language-overrides-de-custom-auto-download');
  $this
    ->assertFieldChecked('edit-language-overrides-en-custom-auto-download');
  $this
    ->assertOptionSelected('edit-language-overrides-es-custom-workflow', 'test_workflow');
  $this
    ->assertOptionSelected('edit-language-overrides-de-custom-workflow', 'default');
  $this
    ->assertOptionSelected('edit-language-overrides-en-custom-workflow', 'default');

  // Assert that the override languages are present and ordered alphabetically.
  $selects = $this
    ->xpath('//details[@id="edit-language-overrides"]/*/*//select');

  // There must be 2 select options for each of the 3 languages.
  $this
    ->assertEqual(count($selects), 2 * 3, 'There are options for all the potential language overrides.');

  // And the first one must be German alphabetically.
  $this
    ->assertEqual((string) $selects[0]['id'], 'edit-language-overrides-de-overrides', 'Languages are ordered alphabetically.');
}