You are here

public function LingotekContentEntityGetProfileHookTest::testProfileOverrideOnUploadTranslation in Lingotek Translation 3.0.x

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

Tests that a profile can be overridden before uploading.

File

tests/src/Functional/LingotekContentEntityGetProfileHookTest.php, line 84

Class

LingotekContentEntityGetProfileHookTest
Tests the hooks for getting content entity associated profile.

Namespace

Drupal\Tests\lingotek\Functional

Code

public function testProfileOverrideOnUploadTranslation() {
  $this
    ->saveLingotekContentTranslationSettings([
    'node' => [
      'article' => [
        'profiles' => 'manual',
        'fields' => [
          'title' => 1,
          'body' => 1,
        ],
      ],
    ],
    'comment' => [
      'comment' => [
        'profiles' => 'automatic',
        'fields' => [
          'comment_body' => 1,
        ],
      ],
    ],
  ]);
  $profile1 = LingotekProfile::create([
    'id' => 'group_1',
    'label' => 'Group 1',
    'auto_upload' => TRUE,
    'intelligence_metadata' => [
      'override' => TRUE,
      'use_business_division' => TRUE,
      'business_division' => 'Group 1',
    ],
  ]);
  $profile1
    ->save();
  $profile2 = LingotekProfile::create([
    'id' => 'group_2',
    'label' => 'Group 2',
    'auto_upload' => TRUE,
    'intelligence_metadata' => [
      'override' => TRUE,
      'use_business_division' => TRUE,
      'business_division' => 'Group 2',
    ],
  ]);
  $profile2
    ->save();
  $this
    ->drupalGet("/admin/lingotek/settings/profile/group_1/edit");

  // Create a node with group 1 profile.
  $edit = [];
  $edit['title[0][value]'] = 'Llamas are cool';
  $edit['body[0][value]'] = 'Llamas are very cool';
  $edit['langcode[0][value]'] = 'en';
  $edit['lingotek_translation_management[lingotek_translation_profile]'] = 'group_1';
  $this
    ->saveAndPublishNodeForm($edit);

  // Save a comment for the group_1 node.
  $edit = [];
  $edit['subject[0][value]'] = 'Group 1 test';
  $edit['comment_body[0][value]'] = 'Group 1 test body';
  $this
    ->drupalPostForm(NULL, $edit, 'Save');

  // Check that the configured fields have been uploaded, but also the one
  // added via the hook.
  $data = json_decode(\Drupal::state()
    ->get('lingotek.uploaded_content', '[]'), TRUE);
  $this
    ->assertUploadedDataFieldCount($data, 1);
  $this
    ->assertTrue(isset($data['comment_body'][0]['value']));
  $this
    ->assertEquals('Group 1', $data['_lingotek_metadata']['_intelligence']['business_division']);

  // Create a node with group 1 profile.
  $edit = [];
  $edit['title[0][value]'] = 'Llamas are cool 2';
  $edit['body[0][value]'] = 'Llamas are very cool 2';
  $edit['langcode[0][value]'] = 'en';
  $edit['lingotek_translation_management[lingotek_translation_profile]'] = 'group_2';
  $this
    ->saveAndPublishNodeForm($edit);

  // Save a comment for the group_1 node.
  $edit = [];
  $edit['subject[0][value]'] = 'Group 2 test';
  $edit['comment_body[0][value]'] = 'Group 2 test body';
  $this
    ->drupalPostForm(NULL, $edit, 'Save');

  // Check that the configured fields have been uploaded, but also the one
  // added via the hook.
  $data = json_decode(\Drupal::state()
    ->get('lingotek.uploaded_content', '[]'), TRUE);
  $this
    ->assertUploadedDataFieldCount($data, 1);
  $this
    ->assertTrue(isset($data['comment_body'][0]['value']));
  $this
    ->assertEquals('Group 2', $data['_lingotek_metadata']['_intelligence']['business_division']);
}