X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Faggregator%2Ftests%2Fsrc%2FKernel%2FAggregatorTitleTest.php;fp=web%2Fcore%2Fmodules%2Faggregator%2Ftests%2Fsrc%2FKernel%2FAggregatorTitleTest.php;h=782ac6f14b089a4b0730edea92d05e23c83ffa37;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/core/modules/aggregator/tests/src/Kernel/AggregatorTitleTest.php b/web/core/modules/aggregator/tests/src/Kernel/AggregatorTitleTest.php new file mode 100644 index 000000000..782ac6f14 --- /dev/null +++ b/web/core/modules/aggregator/tests/src/Kernel/AggregatorTitleTest.php @@ -0,0 +1,90 @@ +installConfig(['field']); + $this->installEntitySchema('aggregator_feed'); + $this->installEntitySchema('aggregator_item'); + + \Drupal::service('router.builder')->rebuild(); + + $this->fieldName = 'title'; + } + + /** + * Tests the formatter output. + */ + 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->assertContains('testing title', $result); + $this->assertContains('href="' . $aggregator_feed->getUrl() . '"', $result); + + $build = $aggregator_feed->{$this->fieldName}->view(['type' => 'aggregator_title', 'settings' => ['display_as_link' => FALSE]]); + $result = $this->render($build); + $this->assertContains('testing title', $result); + $this->assertNotContains($aggregator_feed->getUrl(), $result); + + // 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->assertContains('test title', $result); + $this->assertContains('href="' . $aggregator_item->getLink() . '"', $result); + + $build = $aggregator_item->{$this->fieldName}->view(['type' => 'aggregator_title', 'settings' => ['display_as_link' => FALSE]]); + $result = $this->render($build); + $this->assertContains('test title', $result); + $this->assertNotContains($aggregator_item->getLink(), $result); + } + +}