Loading core/modules/comment/tests/src/Functional/CommentAdminTest.php +7 −6 Changes for core/modules/comment/tests/src/Functional/CommentAdminTest.php: 7 added lines, 6 removed lines. Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ use Drupal\comment\Entity\Comment; use Drupal\Component\Utility\Html; use Drupal\language\Entity\ConfigurableLanguage; use Drupal\user\Entity\Role; use Drupal\user\RoleInterface; use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses; Loading Loading @@ -38,11 +39,11 @@ protected function setUp(): void { */ public function testApprovalAdminInterface(): void { // Set anonymous comments to require approval. user_role_change_permissions(RoleInterface::ANONYMOUS_ID, [ Role::loadOverrideFree(RoleInterface::ANONYMOUS_ID)->changePermissions([ 'access comments' => TRUE, 'post comments' => TRUE, 'skip comment approval' => FALSE, ]); ])->save(); $this->drupalLogin($this->adminUser); // Ensure that doesn't require contact info. $this->setCommentAnonymous(AnonymousContact::Forbidden); Loading Loading @@ -131,11 +132,11 @@ public function testApprovalAdminInterface(): void { */ public function testApprovalNodeInterface(): void { // Set anonymous comments to require approval. user_role_change_permissions(RoleInterface::ANONYMOUS_ID, [ Role::loadOverrideFree(RoleInterface::ANONYMOUS_ID)->changePermissions([ 'access comments' => TRUE, 'post comments' => TRUE, 'skip comment approval' => FALSE, ]); ])->save(); // Ensure that doesn't require contact info. $this->setCommentAnonymous(AnonymousContact::Forbidden); Loading Loading @@ -206,11 +207,11 @@ public function testCommentAdmin(): void { */ public function testEditComment(): void { // Enable anonymous user comments. user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, [ Role::loadOverrideFree(RoleInterface::ANONYMOUS_ID)->grantPermissions([ 'access comments', 'post comments', 'skip comment approval', ]); ])->save(); // Log in as a web user. $this->drupalLogin($this->webUser); Loading core/modules/comment/tests/src/Functional/CommentAnonymousTest.php +17 −12 Changes for core/modules/comment/tests/src/Functional/CommentAnonymousTest.php: 17 added lines, 12 removed lines. Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ namespace Drupal\Tests\comment\Functional; use Drupal\comment\AnonymousContact; use Drupal\user\Entity\Role; use Drupal\user\RoleInterface; use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses; Loading @@ -28,16 +29,16 @@ protected function setUp(): void { parent::setUp(); // Enable anonymous and authenticated user comments. user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, [ Role::loadOverrideFree(RoleInterface::ANONYMOUS_ID)->grantPermissions([ 'access comments', 'post comments', 'skip comment approval', ]); user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, [ ])->save(); Role::loadOverrideFree(RoleInterface::AUTHENTICATED_ID)->grantPermissions([ 'access comments', 'post comments', 'skip comment approval', ]); ])->save(); } /** Loading @@ -60,7 +61,9 @@ public function testAnonymous(): void { $this->assertStringContainsString($body, $preview, 'Anonymous user can preview comment body.'); // Preview comments (without `skip comment approval` permission). user_role_revoke_permissions(RoleInterface::ANONYMOUS_ID, ['skip comment approval']); Role::loadOverrideFree(RoleInterface::ANONYMOUS_ID)->revokePermissions([ 'skip comment approval', ])->save(); $edit = []; $title = 'comment title without skip comment approval'; $body = 'comment body without skip comment approval'; Loading @@ -72,7 +75,9 @@ public function testAnonymous(): void { $preview = (string) $this->cssSelect('[data-drupal-selector="edit-comment-preview"]')[0]->getHtml(); $this->assertStringContainsString($title, $preview, 'Anonymous user can preview comment title.'); $this->assertStringContainsString($body, $preview, 'Anonymous user can preview comment body.'); user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['skip comment approval']); Role::loadOverrideFree(RoleInterface::ANONYMOUS_ID)->grantPermissions([ 'skip comment approval', ])->save(); // Post anonymous comment without contact info. $anonymous_comment1 = $this->postComment($this->node, $this->randomMachineName(), $this->randomMachineName()); Loading Loading @@ -175,11 +180,11 @@ public function testAnonymous(): void { $this->assertSession()->statusCodeEquals(403); // Reset. user_role_change_permissions(RoleInterface::ANONYMOUS_ID, [ Role::loadOverrideFree(RoleInterface::ANONYMOUS_ID)->changePermissions([ 'access comments' => FALSE, 'post comments' => FALSE, 'skip comment approval' => FALSE, ]); ])->save(); // Attempt to view comments while disallowed. // NOTE: if authenticated user has permission to post comments, then a Loading @@ -193,22 +198,22 @@ public function testAnonymous(): void { $this->drupalGet('comment/reply/node/' . $this->node->id() . '/comment'); $this->assertSession()->statusCodeEquals(403); user_role_change_permissions(RoleInterface::ANONYMOUS_ID, [ Role::loadOverrideFree(RoleInterface::ANONYMOUS_ID)->changePermissions([ 'access comments' => TRUE, 'post comments' => FALSE, 'skip comment approval' => FALSE, ]); ])->save(); $this->drupalGet('node/' . $this->node->id()); // Verify that the comment field title is displayed. $this->assertSession()->responseMatches('@<h2[^>]*>Comments</h2>@'); $this->assertSession()->linkExists('Log in', 1, 'Link to login was found.'); $this->assertSession()->linkExists('register', 1, 'Link to register was found.'); user_role_change_permissions(RoleInterface::ANONYMOUS_ID, [ Role::loadOverrideFree(RoleInterface::ANONYMOUS_ID)->changePermissions([ 'access comments' => FALSE, 'post comments' => TRUE, 'skip comment approval' => TRUE, ]); ])->save(); $this->drupalGet('node/' . $this->node->id()); // Verify that comments were not displayed. $this->assertSession()->responseNotMatches('@<h2[^>]*>Comments</h2>@'); Loading core/modules/comment/tests/src/Functional/CommentBlockTest.php +7 −2 Changes for core/modules/comment/tests/src/Functional/CommentBlockTest.php: 7 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ namespace Drupal\Tests\comment\Functional; use Drupal\user\Entity\Role; use Drupal\user\RoleInterface; use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses; Loading Loading @@ -63,10 +64,14 @@ public function testRecentCommentBlock(): void { // Test that a user without the 'access comments' permission cannot see the // block. $this->drupalLogout(); user_role_revoke_permissions(RoleInterface::ANONYMOUS_ID, ['access comments']); Role::loadOverrideFree(RoleInterface::ANONYMOUS_ID)->revokePermissions([ 'access comments', ])->save(); $this->drupalGet(''); $this->assertSession()->pageTextNotContains('Recent comments'); user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['access comments']); Role::loadOverrideFree(RoleInterface::ANONYMOUS_ID)->grantPermissions([ 'access comments', ])->save(); // Test that a user with the 'access comments' permission can see the // block. Loading core/modules/comment/tests/src/Functional/CommentCSSTest.php +3 −2 Changes for core/modules/comment/tests/src/Functional/CommentCSSTest.php: 3 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ use Drupal\comment\Entity\Comment; use Drupal\Core\Language\LanguageInterface; use Drupal\Tests\Traits\Core\GeneratePermutationsTrait; use Drupal\user\Entity\Role; use Drupal\user\RoleInterface; use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses; Loading Loading @@ -35,10 +36,10 @@ protected function setUp(): void { parent::setUp(); // Allow anonymous users to see comments. user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, [ Role::loadOverrideFree(RoleInterface::ANONYMOUS_ID)->grantPermissions([ 'access comments', 'access content', ]); ])->save(); } /** Loading core/modules/comment/tests/src/Functional/CommentDisplayConfigurableTest.php +3 −2 Changes for core/modules/comment/tests/src/Functional/CommentDisplayConfigurableTest.php: 3 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ use Drupal\comment\Entity\Comment; use Drupal\Core\Entity\Entity\EntityViewDisplay; use Drupal\Core\Language\LanguageInterface; use Drupal\user\Entity\Role; use Drupal\user\RoleInterface; use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses; Loading @@ -31,10 +32,10 @@ protected function setUp(): void { parent::setUp(); // Allow anonymous users to see comments. user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, [ Role::loadOverrideFree(RoleInterface::ANONYMOUS_ID)->grantPermissions([ 'access comments', 'access content', ]); ])->save(); } /** Loading Loading
core/modules/comment/tests/src/Functional/CommentAdminTest.php +7 −6 Changes for core/modules/comment/tests/src/Functional/CommentAdminTest.php: 7 added lines, 6 removed lines. Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ use Drupal\comment\Entity\Comment; use Drupal\Component\Utility\Html; use Drupal\language\Entity\ConfigurableLanguage; use Drupal\user\Entity\Role; use Drupal\user\RoleInterface; use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses; Loading Loading @@ -38,11 +39,11 @@ protected function setUp(): void { */ public function testApprovalAdminInterface(): void { // Set anonymous comments to require approval. user_role_change_permissions(RoleInterface::ANONYMOUS_ID, [ Role::loadOverrideFree(RoleInterface::ANONYMOUS_ID)->changePermissions([ 'access comments' => TRUE, 'post comments' => TRUE, 'skip comment approval' => FALSE, ]); ])->save(); $this->drupalLogin($this->adminUser); // Ensure that doesn't require contact info. $this->setCommentAnonymous(AnonymousContact::Forbidden); Loading Loading @@ -131,11 +132,11 @@ public function testApprovalAdminInterface(): void { */ public function testApprovalNodeInterface(): void { // Set anonymous comments to require approval. user_role_change_permissions(RoleInterface::ANONYMOUS_ID, [ Role::loadOverrideFree(RoleInterface::ANONYMOUS_ID)->changePermissions([ 'access comments' => TRUE, 'post comments' => TRUE, 'skip comment approval' => FALSE, ]); ])->save(); // Ensure that doesn't require contact info. $this->setCommentAnonymous(AnonymousContact::Forbidden); Loading Loading @@ -206,11 +207,11 @@ public function testCommentAdmin(): void { */ public function testEditComment(): void { // Enable anonymous user comments. user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, [ Role::loadOverrideFree(RoleInterface::ANONYMOUS_ID)->grantPermissions([ 'access comments', 'post comments', 'skip comment approval', ]); ])->save(); // Log in as a web user. $this->drupalLogin($this->webUser); Loading
core/modules/comment/tests/src/Functional/CommentAnonymousTest.php +17 −12 Changes for core/modules/comment/tests/src/Functional/CommentAnonymousTest.php: 17 added lines, 12 removed lines. Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ namespace Drupal\Tests\comment\Functional; use Drupal\comment\AnonymousContact; use Drupal\user\Entity\Role; use Drupal\user\RoleInterface; use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses; Loading @@ -28,16 +29,16 @@ protected function setUp(): void { parent::setUp(); // Enable anonymous and authenticated user comments. user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, [ Role::loadOverrideFree(RoleInterface::ANONYMOUS_ID)->grantPermissions([ 'access comments', 'post comments', 'skip comment approval', ]); user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, [ ])->save(); Role::loadOverrideFree(RoleInterface::AUTHENTICATED_ID)->grantPermissions([ 'access comments', 'post comments', 'skip comment approval', ]); ])->save(); } /** Loading @@ -60,7 +61,9 @@ public function testAnonymous(): void { $this->assertStringContainsString($body, $preview, 'Anonymous user can preview comment body.'); // Preview comments (without `skip comment approval` permission). user_role_revoke_permissions(RoleInterface::ANONYMOUS_ID, ['skip comment approval']); Role::loadOverrideFree(RoleInterface::ANONYMOUS_ID)->revokePermissions([ 'skip comment approval', ])->save(); $edit = []; $title = 'comment title without skip comment approval'; $body = 'comment body without skip comment approval'; Loading @@ -72,7 +75,9 @@ public function testAnonymous(): void { $preview = (string) $this->cssSelect('[data-drupal-selector="edit-comment-preview"]')[0]->getHtml(); $this->assertStringContainsString($title, $preview, 'Anonymous user can preview comment title.'); $this->assertStringContainsString($body, $preview, 'Anonymous user can preview comment body.'); user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['skip comment approval']); Role::loadOverrideFree(RoleInterface::ANONYMOUS_ID)->grantPermissions([ 'skip comment approval', ])->save(); // Post anonymous comment without contact info. $anonymous_comment1 = $this->postComment($this->node, $this->randomMachineName(), $this->randomMachineName()); Loading Loading @@ -175,11 +180,11 @@ public function testAnonymous(): void { $this->assertSession()->statusCodeEquals(403); // Reset. user_role_change_permissions(RoleInterface::ANONYMOUS_ID, [ Role::loadOverrideFree(RoleInterface::ANONYMOUS_ID)->changePermissions([ 'access comments' => FALSE, 'post comments' => FALSE, 'skip comment approval' => FALSE, ]); ])->save(); // Attempt to view comments while disallowed. // NOTE: if authenticated user has permission to post comments, then a Loading @@ -193,22 +198,22 @@ public function testAnonymous(): void { $this->drupalGet('comment/reply/node/' . $this->node->id() . '/comment'); $this->assertSession()->statusCodeEquals(403); user_role_change_permissions(RoleInterface::ANONYMOUS_ID, [ Role::loadOverrideFree(RoleInterface::ANONYMOUS_ID)->changePermissions([ 'access comments' => TRUE, 'post comments' => FALSE, 'skip comment approval' => FALSE, ]); ])->save(); $this->drupalGet('node/' . $this->node->id()); // Verify that the comment field title is displayed. $this->assertSession()->responseMatches('@<h2[^>]*>Comments</h2>@'); $this->assertSession()->linkExists('Log in', 1, 'Link to login was found.'); $this->assertSession()->linkExists('register', 1, 'Link to register was found.'); user_role_change_permissions(RoleInterface::ANONYMOUS_ID, [ Role::loadOverrideFree(RoleInterface::ANONYMOUS_ID)->changePermissions([ 'access comments' => FALSE, 'post comments' => TRUE, 'skip comment approval' => TRUE, ]); ])->save(); $this->drupalGet('node/' . $this->node->id()); // Verify that comments were not displayed. $this->assertSession()->responseNotMatches('@<h2[^>]*>Comments</h2>@'); Loading
core/modules/comment/tests/src/Functional/CommentBlockTest.php +7 −2 Changes for core/modules/comment/tests/src/Functional/CommentBlockTest.php: 7 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ namespace Drupal\Tests\comment\Functional; use Drupal\user\Entity\Role; use Drupal\user\RoleInterface; use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses; Loading Loading @@ -63,10 +64,14 @@ public function testRecentCommentBlock(): void { // Test that a user without the 'access comments' permission cannot see the // block. $this->drupalLogout(); user_role_revoke_permissions(RoleInterface::ANONYMOUS_ID, ['access comments']); Role::loadOverrideFree(RoleInterface::ANONYMOUS_ID)->revokePermissions([ 'access comments', ])->save(); $this->drupalGet(''); $this->assertSession()->pageTextNotContains('Recent comments'); user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['access comments']); Role::loadOverrideFree(RoleInterface::ANONYMOUS_ID)->grantPermissions([ 'access comments', ])->save(); // Test that a user with the 'access comments' permission can see the // block. Loading
core/modules/comment/tests/src/Functional/CommentCSSTest.php +3 −2 Changes for core/modules/comment/tests/src/Functional/CommentCSSTest.php: 3 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ use Drupal\comment\Entity\Comment; use Drupal\Core\Language\LanguageInterface; use Drupal\Tests\Traits\Core\GeneratePermutationsTrait; use Drupal\user\Entity\Role; use Drupal\user\RoleInterface; use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses; Loading Loading @@ -35,10 +36,10 @@ protected function setUp(): void { parent::setUp(); // Allow anonymous users to see comments. user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, [ Role::loadOverrideFree(RoleInterface::ANONYMOUS_ID)->grantPermissions([ 'access comments', 'access content', ]); ])->save(); } /** Loading
core/modules/comment/tests/src/Functional/CommentDisplayConfigurableTest.php +3 −2 Changes for core/modules/comment/tests/src/Functional/CommentDisplayConfigurableTest.php: 3 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ use Drupal\comment\Entity\Comment; use Drupal\Core\Entity\Entity\EntityViewDisplay; use Drupal\Core\Language\LanguageInterface; use Drupal\user\Entity\Role; use Drupal\user\RoleInterface; use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses; Loading @@ -31,10 +32,10 @@ protected function setUp(): void { parent::setUp(); // Allow anonymous users to see comments. user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, [ Role::loadOverrideFree(RoleInterface::ANONYMOUS_ID)->grantPermissions([ 'access comments', 'access content', ]); ])->save(); } /** Loading