You are here

public function LingotekSettingsTabContentFormTest::testCreateFieldAndUseLingotekToTranslateWithImageProperties in Lingotek Translation 3.7.x

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

Tests the "Use Lingotek To Translate" option when creating a new image field with properties

File

tests/src/Functional/Form/LingotekSettingsTabContentFormTest.php, line 576

Class

LingotekSettingsTabContentFormTest
Tests the Lingotek content settings form.

Namespace

Drupal\Tests\lingotek\Functional\Form

Code

public function testCreateFieldAndUseLingotekToTranslateWithImageProperties() {

  // Enable translation for the current entity type and ensure the change is
  // picked up.
  ContentLanguageSettings::loadByEntityTypeBundle('node', 'article')
    ->setLanguageAlterable(TRUE)
    ->save();
  \Drupal::service('content_translation.manager')
    ->setEnabled('node', 'article', TRUE);
  drupal_static_reset();
  \Drupal::entityTypeManager()
    ->clearCachedDefinitions();
  $this
    ->applyEntityUpdates();

  // Rebuild the container so that the new languages are picked up by services
  // that hold a list of languages.
  $this
    ->rebuildContainer();
  $this
    ->applyEntityUpdates();
  $this
    ->drupalGet('admin/lingotek/settings');

  // Check the form contains the fields but they are disabled.
  $this
    ->assertNoFieldChecked('edit-node-article-fields-body');
  $this
    ->assertNoFieldChecked('edit-node-article-fields-field-image');
  $this
    ->assertNoFieldChecked('edit-node-article-fields-field-imageproperties-alt');

  // Check image and alt subfield.
  $edit = [
    'node[article][enabled]' => 1,
    'node[article][profiles]' => 'automatic',
    'node[article][fields][title]' => 1,
    'node[article][fields][body]' => 1,
    'node[article][fields][field_image]' => 1,
    'node[article][fields][field_image:properties][alt]' => 'alt',
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'Save', [], 'lingoteksettings-tab-content-form');
  $this
    ->assertFieldChecked('edit-node-article-fields-body');
  $this
    ->assertFieldChecked('edit-node-article-fields-field-image');
  $this
    ->assertNoFieldChecked('edit-node-article-fields-field-imageproperties-file');
  $this
    ->assertFieldChecked('edit-node-article-fields-field-imageproperties-alt');
  $this
    ->assertNoFieldChecked('edit-node-article-fields-field-imageproperties-title');

  // Submit again unchecking image including subfields.
  $edit = [
    'node[article][fields][field_image]' => FALSE,
    'node[article][fields][field_image:properties][alt]' => FALSE,
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'Save', [], 'lingoteksettings-tab-content-form');

  // Those checkboxes should not be checked anymore.
  $this
    ->assertFieldChecked('edit-node-article-fields-body');
  $this
    ->assertNoFieldChecked('edit-node-article-fields-field-image');
  $this
    ->assertNoFieldChecked('edit-node-article-fields-field-imageproperties-file');
  $this
    ->assertNoFieldChecked('edit-node-article-fields-field-imageproperties-alt');
  $this
    ->assertNoFieldChecked('edit-node-article-fields-field-imageproperties-title');
  $this
    ->drupalGet('/admin/config/regional/config-translation/node_fields');
  $this
    ->clickLink(t('Translate'), 1);
  $this
    ->clickLink('Edit');
  $this
    ->assertNoFieldChecked('edit-translatable-for-lingotek');
  $this
    ->assertNoFieldChecked('edit-third-party-settings-content-translation-translation-sync-file');
  $this
    ->assertFieldChecked('edit-third-party-settings-content-translation-translation-sync-alt');
  $this
    ->assertFieldChecked('edit-third-party-settings-content-translation-translation-sync-title');
  $this
    ->assertNoFieldChecked('edit-translatable-for-lingotek-properties-file');
  $this
    ->assertNoFieldChecked('edit-translatable-for-lingotek-properties-alt');
  $this
    ->assertNoFieldChecked('edit-translatable-for-lingotek-properties-title');
  $edit = [
    'translatable_for_lingotek' => 1,
    'third_party_settings[content_translation][translation_sync][alt]' => 'alt',
    'translatable_for_lingotek_properties_alt' => 1,
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'Save settings');
  $this
    ->clickLink('Edit');
  $this
    ->assertFieldChecked('edit-translatable-for-lingotek');
  $this
    ->assertNoFieldChecked('edit-third-party-settings-content-translation-translation-sync-file');
  $this
    ->assertFieldChecked('edit-third-party-settings-content-translation-translation-sync-alt');
  $this
    ->assertFieldChecked('edit-third-party-settings-content-translation-translation-sync-title');
  $this
    ->assertNoFieldChecked('edit-translatable-for-lingotek-properties-file');
  $this
    ->assertFieldChecked('edit-translatable-for-lingotek-properties-alt');
  $this
    ->assertNoFieldChecked('edit-translatable-for-lingotek-properties-title');
  $this
    ->drupalGet('/admin/lingotek/settings');
  $this
    ->assertFieldChecked("edit-node-article-fields-field-image");
  $this
    ->assertNoFieldChecked('edit-node-article-fields-field-imageproperties-file');
  $this
    ->assertFieldChecked('edit-node-article-fields-field-imageproperties-alt');
  $this
    ->assertNoFieldChecked('edit-node-article-fields-field-imageproperties-title');
  $edit = [
    'node[article][fields][field_image]' => 1,
    'node[article][fields][field_image:properties][file]' => FALSE,
    'node[article][fields][field_image:properties][alt]' => FALSE,
    'node[article][fields][field_image:properties][title]' => FALSE,
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'Save', [], 'lingoteksettings-tab-content-form');
  $this
    ->assertNoFieldChecked('edit-node-article-fields-field-imageproperties-file');
  $this
    ->assertNoFieldChecked('edit-node-article-fields-field-imageproperties-alt');
  $this
    ->assertNoFieldChecked('edit-node-article-fields-field-imageproperties-title');
  $this
    ->drupalGet('/admin/config/regional/config-translation/node_fields');
  $this
    ->clickLink(t('Translate'), 1);
  $this
    ->clickLink('Edit');
  $edit = [
    'translatable_for_lingotek' => 1,
    'third_party_settings[content_translation][translation_sync][file]' => 'file',
    'third_party_settings[content_translation][translation_sync][alt]' => 'alt',
    'third_party_settings[content_translation][translation_sync][title]' => 'title',
    'translatable_for_lingotek_properties_alt' => 1,
    'translatable_for_lingotek_properties_title' => 1,
    'translatable_for_lingotek_properties_file' => 1,
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'Save settings');
  $this
    ->clickLink('Edit');
  $this
    ->assertFieldChecked('edit-translatable-for-lingotek');
  $this
    ->assertFieldChecked('edit-third-party-settings-content-translation-translation-sync-file');
  $this
    ->assertFieldChecked('edit-third-party-settings-content-translation-translation-sync-alt');
  $this
    ->assertFieldChecked('edit-third-party-settings-content-translation-translation-sync-title');
  $this
    ->assertFieldChecked('edit-translatable-for-lingotek-properties-file');
  $this
    ->assertFieldChecked('edit-translatable-for-lingotek-properties-alt');
  $this
    ->assertFieldChecked('edit-translatable-for-lingotek-properties-title');
  $this
    ->drupalGet('/admin/lingotek/settings');
  $this
    ->assertFieldChecked("edit-node-article-fields-field-image");
  $this
    ->assertFieldChecked('edit-node-article-fields-field-imageproperties-file');
  $this
    ->assertFieldChecked('edit-node-article-fields-field-imageproperties-alt');
  $this
    ->assertFieldChecked('edit-node-article-fields-field-imageproperties-title');
  $edit = [
    'node[article][fields][field_image]' => 1,
    'node[article][fields][field_image:properties][file]' => FALSE,
    'node[article][fields][field_image:properties][alt]' => FALSE,
    'node[article][fields][field_image:properties][title]' => FALSE,
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'Save', [], 'lingoteksettings-tab-content-form');
  $this
    ->assertFieldChecked("edit-node-article-fields-field-image");
  $this
    ->assertNoFieldChecked('edit-node-article-fields-field-imageproperties-file');
  $this
    ->assertNoFieldChecked('edit-node-article-fields-field-imageproperties-alt');
  $this
    ->assertNoFieldChecked('edit-node-article-fields-field-imageproperties-title');
  $this
    ->drupalGet('/admin/config/regional/config-translation/node_fields');
  $this
    ->clickLink(t('Translate'), 1);
  $this
    ->clickLink('Edit');
  $edit = [
    'translatable_for_lingotek' => 1,
    'third_party_settings[content_translation][translation_sync][alt]' => FALSE,
    'third_party_settings[content_translation][translation_sync][title]' => FALSE,
    'third_party_settings[content_translation][translation_sync][file]' => FALSE,
    'translatable_for_lingotek_properties_alt' => 1,
    'translatable_for_lingotek_properties_title' => 1,
    'translatable_for_lingotek_properties_file' => 1,
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'Save settings');
  $this
    ->clickLink('Edit');
  $this
    ->assertFieldChecked('edit-translatable-for-lingotek');
  $this
    ->assertNoFieldChecked('edit-third-party-settings-content-translation-translation-sync-file');
  $this
    ->assertNoFieldChecked('edit-third-party-settings-content-translation-translation-sync-alt');
  $this
    ->assertNoFieldChecked('edit-third-party-settings-content-translation-translation-sync-title');
  $this
    ->assertNoFieldChecked('edit-translatable-for-lingotek-properties-file');
  $this
    ->assertNoFieldChecked('edit-translatable-for-lingotek-properties-alt');
  $this
    ->assertNoFieldChecked('edit-translatable-for-lingotek-properties-title');
  $this
    ->drupalGet('/admin/lingotek/settings');
  $this
    ->assertFieldChecked("edit-node-article-fields-field-image");
  $this
    ->assertNoFieldChecked('edit-node-article-fields-field-imageproperties-alt');
  $this
    ->assertNoFieldChecked('edit-node-article-fields-field-imageproperties-title');
  $this
    ->assertNoFieldChecked('edit-node-article-fields-field-imageproperties-file');
  $edit = [
    'node[article][fields][field_image]' => 1,
    'node[article][fields][field_image:properties][alt]' => FALSE,
    'node[article][fields][field_image:properties][title]' => FALSE,
    'node[article][fields][field_image:properties][file]' => FALSE,
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'Save', [], 'lingoteksettings-tab-content-form');
  $this
    ->assertNoFieldChecked('edit-node-article-fields-field-imageproperties-alt');
  $this
    ->assertNoFieldChecked('edit-node-article-fields-field-imageproperties-title');
  $this
    ->assertNoFieldChecked('edit-node-article-fields-field-imageproperties-file');
}