function DisplayFeedTranslationTest::checkFeedResults

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

Checks the feed results for the given style of node links.

Parameters

string $link_style: What style of links do we expect? Either 'raw-node-path' or 'path-alias'. Only used for human-readable assert failure messages.

\Drupal\node\Entity\Node $node: The node entity that's been created.

1 call to DisplayFeedTranslationTest::checkFeedResults()
DisplayFeedTranslationTest::testFeedFieldOutput in core/modules/views/tests/src/Functional/Plugin/DisplayFeedTranslationTest.php
Tests the rendered output for fields display with multiple translations.

File

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

Class

DisplayFeedTranslationTest
Tests the feed display plugin with translated content.

Namespace

Drupal\Tests\views\Functional\Plugin

Code

protected function checkFeedResults($link_style, Node $node) {
    
    /** @var \Drupal\Core\Language\LanguageManagerInterface $languageManager */
    $language_manager = \Drupal::languageManager()->reset();
    $node_links = [];
    $node_links['en'] = $node->toUrl()
        ->setAbsolute()
        ->toString();
    foreach ($this->langcodes as $langcode) {
        $node_links[$langcode] = $node->toUrl()
            ->setOption('language', $language_manager->getLanguage($langcode))
            ->setAbsolute()
            ->toString();
    }
    $expected = [
        'pt-br' => [
            'description' => '<p>Algo em Português</p>',
        ],
        'es' => [
            'description' => '<p>Algo en Español</p>',
        ],
        'en' => [
            'description' => '<p>Something in English.</p>',
        ],
    ];
    foreach ($node_links as $langcode => $link) {
        $expected[$langcode]['link'] = $link;
    }
    $this->drupalGet('test-feed-display-fields.xml');
    $this->assertSession()
        ->statusCodeEquals(200);
    $items = $this->getSession()
        ->getDriver()
        ->find('//channel/item');
    // There should only be 3 items in the feed.
    $this->assertCount(3, $items, "{$link_style}: 3 items in feed");
    // Don't rely on the sort order of the items in the feed. Instead, each
    // item's title is the langcode for that item. Iterate over all the items,
    // get the title text for each one, make sure we're expecting each langcode
    // we find, and then assert that the rest of the content of that item is
    // what we expect for the given langcode.
    foreach ($items as $item) {
        $title_element = $item->findAll('xpath', 'title');
        $this->assertCount(1, $title_element, "{$link_style}: Missing title element");
        $langcode = $title_element[0]->getText();
        $this->assertArrayHasKey($langcode, $expected, "{$link_style}: Missing expected output for {$langcode}");
        foreach ($expected[$langcode] as $key => $expected_value) {
            $elements = $item->findAll('xpath', $key);
            $this->assertCount(1, $elements, "{$link_style}: Xpath {$key} missing");
            $this->assertEquals($expected_value, $elements[0]->getText(), "{$link_style}: Unexpected value for {$key}");
        }
    }
}

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