Mercurial > hg > isophonics-drupal-site
diff core/modules/comment/tests/src/Functional/CommentRssTest.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | af1871eacc83 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/modules/comment/tests/src/Functional/CommentRssTest.php Wed Nov 29 16:09:58 2017 +0000 @@ -0,0 +1,79 @@ +<?php + +namespace Drupal\Tests\comment\Functional; + +use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; +use Drupal\Core\Cache\Cache; +use Drupal\Core\Entity\Entity\EntityViewDisplay; +use Drupal\system\Tests\Cache\AssertPageCacheContextsAndTagsTrait; + +/** + * Tests comments as part of an RSS feed. + * + * @group comment + */ +class CommentRssTest extends CommentTestBase { + + use AssertPageCacheContextsAndTagsTrait; + + /** + * Modules to install. + * + * @var array + */ + public static $modules = ['views']; + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + + // Setup the rss view display. + EntityViewDisplay::create([ + 'status' => TRUE, + 'targetEntityType' => 'node', + 'bundle' => 'article', + 'mode' => 'rss', + 'content' => ['links' => ['weight' => 100]], + ])->save(); + } + + /** + * Tests comments as part of an RSS feed. + */ + public function testCommentRss() { + // Find comment in RSS feed. + $this->drupalLogin($this->webUser); + $this->postComment($this->node, $this->randomMachineName(), $this->randomMachineName()); + $this->drupalGet('rss.xml'); + + $cache_contexts = [ + 'languages:language_interface', + 'theme', + 'url.site', + 'user.node_grants:view', + 'user.permissions', + 'timezone', + ]; + $this->assertCacheContexts($cache_contexts); + + $cache_context_tags = \Drupal::service('cache_contexts_manager')->convertTokensToKeys($cache_contexts)->getCacheTags(); + $this->assertCacheTags(Cache::mergeTags($cache_context_tags, [ + 'config:views.view.frontpage', + 'node:1', 'node_list', + 'node_view', + 'user:3', + ])); + + $raw = '<comments>' . $this->node->url('canonical', ['fragment' => 'comments', 'absolute' => TRUE]) . '</comments>'; + $this->assertRaw($raw, 'Comments as part of RSS feed.'); + + // Hide comments from RSS feed and check presence. + $this->node->set('comment', CommentItemInterface::HIDDEN); + $this->node->save(); + $this->drupalGet('rss.xml'); + $this->assertNoRaw($raw, 'Hidden comments is not a part of RSS feed.'); + } + +}