function DisplayFeedTranslationTest::testFeedFieldOutput

Same name in other branches
  1. 9 core/modules/views/tests/src/Functional/Plugin/DisplayFeedTranslationTest.php \Drupal\Tests\views\Functional\Plugin\DisplayFeedTranslationTest::testFeedFieldOutput()
  2. 8.9.x core/modules/views/tests/src/Functional/Plugin/DisplayFeedTranslationTest.php \Drupal\Tests\views\Functional\Plugin\DisplayFeedTranslationTest::testFeedFieldOutput()
  3. 10 core/modules/views/tests/src/Functional/Plugin/DisplayFeedTranslationTest.php \Drupal\Tests\views\Functional\Plugin\DisplayFeedTranslationTest::testFeedFieldOutput()

Tests the rendered output for fields display with multiple translations.

File

core/modules/views/tests/src/Functional/Plugin/DisplayFeedTranslationTest.php, line 97

Class

DisplayFeedTranslationTest
Tests the feed display plugin with translated content.

Namespace

Drupal\Tests\views\Functional\Plugin

Code

public function testFeedFieldOutput() : void {
    $node = $this->drupalCreateNode([
        'type' => 'page',
        'title' => 'en',
        'body' => [
            0 => [
                'value' => 'Something in English.',
                'format' => filter_default_format(),
            ],
        ],
        'langcode' => 'en',
    ]);
    $es_translation = $node->addTranslation('es');
    $es_translation->set('title', 'es');
    $es_translation->set('body', [
        [
            'value' => 'Algo en Español',
        ],
    ]);
    $es_translation->save();
    $pt_br_translation = $node->addTranslation('pt-br');
    $pt_br_translation->set('title', 'pt-br');
    $pt_br_translation->set('body', [
        [
            'value' => 'Algo em Português',
        ],
    ]);
    $pt_br_translation->save();
    // First, check everything with raw node paths (e.g. node/1).
    $this->checkFeedResults('raw-node-path', $node);
    // Now, create path aliases for each translation.
    $node_path = '/node/' . $node->id();
    $this->createPathAlias($node_path, "{$node_path}/en-alias");
    $this->createPathAlias($node_path, "{$node_path}/es-alias", 'es');
    $this->createPathAlias($node_path, "{$node_path}/pt-br-alias", 'pt-br');
    // Save the node again, to clear the cache on the feed.
    $node->save();
    // Assert that all the results are correct using path aliases.
    $this->checkFeedResults('path-alias', $node);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.