class CommentRssTest in Drupal 10
Same name and namespace in other branches
- 8 core/modules/comment/tests/src/Functional/CommentRssTest.php \Drupal\Tests\comment\Functional\CommentRssTest
- 9 core/modules/comment/tests/src/Functional/CommentRssTest.php \Drupal\Tests\comment\Functional\CommentRssTest
Tests comments as part of an RSS feed.
@group comment
Hierarchy
- class \Drupal\Tests\BrowserTestBase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, FunctionalTestSetupTrait, TestSetupTrait, BlockCreationTrait, ConfigTestTrait, ExtensionListTestTrait, ContentTypeCreationTrait, NodeCreationTrait, RandomGeneratorTrait, TestRequirementsTrait, PhpUnitWarnings, UiHelperTrait, UserCreationTrait, XdebugRequestTrait
- class \Drupal\Tests\comment\Functional\CommentTestBase uses CommentTestTrait
- class \Drupal\Tests\comment\Functional\CommentRssTest uses AssertPageCacheContextsAndTagsTrait
- class \Drupal\Tests\comment\Functional\CommentTestBase uses CommentTestTrait
Expanded class hierarchy of CommentRssTest
File
- core/
modules/ comment/ tests/ src/ Functional/ CommentRssTest.php, line 15
Namespace
Drupal\Tests\comment\FunctionalView source
class CommentRssTest extends CommentTestBase {
use AssertPageCacheContextsAndTagsTrait;
/**
* Modules to install.
*
* @var array
*/
protected static $modules = [
'views',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected function setUp() : void {
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
->toUrl('canonical', [
'fragment' => 'comments',
'absolute' => TRUE,
])
->toString() . '</comments>';
$this
->assertSession()
->responseContains($raw);
// Hide comments from RSS feed and check presence.
$this->node
->set('comment', CommentItemInterface::HIDDEN);
$this->node
->save();
$this
->drupalGet('rss.xml');
$this
->assertSession()
->responseNotContains($raw);
}
}