504b3bacf6714ae09b3c24458df415d638aba9ee
[yaffs-website] / web / core / modules / comment / tests / src / Functional / CommentStatusFieldAccessTest.php
1 <?php
2
3 namespace Drupal\Tests\comment\Functional;
4
5
6 use Drupal\comment\Tests\CommentTestTrait;
7 use Drupal\node\Entity\NodeType;
8 use Drupal\Tests\BrowserTestBase;
9
10 /**
11  * Tests comment status field access.
12  *
13  * @group comment
14  */
15 class CommentStatusFieldAccessTest extends BrowserTestBase {
16
17   use CommentTestTrait;
18
19   /**
20    * {@inheritdoc}
21    */
22   public $profile = 'testing';
23
24   /**
25    * Comment admin.
26    *
27    * @var \Drupal\user\UserInterface
28    */
29   protected $commentAdmin;
30
31   /**
32    * Node author.
33    *
34    * @var \Drupal\user\UserInterface
35    */
36   protected $nodeAuthor;
37
38   /**
39    * {@inheritdoc}
40    */
41   public static $modules = [
42     'node',
43     'comment',
44     'user',
45     'system',
46     'text',
47   ];
48
49   /**
50    * {@inheritdoc}
51    */
52   protected function setUp() {
53     parent::setUp();
54     $node_type = NodeType::create([
55       'type' => 'article',
56       'name' => t('Article'),
57     ]);
58     $node_type->save();
59     $this->nodeAuthor = $this->drupalCreateUser([
60       'create article content',
61       'skip comment approval',
62       'post comments',
63       'edit own comments',
64       'access comments',
65       'administer nodes',
66     ]);
67     $this->commentAdmin = $this->drupalCreateUser([
68       'administer comments',
69       'create article content',
70       'edit own comments',
71       'skip comment approval',
72       'post comments',
73       'access comments',
74       'administer nodes',
75     ]);
76     $this->addDefaultCommentField('node', 'article');
77   }
78
79   /**
80    * Tests comment status field access.
81    */
82   public function testCommentStatusFieldAccessStatus() {
83     $this->drupalLogin($this->nodeAuthor);
84     $this->drupalGet('node/add/article');
85     $assert = $this->assertSession();
86     $assert->fieldNotExists('comment[0][status]');
87     $this->submitForm([
88       'title[0][value]' => 'Node 1',
89     ], t('Save and publish'));
90     $assert->fieldExists('subject[0][value]');
91     $this->drupalLogin($this->commentAdmin);
92     $this->drupalGet('node/add/article');
93     $assert->fieldExists('comment[0][status]');
94     $this->submitForm([
95       'title[0][value]' => 'Node 2',
96     ], t('Save and publish'));
97     $assert->fieldExists('subject[0][value]');
98   }
99
100 }