You are here

public function LingotekProfileFormTest::testProfileSettingsOverride in Lingotek Translation 3.3.x

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/Form/LingotekProfileFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekProfileFormTest::testProfileSettingsOverride()
  2. 4.0.x tests/src/Functional/Form/LingotekProfileFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekProfileFormTest::testProfileSettingsOverride()
  3. 3.0.x tests/src/Functional/Form/LingotekProfileFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekProfileFormTest::testProfileSettingsOverride()
  4. 3.1.x tests/src/Functional/Form/LingotekProfileFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekProfileFormTest::testProfileSettingsOverride()
  5. 3.2.x tests/src/Functional/Form/LingotekProfileFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekProfileFormTest::testProfileSettingsOverride()
  6. 3.4.x tests/src/Functional/Form/LingotekProfileFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekProfileFormTest::testProfileSettingsOverride()
  7. 3.5.x tests/src/Functional/Form/LingotekProfileFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekProfileFormTest::testProfileSettingsOverride()
  8. 3.6.x tests/src/Functional/Form/LingotekProfileFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekProfileFormTest::testProfileSettingsOverride()
  9. 3.7.x tests/src/Functional/Form/LingotekProfileFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekProfileFormTest::testProfileSettingsOverride()
  10. 3.8.x tests/src/Functional/Form/LingotekProfileFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekProfileFormTest::testProfileSettingsOverride()

Test profiles language settings override.

File

tests/src/Functional/Form/LingotekProfileFormTest.php, line 378

Class

LingotekProfileFormTest
Tests the Lingotek profile form.

Namespace

Drupal\Tests\lingotek\Functional\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 \Drupal\lingotek\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' => 'test_workflow2',
    'language_overrides[es][overrides]' => 'custom',
    'language_overrides[es][custom][auto_download]' => FALSE,
    'language_overrides[es][custom][workflow]' => 'test_workflow',
    'language_overrides[es][custom][vault]' => 'test_vault',
    'language_overrides[de][overrides]' => 'custom',
    'language_overrides[de][custom][auto_download]' => FALSE,
    'language_overrides[de][custom][workflow]' => 'default',
    'language_overrides[de][custom][vault]' => 'default',
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Save'));

  /** @var \Drupal\lingotek\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('test_workflow2', $profile
    ->getWorkflow());
  $this
    ->assertIdentical('test_workflow', $profile
    ->getWorkflowForTarget('es'));
  $this
    ->assertIdentical('default', $profile
    ->getWorkflowForTarget('de'));
  $this
    ->assertIdentical('test_vault', $profile
    ->getVaultForTarget('es'));
  $this
    ->assertIdentical('default', $profile
    ->getVaultForTarget('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', 'test_workflow2');
  $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), 3 * 3, 'There are options for all the potential language overrides.');

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