You are here

LingotekNotEnabledNodeBulkTranslationTest.php in Lingotek Translation 8.2

File

tests/src/Functional/LingotekNotEnabledNodeBulkTranslationTest.php
View source
<?php

namespace Drupal\Tests\lingotek\Functional;

use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\lingotek\Lingotek;

/**
 * Tests what happens when uploading a not enabled node using the bulk management form.
 *
 * @group lingotek
 * @group legacy
 */
class LingotekNotEnabledNodeBulkTranslationTest extends LingotekTestBase {

  /**
   * {@inheritdoc}
   */
  public static $modules = [
    'block',
    'node',
  ];

  /**
   * A node.
   *
   * @var \Drupal\node\NodeInterface
   */
  protected $node;

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();

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

    // Add a language.
    ConfigurableLanguage::createFromLangcode('es')
      ->setThirdPartySetting('lingotek', 'locale', 'es_MX')
      ->save();

    // 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
      ->saveLingotekContentTranslationSettingsForNodeTypes();
  }

  /**
   * Tests that a node can be translated using the links on the management page.
   */
  public function testNodeTranslationUsingLinks() {

    // Create a node.
    $edit = [];
    $edit['title[0][value]'] = 'Llamas are cool';
    $edit['body[0][value]'] = 'Llamas are very cool';
    $this
      ->saveAndPublishNodeForm($edit, 'page');

    // Login as translation manager.
    $this
      ->drupalLogin($this->translationManagerUser);
    $this
      ->goToContentBulkManagementForm();

    // Clicking English must init the upload of content.
    $this
      ->assertLingotekUploadLink();

    // And we cannot request yet a translation.
    $this
      ->assertNoLingotekRequestTranslationLink('es_MX');
    $this
      ->clickLink('EN');
    $this
      ->assertText('The upload for node Llamas are cool failed. Check your configuration and profile and try again.');
    $this
      ->assertNull(\Drupal::state()
      ->get('lingotek.uploaded_locale'));
    $this
      ->assertNoSourceStatus('EN', Lingotek::STATUS_IMPORTING);
    $this
      ->assertSourceStatus('EN', Lingotek::STATUS_UNTRACKED);
    $this
      ->assertLingotekUploadLink();
  }

}

Classes

Namesort descending Description
LingotekNotEnabledNodeBulkTranslationTest Tests what happens when uploading a not enabled node using the bulk management form.