Multilingual node tests should use the API rather than form submissions in setUp()

Created on 27 July 2020, about 4 years ago
Updated 30 January 2023, over 1 year ago

Problem/Motivation

Various functional tests in node module use form submission to perform setup. E.g., in NodeFieldMultilingualTest::setUp():

    // Enable URL language detection and selection.
    $edit = ['language_interface[enabled][language-url]' => '1'];
    $this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings'));

    // Set "Basic page" content type to use multilingual support.
    $edit = [
      'language_configuration[language_alterable]' => TRUE,
    ];
    $this->drupalPostForm('admin/structure/types/manage/page', $edit, t('Save content type'));
    $this->assertRaw(t('The content type %type has been updated.', ['%type' => 'Basic page']), 'Basic page content type has been updated.');

This makes the test slower, because form submissions in the test browser take longer than API calls.

Replacing this with API calls will make the test faster to run, and easier to read.

Proposed resolution

Replace with API calls.

From what I can tell, what's needed is something like this:

    $config = $this->config('language.negotiation');
    $config->set('url.prefixes', [
      'en' => 'en',
      'de' => 'de',
    ])->save();

      $this->container->get('entity_type.manager')->getStorage('language_content_settings')->create([
        'target_entity_type_id' => $entity_type,
        'target_bundle' => $bundle,
      ])->save();
📌 Task
Status

Needs work

Version

10.1

Component
Node system 

Last updated less than a minute ago

No maintainer
Created by

🇬🇧United Kingdom joachim

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

Production build 0.71.5 2024