commit 42017c8bf79decc6e4c397804779c3a6ef5f3d40 Author: Lee Rowlands Date: Wed Sep 9 09:31:07 2015 +1000 fail diff --git a/core/modules/comment/src/Tests/CommentBlockContentTest.php b/core/modules/comment/src/Tests/CommentBlockContentTest.php new file mode 100644 index 0000000..b791f64 --- /dev/null +++ b/core/modules/comment/src/Tests/CommentBlockContentTest.php @@ -0,0 +1,109 @@ + 'comments', + 'label' => 'Comments', + ]); + $type->save(); + block_content_add_body_field($type->id()); + CommentType::create([ + 'id' => 'comment', + 'label' => 'Comment settings', + 'description' => 'Comment settings', + 'target_entity_type_id' => 'block_content', + ])->save(); + // Create comment field on block_content bundle. + $this->addDefaultCommentField('block_content', 'comments'); + + // Create test user. + $this->adminUser = $this->drupalCreateUser(array( + 'administer comments', + 'skip comment approval', + 'post comments', + 'access comments', + 'administer blocks', + )); + + // Enable anonymous and authenticated user comments. + user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array( + 'access comments', + 'post comments', + 'skip comment approval', + )); + + // Create a block and place it. + $this->drupalLogin($this->adminUser); + $edit = array(); + $edit['info[0][value]'] = $this->randomMachineName(8); + $body = $this->randomMachineName(16); + $edit['body[0][value]'] = $body; + $this->drupalPostForm('block/add', $edit, t('Save')); + + // Place the block. + $instance = array( + 'id' => Unicode::strtolower($edit['info[0][value]']), + 'settings[label]' => $edit['info[0][value]'], + 'region' => 'sidebar_first', + ); + $block = BlockContent::load(1); + $url = 'admin/structure/block/add/block_content:' . $block->uuid() . '/' . $this->config('system.theme')->get('default'); + $this->drupalPostForm($url, $instance, t('Save block')); + $this->drupalLogout(); + } + + /** + * Tests anonymous commenting via a block. + */ + public function testAnonymousBlockContentCommenting() { + // Navigate to home page. + $this->drupalGet(''); + // Comment on the block. + $edit = []; + $edit['comment_body[0][value]'] = 'Noni the pony is skinny and bony'; + $edit['subject[0][value]'] = 'Oh no, why does it go?'; + $this->drupalPostForm(NULL, $edit, t('Save')); + // User without permission to visit block/{block} doesn't get redirected. + $this->assertResponse(200); + $this->assertUrl(Url::fromRoute('comment.reply', ['entity_type' => 'block_content', 'entity' => 1, 'field_name' => 'comment'])); + } + +}