Commit 47299605 authored by catch's avatar catch
Browse files

Issue #3384936 by marvil07, vbouchet, smustgrave, xjm, joachim: Use the API to...

Issue #3384936 by marvil07, vbouchet, smustgrave, xjm, joachim: Use the API to set up languages in tests that are not specifically testing the language form

(cherry picked from commit ed1c6900)
parent 0969fb95
Loading
Loading
Loading
Loading
Loading
+5 −7
Original line number Diff line number Diff line
@@ -2,9 +2,8 @@

namespace Drupal\Tests\contact\Functional;

use Drupal\Core\Language\LanguageInterface;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\language\Traits\LanguageTestTrait;

/**
 * Tests contact messages with language module.
@@ -17,6 +16,8 @@
 */
class ContactLanguageTest extends BrowserTestBase {

  use LanguageTestTrait;

  /**
   * Modules to enable.
   *
@@ -56,11 +57,8 @@ public function testContactLanguage() {
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->fieldNotExists('edit-langcode-0-value');

    // Enable language select.
    $config = ContentLanguageSettings::loadByEntityTypeBundle('contact_message', 'feedback');
    $config->setDefaultLangcode(LanguageInterface::LANGCODE_SITE_DEFAULT);
    $config->setLanguageAlterable(TRUE);
    $config->save();
    // Enable translations for feedback contact messages.
    static::enableBundleTranslation('contact_message', 'feedback');

    // Ensure that contact form now shows the language select.
    $this->drupalGet('contact');
+4 −12
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@

use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait;
use Drupal\Tests\content_translation\Traits\ContentTranslationTestTrait;

/**
 * Test content_moderation functionality with content_translation.
@@ -13,6 +14,7 @@
class ModerationContentTranslationTest extends BrowserTestBase {

  use ContentModerationTestTrait;
  use ContentTranslationTestTrait;

  /**
   * A user with permission to bypass access content.
@@ -45,19 +47,9 @@ protected function setUp(): void {
    $this->drupalLogin($this->rootUser);
    // Create an Article content type.
    $this->drupalCreateContentType(['type' => 'article', 'name' => 'Article'])->save();
    $edit = [
      'predefined_langcode' => 'fr',
    ];
    $this->drupalGet('admin/config/regional/language/add');
    $this->submitForm($edit, 'Add language');
    static::createLanguageFromLangcode('fr');
    // Enable content translation on articles.
    $this->drupalGet('admin/config/regional/content-language');
    $edit = [
      'entity_types[node]' => TRUE,
      'settings[node][article][translatable]' => TRUE,
      'settings[node][article][settings][language][language_alterable]' => TRUE,
    ];
    $this->submitForm($edit, 'Save configuration');
    $this->enableContentTranslation('node', 'article');
    // Adding languages requires a container rebuild in the test running
    // environment so that multilingual services are used.
    $this->rebuildContainer();
+7 −14
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@

use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Url;
use Drupal\Tests\content_translation\Traits\ContentTranslationTestTrait;

/**
 * Tests the moderation form, specifically on nodes.
@@ -13,6 +14,8 @@
 */
class ModerationFormTest extends ModerationStateTestBase {

  use ContentTranslationTestTrait;

  /**
   * Modules to enable.
   *
@@ -283,20 +286,10 @@ public function testContentTranslationNodeForm() {
    $this->drupalLogin($this->rootUser);

    // Add French language.
    $edit = [
      'predefined_langcode' => 'fr',
    ];
    $this->drupalGet('admin/config/regional/language/add');
    $this->submitForm($edit, 'Add language');

    // Enable content translation on articles.
    $this->drupalGet('admin/config/regional/content-language');
    $edit = [
      'entity_types[node]' => TRUE,
      'settings[node][moderated_content][translatable]' => TRUE,
      'settings[node][moderated_content][settings][language][language_alterable]' => TRUE,
    ];
    $this->submitForm($edit, 'Save configuration');
    static::createLanguageFromLangcode('fr');

    // Enable content translation on moderated_content.
    $this->enableContentTranslation('node', 'moderated_content');

    // Adding languages requires a container rebuild in the test running
    // environment so that multilingual services are used.
+6 −14
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
namespace Drupal\Tests\content_moderation\Functional;

use Drupal\node\NodeInterface;
use Drupal\Tests\content_translation\Traits\ContentTranslationTestTrait;

/**
 * Test content_moderation functionality with localization and translation.
@@ -12,6 +13,8 @@
 */
class ModerationLocaleTest extends ModerationStateTestBase {

  use ContentTranslationTestTrait;

  /**
   * Modules to enable.
   *
@@ -41,22 +44,11 @@ protected function setUp(): void {
    $this->createContentTypeFromUi('Article', 'article', TRUE);

    // Add French and Italian languages.
    foreach (['fr', 'it'] as $langcode) {
      $edit = [
        'predefined_langcode' => $langcode,
      ];
      $this->drupalGet('admin/config/regional/language/add');
      $this->submitForm($edit, 'Add language');
    }
    static::createLanguageFromLangcode('fr');
    static::createLanguageFromLangcode('it');

    // Enable content translation on articles.
    $this->drupalGet('admin/config/regional/content-language');
    $edit = [
      'entity_types[node]' => TRUE,
      'settings[node][article][translatable]' => TRUE,
      'settings[node][article][settings][language][language_alterable]' => TRUE,
    ];
    $this->submitForm($edit, 'Save configuration');
    $this->enableContentTranslation('node', 'article');

    // Adding languages requires a container rebuild in the test running
    // environment so that multilingual services are used.
+5 −14
Original line number Diff line number Diff line
@@ -3,9 +3,9 @@
namespace Drupal\Tests\content_translation\Functional;

use Drupal\field\Entity\FieldConfig;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\content_translation\Traits\ContentTranslationTestTrait;

/**
 * Tests that contextual links are available for content translation.
@@ -14,6 +14,8 @@
 */
class ContentTranslationContextualLinksTest extends BrowserTestBase {

  use ContentTranslationTestTrait;

  /**
   * The bundle being tested.
   *
@@ -68,7 +70,7 @@ protected function setUp(): void {
    parent::setUp();
    // Set up an additional language.
    $this->langcodes = [\Drupal::languageManager()->getDefaultLanguage()->getId(), 'es'];
    ConfigurableLanguage::createFromLangcode('es')->save();
    static::createLanguageFromLangcode('es');

    // Create a content type.
    $this->bundle = $this->randomMachineName();
@@ -114,18 +116,7 @@ public function testContentTranslationContextualLinks() {
    $this->drupalCreateNode(['type' => $this->bundle, 'title' => $title, 'langcode' => 'en']);
    $node = $this->drupalGetNodeByTitle($title);

    // Use a UI form submission to make the node type and field translatable.
    // This tests that caches are properly invalidated.
    $this->drupalLogin($this->rootUser);
    $edit = [
      'entity_types[node]' => TRUE,
      'settings[node][' . $this->bundle . '][settings][language][language_alterable]' => TRUE,
      'settings[node][' . $this->bundle . '][translatable]' => TRUE,
      'settings[node][' . $this->bundle . '][fields][field_test_text]' => TRUE,
    ];
    $this->drupalGet('admin/config/regional/content-language');
    $this->submitForm($edit, 'Save configuration');
    $this->drupalLogout();
    static::enableContentTranslation('node', $this->bundle);

    // Check that the link leads to the translate page.
    $this->drupalLogin($this->translator);
Loading