You are here

public function AggregatorTitleTest::testStringFormatter in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/aggregator/src/Tests/AggregatorTitleTest.php \Drupal\aggregator\Tests\AggregatorTitleTest::testStringFormatter()

File

core/modules/aggregator/src/Tests/AggregatorTitleTest.php, line 52
Contains \Drupal\aggregator\Tests\AggregatorTitleTest.

Class

AggregatorTitleTest
Tests the aggregator_title formatter.

Namespace

Drupal\aggregator\Tests

Code

public function testStringFormatter() {

  // Create an aggregator feed.
  $aggregator_feed = Feed::create([
    'title' => 'testing title',
    'url' => 'http://www.example.com',
  ]);
  $aggregator_feed
    ->save();

  // Create an aggregator feed item.
  $aggregator_item = Item::create([
    'title' => 'test title',
    'fid' => $aggregator_feed
      ->id(),
    'link' => 'http://www.example.com',
  ]);
  $aggregator_item
    ->save();

  // Verify aggregator feed title with and without links.
  $build = $aggregator_feed->{$this->fieldName}
    ->view([
    'type' => 'aggregator_title',
    'settings' => [
      'display_as_link' => TRUE,
    ],
  ]);
  $result = $this
    ->render($build);
  $this
    ->assertTrue(strpos($result, 'testing title'));
  $this
    ->assertTrue(strpos($result, 'href="' . $aggregator_feed
    ->getUrl()) . '"');
  $build = $aggregator_feed->{$this->fieldName}
    ->view([
    'type' => 'aggregator_title',
    'settings' => [
      'display_as_link' => FALSE,
    ],
  ]);
  $result = $this
    ->render($build);
  $this
    ->assertTrue(strpos($result, 'testing title') === 0);
  $this
    ->assertTrue(strpos($result, $aggregator_feed
    ->getUrl()) === FALSE);

  // Verify aggregator item title with and without links.
  $build = $aggregator_item->{$this->fieldName}
    ->view([
    'type' => 'aggregator_title',
    'settings' => [
      'display_as_link' => TRUE,
    ],
  ]);
  $result = $this
    ->render($build);
  $this
    ->assertTrue(strpos($result, 'test title'));
  $this
    ->assertTrue(strpos($result, 'href="' . $aggregator_item
    ->getLink()) . '"');
  $build = $aggregator_item->{$this->fieldName}
    ->view([
    'type' => 'aggregator_title',
    'settings' => [
      'display_as_link' => FALSE,
    ],
  ]);
  $result = $this
    ->render($build);
  $this
    ->assertTrue(strpos($result, 'test title') === 0);
  $this
    ->assertTrue(strpos($result, $aggregator_item
    ->getLink()) === FALSE);
}