Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/comment/tests/src/Functional/CommentNonNodeTest.php @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | a9cd425dd02b |
children |
comparison
equal
deleted
inserted
replaced
4:a9cd425dd02b | 5:12f9dff5fda9 |
---|---|
59 ])->save(); | 59 ])->save(); |
60 // Create comment field on entity_test bundle. | 60 // Create comment field on entity_test bundle. |
61 $this->addDefaultCommentField('entity_test', 'entity_test'); | 61 $this->addDefaultCommentField('entity_test', 'entity_test'); |
62 | 62 |
63 // Verify that bundles are defined correctly. | 63 // Verify that bundles are defined correctly. |
64 $bundles = \Drupal::entityManager()->getBundleInfo('comment'); | 64 $bundles = \Drupal::service('entity_type.bundle.info')->getBundleInfo('comment'); |
65 $this->assertEqual($bundles['comment']['label'], 'Comment settings'); | 65 $this->assertEqual($bundles['comment']['label'], 'Comment settings'); |
66 | 66 |
67 // Create test user. | 67 // Create test user. |
68 $this->adminUser = $this->drupalCreateUser([ | 68 $this->adminUser = $this->drupalCreateUser([ |
69 'administer comments', | 69 'administer comments', |
183 * Boolean indicating whether the comment was found. | 183 * Boolean indicating whether the comment was found. |
184 */ | 184 */ |
185 public function commentExists(CommentInterface $comment = NULL, $reply = FALSE) { | 185 public function commentExists(CommentInterface $comment = NULL, $reply = FALSE) { |
186 if ($comment) { | 186 if ($comment) { |
187 $regex = '/' . ($reply ? '<div class="indented">(.*?)' : ''); | 187 $regex = '/' . ($reply ? '<div class="indented">(.*?)' : ''); |
188 $regex .= '<a id="comment-' . $comment->id() . '"(.*?)'; | 188 $regex .= '<article(.*?)id="comment-' . $comment->id() . '"(.*?)'; |
189 $regex .= $comment->getSubject() . '(.*?)'; | 189 $regex .= $comment->getSubject() . '(.*?)'; |
190 $regex .= $comment->comment_body->value . '(.*?)'; | 190 $regex .= $comment->comment_body->value . '(.*?)'; |
191 $regex .= '/s'; | 191 $regex .= '/s'; |
192 | 192 |
193 return (boolean) preg_match($regex, $this->getSession()->getPage()->getContent()); | 193 return (boolean) preg_match($regex, $this->getSession()->getPage()->getContent()); |
339 'view test entity' => TRUE, | 339 'view test entity' => TRUE, |
340 ]); | 340 ]); |
341 | 341 |
342 // Attempt to view comments while disallowed. | 342 // Attempt to view comments while disallowed. |
343 $this->drupalGet('entity-test/' . $this->entity->id()); | 343 $this->drupalGet('entity-test/' . $this->entity->id()); |
344 $this->assertNoPattern('@<h2[^>]*>Comments</h2>@', 'Comments were not displayed.'); | 344 $this->assertSession()->responseNotMatches('@<h2[^>]*>Comments</h2>@', 'Comments were not displayed.'); |
345 $this->assertNoLink('Add new comment', 'Link to add comment was found.'); | 345 $this->assertNoLink('Add new comment', 'Link to add comment was found.'); |
346 | 346 |
347 // Attempt to view test entity comment form while disallowed. | 347 // Attempt to view test entity comment form while disallowed. |
348 $this->drupalGet('comment/reply/entity_test/' . $this->entity->id() . '/comment'); | 348 $this->drupalGet('comment/reply/entity_test/' . $this->entity->id() . '/comment'); |
349 $this->assertResponse(403); | 349 $this->assertResponse(403); |
371 'post comments' => TRUE, | 371 'post comments' => TRUE, |
372 'skip comment approval' => TRUE, | 372 'skip comment approval' => TRUE, |
373 'view test entity' => TRUE, | 373 'view test entity' => TRUE, |
374 ]); | 374 ]); |
375 $this->drupalGet('entity_test/' . $this->entity->id()); | 375 $this->drupalGet('entity_test/' . $this->entity->id()); |
376 $this->assertNoPattern('@<h2[^>]*>Comments</h2>@', 'Comments were not displayed.'); | 376 $this->assertSession()->responseNotMatches('@<h2[^>]*>Comments</h2>@', 'Comments were not displayed.'); |
377 $this->assertFieldByName('subject[0][value]', '', 'Subject field found.'); | 377 $this->assertFieldByName('subject[0][value]', '', 'Subject field found.'); |
378 $this->assertFieldByName('comment_body[0][value]', '', 'Comment field found.'); | 378 $this->assertFieldByName('comment_body[0][value]', '', 'Comment field found.'); |
379 | 379 |
380 $this->drupalGet('comment/reply/entity_test/' . $this->entity->id() . '/comment/' . $comment1->id()); | 380 $this->drupalGet('comment/reply/entity_test/' . $this->entity->id() . '/comment/' . $comment1->id()); |
381 $this->assertResponse(403); | 381 $this->assertResponse(403); |
394 $this->assertNoFieldChecked('edit-default-value-input-comment-0-status-1'); | 394 $this->assertNoFieldChecked('edit-default-value-input-comment-0-status-1'); |
395 $this->assertFieldChecked('edit-default-value-input-comment-0-status-2'); | 395 $this->assertFieldChecked('edit-default-value-input-comment-0-status-2'); |
396 // Test comment option change in field settings. | 396 // Test comment option change in field settings. |
397 $edit = [ | 397 $edit = [ |
398 'default_value_input[comment][0][status]' => CommentItemInterface::CLOSED, | 398 'default_value_input[comment][0][status]' => CommentItemInterface::CLOSED, |
399 'settings[anonymous]' => COMMENT_ANONYMOUS_MAY_CONTACT, | 399 'settings[anonymous]' => CommentInterface::ANONYMOUS_MAY_CONTACT, |
400 ]; | 400 ]; |
401 $this->drupalPostForm(NULL, $edit, t('Save settings')); | 401 $this->drupalPostForm(NULL, $edit, t('Save settings')); |
402 $this->drupalGet('entity_test/structure/entity_test/fields/entity_test.entity_test.comment'); | 402 $this->drupalGet('entity_test/structure/entity_test/fields/entity_test.entity_test.comment'); |
403 $this->assertNoFieldChecked('edit-default-value-input-comment-0-status-0'); | 403 $this->assertNoFieldChecked('edit-default-value-input-comment-0-status-0'); |
404 $this->assertFieldChecked('edit-default-value-input-comment-0-status-1'); | 404 $this->assertFieldChecked('edit-default-value-input-comment-0-status-1'); |
405 $this->assertNoFieldChecked('edit-default-value-input-comment-0-status-2'); | 405 $this->assertNoFieldChecked('edit-default-value-input-comment-0-status-2'); |
406 $this->assertFieldByName('settings[anonymous]', COMMENT_ANONYMOUS_MAY_CONTACT); | 406 $this->assertFieldByName('settings[anonymous]', CommentInterface::ANONYMOUS_MAY_CONTACT); |
407 | 407 |
408 // Add a new comment-type. | 408 // Add a new comment-type. |
409 $bundle = CommentType::create([ | 409 $bundle = CommentType::create([ |
410 'id' => 'foobar', | 410 'id' => 'foobar', |
411 'label' => 'Foobar', | 411 'label' => 'Foobar', |