3 namespace Drupal\Tests\aggregator\Kernel;
5 use Drupal\aggregator\Entity\Feed;
6 use Drupal\aggregator\Entity\Item;
7 use Drupal\KernelTests\KernelTestBase;
11 * Tests the aggregator_title formatter.
15 class AggregatorTitleTest extends KernelTestBase {
22 public static $modules = ['file', 'field', 'options', 'aggregator', 'system'];
25 * The field name that is tested.
34 protected function setUp() {
37 $this->installConfig(['field']);
38 $this->installEntitySchema('aggregator_feed');
39 $this->installEntitySchema('aggregator_item');
41 \Drupal::service('router.builder')->rebuild();
43 $this->fieldName = 'title';
47 * Tests the formatter output.
49 public function testStringFormatter() {
50 // Create an aggregator feed.
51 $aggregator_feed = Feed::create([
52 'title' => 'testing title',
53 'url' => 'http://www.example.com',
55 $aggregator_feed->save();
57 // Create an aggregator feed item.
58 $aggregator_item = Item::create([
59 'title' => 'test title',
60 'fid' => $aggregator_feed->id(),
61 'link' => 'http://www.example.com',
63 $aggregator_item->save();
65 // Verify aggregator feed title with and without links.
66 $build = $aggregator_feed->{$this->fieldName}->view(['type' => 'aggregator_title', 'settings' => ['display_as_link' => TRUE]]);
67 $result = $this->render($build);
69 $this->assertContains('testing title', $result);
70 $this->assertContains('href="' . $aggregator_feed->getUrl() . '"', $result);
72 $build = $aggregator_feed->{$this->fieldName}->view(['type' => 'aggregator_title', 'settings' => ['display_as_link' => FALSE]]);
73 $result = $this->render($build);
74 $this->assertContains('testing title', $result);
75 $this->assertNotContains($aggregator_feed->getUrl(), $result);
77 // Verify aggregator item title with and without links.
78 $build = $aggregator_item->{$this->fieldName}->view(['type' => 'aggregator_title', 'settings' => ['display_as_link' => TRUE]]);
79 $result = $this->render($build);
81 $this->assertContains('test title', $result);
82 $this->assertContains('href="' . $aggregator_item->getLink() . '"', $result);
84 $build = $aggregator_item->{$this->fieldName}->view(['type' => 'aggregator_title', 'settings' => ['display_as_link' => FALSE]]);
85 $result = $this->render($build);
86 $this->assertContains('test title', $result);
87 $this->assertNotContains($aggregator_item->getLink(), $result);