You are here

public function LingotekSettingsTabContentFormTest::testConfigureTranslatableEntityWithFieldsAndSubfields in Lingotek Translation 3.5.x

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

Test that we can configure entities at the subfield level.

1 call to LingotekSettingsTabContentFormTest::testConfigureTranslatableEntityWithFieldsAndSubfields()
LingotekSettingsTabContentFormTest::testDisableTranslatableEntity in tests/src/Functional/Form/LingotekSettingsTabContentFormTest.php
Test that we can configure entities at the subfield level.

File

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

Class

LingotekSettingsTabContentFormTest
Tests the Lingotek content settings form.

Namespace

Drupal\Tests\lingotek\Functional\Form

Code

public function testConfigureTranslatableEntityWithFieldsAndSubfields() {

  // 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);
  ContentLanguageSettings::loadByEntityTypeBundle('user', 'user')
    ->setLanguageAlterable(TRUE)
    ->save();
  \Drupal::service('content_translation.manager')
    ->setEnabled('user', 'user', 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();

  // Check the form contains the article type and only its text-based fields.
  $this
    ->drupalGet('admin/lingotek/settings');
  $this
    ->assertNoText('There are no translatable content types specified');
  $this
    ->assertNoField('node[article][fields][langcode]');
  $this
    ->assertField('node[article][enabled]');
  $this
    ->assertField('node[article][profiles]');
  $this
    ->assertField('node[article][fields][title]');
  $this
    ->assertField('node[article][fields][body]');

  // Check the title and body fields.
  $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',
    'user[user][enabled]' => 1,
    'user[user][fields][user_picture]' => 1,
    'user[user][fields][user_picture:properties][alt]' => 'alt',
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'Save', [], 'lingoteksettings-tab-content-form');

  // Check that values are kept in the form.
  $this
    ->assertFieldChecked('edit-node-article-enabled');
  $this
    ->assertFieldByName('node[article][profiles]', 'automatic');
  $this
    ->assertFieldChecked('edit-node-article-fields-title');
  $this
    ->assertFieldChecked('edit-node-article-fields-body');
  $this
    ->assertFieldChecked('edit-node-article-fields-field-image');
  $this
    ->assertFieldChecked('edit-node-article-fields-field-imageproperties-alt');
  $this
    ->assertNoFieldChecked('edit-node-article-fields-field-imageproperties-title');

  // Check that the config is correctly saved.
  $config_data = $this
    ->config('lingotek.settings')
    ->getRawData();
  $this
    ->assertTrue($config_data['translate']['entity']['node']['article']['enabled']);
  $this
    ->assertTrue($config_data['translate']['entity']['node']['article']['field']['title']);
  $this
    ->assertTrue($config_data['translate']['entity']['node']['article']['field']['body']);
  $this
    ->assertTrue($config_data['translate']['entity']['node']['article']['field']['field_image']);

  // As the schema here is sequence:ignore, there is no boolean casting.
  $this
    ->assertEqual($config_data['translate']['entity']['node']['article']['field']['field_image:properties']['alt'], '1');
  $this
    ->assertEqual($config_data['translate']['entity']['node']['article']['field']['field_image:properties']['title'], '0');
  $this
    ->assertFalse(array_key_exists('revision_log', $config_data['translate']['entity']['node']['article']['field']));
  $this
    ->assertEqual('automatic', $config_data['translate']['entity']['node']['article']['profile']);
}