You are here

function AddFeedTest::testBasicFeedAddNoTitle in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Common/AddFeedTest.php \Drupal\system\Tests\Common\AddFeedTest::testBasicFeedAddNoTitle()

Tests attaching feeds with paths, URLs, and titles.

File

core/modules/system/src/Tests/Common/AddFeedTest.php, line 23
Contains \Drupal\system\Tests\Common\AddFeedTest.

Class

AddFeedTest
Make sure that attaching feeds works correctly with various constructs.

Namespace

Drupal\system\Tests\Common

Code

function testBasicFeedAddNoTitle() {
  $path = $this
    ->randomMachineName(12);
  $external_url = 'http://' . $this
    ->randomMachineName(12) . '/' . $this
    ->randomMachineName(12);
  $fully_qualified_local_url = Url::fromUri('base:' . $this
    ->randomMachineName(12), array(
    'absolute' => TRUE,
  ))
    ->toString();
  $path_for_title = $this
    ->randomMachineName(12);
  $external_for_title = 'http://' . $this
    ->randomMachineName(12) . '/' . $this
    ->randomMachineName(12);
  $fully_qualified_for_title = Url::fromUri('base:' . $this
    ->randomMachineName(12), array(
    'absolute' => TRUE,
  ))
    ->toString();
  $urls = array(
    'path without title' => array(
      'url' => Url::fromUri('base:' . $path, array(
        'absolute' => TRUE,
      ))
        ->toString(),
      'title' => '',
    ),
    'external URL without title' => array(
      'url' => $external_url,
      'title' => '',
    ),
    'local URL without title' => array(
      'url' => $fully_qualified_local_url,
      'title' => '',
    ),
    'path with title' => array(
      'url' => Url::fromUri('base:' . $path_for_title, array(
        'absolute' => TRUE,
      ))
        ->toString(),
      'title' => $this
        ->randomMachineName(12),
    ),
    'external URL with title' => array(
      'url' => $external_for_title,
      'title' => $this
        ->randomMachineName(12),
    ),
    'local URL with title' => array(
      'url' => $fully_qualified_for_title,
      'title' => $this
        ->randomMachineName(12),
    ),
  );
  $build = [];
  foreach ($urls as $feed_info) {
    $build['#attached']['feed'][] = [
      $feed_info['url'],
      $feed_info['title'],
    ];
  }

  // Use the bare HTML page renderer to render our links.
  $renderer = $this->container
    ->get('bare_html_page_renderer');
  $response = $renderer
    ->renderBarePage($build, '', $this->container
    ->get('theme.manager')
    ->getActiveTheme()
    ->getName());

  // Glean the content from the response object.
  $this
    ->setRawContent($response
    ->getContent());

  // Assert that the content contains the RSS links we specified.
  foreach ($urls as $description => $feed_info) {
    $this
      ->assertPattern($this
      ->urlToRSSLinkPattern($feed_info['url'], $feed_info['title']), format_string('Found correct feed header for %description', array(
      '%description' => $description,
    )));
  }
}