You are here

public function LingotekNodeBulkFormTest::testDefaultProfile in Lingotek Translation 3.1.x

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

Tests default profile is shown in the content management page.

File

tests/src/Functional/Form/LingotekNodeBulkFormTest.php, line 669

Class

LingotekNodeBulkFormTest
Tests the bulk management form.

Namespace

Drupal\Tests\lingotek\Functional\Form

Code

public function testDefaultProfile() {

  // Create Page node types.
  $this
    ->drupalCreateContentType([
    'type' => 'page',
    'name' => 'Page',
  ]);

  // Enable translation for the page entity type and ensure the change is
  // picked up.
  ContentLanguageSettings::loadByEntityTypeBundle('node', 'page')
    ->setLanguageAlterable(TRUE)
    ->save();
  \Drupal::service('content_translation.manager')
    ->setEnabled('node', 'page', 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();
  $nodes = [];

  // Create a node.
  for ($i = 1; $i <= 3; $i++) {
    $bundle = 'page';
    $edit = [];
    $edit['title[0][value]'] = new FormattableMarkup('Llamas are cool @bundle @i', [
      '@bundle' => $bundle,
      '@i' => $i,
    ]);
    $edit['body[0][value]'] = $edit['title[0][value]'];
    $edit['langcode[0][value]'] = 'en';
    $this
      ->saveAndPublishNodeForm($edit, $bundle);
    $nodes[$i] = $edit;
  }
  $this
    ->goToContentBulkManagementForm();

  // Ensure there is no profile shown.
  for ($i = 1; $i <= 3; $i++) {
    $this
      ->assertManagementFormProfile($i, 'Not enabled');
  }

  // Enable automatic profile for pages.
  $this
    ->saveLingotekContentTranslationSettingsForNodeTypes([
    'page',
  ], 'automatic');

  // Now we should see the automatic profile.
  $this
    ->goToContentBulkManagementForm();

  // Ensure there is Automatic profile shown.
  for ($i = 1; $i <= 3; $i++) {
    $this
      ->assertManagementFormProfile($i, 'Automatic');
  }

  // Let's upload one node. The profile should be stored.
  $this
    ->clickLink('EN');

  // Ensure there is Automatic profile shown.
  for ($i = 1; $i <= 3; $i++) {
    $this
      ->assertManagementFormProfile($i, 'Automatic');
  }

  // Now we change the default profile. Should still be the same for the node
  // we uploaded.
  $this
    ->saveLingotekContentTranslationSettingsForNodeTypes([
    'page',
  ], 'manual');
  $this
    ->goToContentBulkManagementForm();

  // Ensure there is Automatic profile for node 1, but Manual profile for
  // nodes 2 and 3.
  $this
    ->assertManagementFormProfile(1, 'Automatic');
  for ($i = 2; $i <= 3; $i++) {
    $this
      ->assertManagementFormProfile($i, 'Manual');
  }
}