3 namespace Drupal\Tests\aggregator\Kernel;
5 use Drupal\aggregator\Entity\Feed;
6 use Drupal\aggregator\Entity\Item;
7 use Drupal\KernelTests\KernelTestBase;
10 * Tests the aggregator_title formatter.
14 class AggregatorTitleTest extends KernelTestBase {
21 public static $modules = ['file', 'field', 'options', 'aggregator', 'system'];
24 * The field name that is tested.
33 protected function setUp() {
36 $this->installConfig(['field']);
37 $this->installEntitySchema('aggregator_feed');
38 $this->installEntitySchema('aggregator_item');
40 \Drupal::service('router.builder')->rebuild();
42 $this->fieldName = 'title';
46 * Tests the formatter output.
48 public function testStringFormatter() {
49 // Create an aggregator feed.
50 $aggregator_feed = Feed::create([
51 'title' => 'testing title',
52 'url' => 'http://www.example.com',
54 $aggregator_feed->save();
56 // Create an aggregator feed item.
57 $aggregator_item = Item::create([
58 'title' => 'test title',
59 'fid' => $aggregator_feed->id(),
60 'link' => 'http://www.example.com',
62 $aggregator_item->save();
64 // Verify aggregator feed title with and without links.
65 $build = $aggregator_feed->{$this->fieldName}->view(['type' => 'aggregator_title', 'settings' => ['display_as_link' => TRUE]]);
66 $result = $this->render($build);
68 $this->assertContains('testing title', $result);
69 $this->assertContains('href="' . $aggregator_feed->getUrl() . '"', $result);
71 $build = $aggregator_feed->{$this->fieldName}->view(['type' => 'aggregator_title', 'settings' => ['display_as_link' => FALSE]]);
72 $result = $this->render($build);
73 $this->assertContains('testing title', $result);
74 $this->assertNotContains($aggregator_feed->getUrl(), $result);
76 // Verify aggregator item title with and without links.
77 $build = $aggregator_item->{$this->fieldName}->view(['type' => 'aggregator_title', 'settings' => ['display_as_link' => TRUE]]);
78 $result = $this->render($build);
80 $this->assertContains('test title', $result);
81 $this->assertContains('href="' . $aggregator_item->getLink() . '"', $result);
83 $build = $aggregator_item->{$this->fieldName}->view(['type' => 'aggregator_title', 'settings' => ['display_as_link' => FALSE]]);
84 $result = $this->render($build);
85 $this->assertContains('test title', $result);
86 $this->assertNotContains($aggregator_item->getLink(), $result);