annotate core/modules/comment/tests/src/Functional/CommentRssTest.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents af1871eacc83
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\Tests\comment\Functional;
Chris@0 4
Chris@0 5 use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
Chris@0 6 use Drupal\Core\Cache\Cache;
Chris@0 7 use Drupal\Core\Entity\Entity\EntityViewDisplay;
Chris@18 8 use Drupal\Tests\system\Functional\Cache\AssertPageCacheContextsAndTagsTrait;
Chris@0 9
Chris@0 10 /**
Chris@0 11 * Tests comments as part of an RSS feed.
Chris@0 12 *
Chris@0 13 * @group comment
Chris@0 14 */
Chris@0 15 class CommentRssTest extends CommentTestBase {
Chris@0 16
Chris@0 17 use AssertPageCacheContextsAndTagsTrait;
Chris@0 18
Chris@0 19 /**
Chris@0 20 * Modules to install.
Chris@0 21 *
Chris@0 22 * @var array
Chris@0 23 */
Chris@0 24 public static $modules = ['views'];
Chris@0 25
Chris@0 26 /**
Chris@0 27 * {@inheritdoc}
Chris@0 28 */
Chris@0 29 protected function setUp() {
Chris@0 30 parent::setUp();
Chris@0 31
Chris@0 32 // Setup the rss view display.
Chris@0 33 EntityViewDisplay::create([
Chris@0 34 'status' => TRUE,
Chris@0 35 'targetEntityType' => 'node',
Chris@0 36 'bundle' => 'article',
Chris@0 37 'mode' => 'rss',
Chris@0 38 'content' => ['links' => ['weight' => 100]],
Chris@0 39 ])->save();
Chris@0 40 }
Chris@0 41
Chris@0 42 /**
Chris@0 43 * Tests comments as part of an RSS feed.
Chris@0 44 */
Chris@0 45 public function testCommentRss() {
Chris@0 46 // Find comment in RSS feed.
Chris@0 47 $this->drupalLogin($this->webUser);
Chris@0 48 $this->postComment($this->node, $this->randomMachineName(), $this->randomMachineName());
Chris@0 49 $this->drupalGet('rss.xml');
Chris@0 50
Chris@0 51 $cache_contexts = [
Chris@0 52 'languages:language_interface',
Chris@0 53 'theme',
Chris@0 54 'url.site',
Chris@0 55 'user.node_grants:view',
Chris@0 56 'user.permissions',
Chris@0 57 'timezone',
Chris@0 58 ];
Chris@0 59 $this->assertCacheContexts($cache_contexts);
Chris@0 60
Chris@0 61 $cache_context_tags = \Drupal::service('cache_contexts_manager')->convertTokensToKeys($cache_contexts)->getCacheTags();
Chris@0 62 $this->assertCacheTags(Cache::mergeTags($cache_context_tags, [
Chris@0 63 'config:views.view.frontpage',
Chris@0 64 'node:1', 'node_list',
Chris@0 65 'node_view',
Chris@0 66 'user:3',
Chris@0 67 ]));
Chris@0 68
Chris@18 69 $raw = '<comments>' . $this->node->toUrl('canonical', ['fragment' => 'comments', 'absolute' => TRUE])->toString() . '</comments>';
Chris@0 70 $this->assertRaw($raw, 'Comments as part of RSS feed.');
Chris@0 71
Chris@0 72 // Hide comments from RSS feed and check presence.
Chris@0 73 $this->node->set('comment', CommentItemInterface::HIDDEN);
Chris@0 74 $this->node->save();
Chris@0 75 $this->drupalGet('rss.xml');
Chris@0 76 $this->assertNoRaw($raw, 'Hidden comments is not a part of RSS feed.');
Chris@0 77 }
Chris@0 78
Chris@0 79 }