You are here

public function LingotekGetSourceDataTest::testFieldsAreNotExtractedIfNotTranslatableEvenIfStorageIsTranslatable in Lingotek Translation 3.6.x

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

File

tests/src/Functional/LingotekGetSourceDataTest.php, line 54

Class

LingotekGetSourceDataTest
Tests the Lingotek content service extract data from entities correctly.

Namespace

Drupal\Tests\lingotek\Functional

Code

public function testFieldsAreNotExtractedIfNotTranslatableEvenIfStorageIsTranslatable() {

  // Ensure field storage is translatable.
  $field_storage = FieldStorageConfig::loadByName('node', 'body');
  $field_storage
    ->setTranslatable(TRUE)
    ->save();

  // Ensure field instance is translatable.
  $field = FieldConfig::loadByName('node', 'article', 'body');
  $field
    ->setTranslatable(TRUE)
    ->save();

  // Ensure changes were saved correctly.
  $field_storage = FieldStorageConfig::loadByName('node', 'body');
  $field = FieldConfig::loadByName('node', 'article', 'body');
  $this
    ->assertTrue($field_storage
    ->isTranslatable(), 'Field storage is translatable.');
  $this
    ->assertTrue($field
    ->isTranslatable(), 'Field instance is translatable.');

  // Create a node.
  $node = $this
    ->createNode([
    'type' => 'article',
  ]);

  /** @var \Drupal\lingotek\LingotekContentTranslationServiceInterface $translation_service */
  $translation_service = \Drupal::service('lingotek.content_translation');
  $serialized_node = $translation_service
    ->getSourceData($node);
  $this
    ->assertTrue(isset($serialized_node['body']), 'The body is included in the extracted data.');

  // Make the field as not translatable.
  $field
    ->setTranslatable(FALSE)
    ->save();
  $this
    ->assertTrue($field_storage
    ->isTranslatable(), 'Field storage is translatable.');
  $this
    ->assertFalse($field
    ->isTranslatable(), 'Field instance is not translatable.');

  // If the field is not translatable, the field is not there.
  $translation_service = \Drupal::service('lingotek.content_translation');
  $serialized_node = $translation_service
    ->getSourceData($node);
  $this
    ->assertFalse(isset($serialized_node['body']), 'The body is not included in the extracted data.');
}