private function ForumAccessTestCase::testForumAccessUpdateComment in Forum Access 6
This function test if the user can update a comment Three steps: is there a edit link, does the edit page opens and can the edited comment be saved
1 call to ForumAccessTestCase::testForumAccessUpdateComment()
- ForumAccessTestCase::testForumAccessRun in ./
forum_access.test - The main function which is used to start testing a specific forum configuration.
File
- ./
forum_access.test, line 968 - Test file for forum_access.module.
Class
- ForumAccessTestCase
- This is the base class for forum access testing.
Code
private function testForumAccessUpdateComment($topic_id = 0, $comment_id = 0) {
if (intval($topic_id) > 0 && intval($comment_id) > 0) {
$allowed = $this
->testForumAccessAllowed('comment_update', $comment_id);
// Check to see if the edit link is on the view page
$this
->drupalGet('node/' . $topic_id, array(
'fragment' => 'comment-' . $comment_id,
));
if ($allowed) {
if (!$this
->assertPattern("/comment\\/edit\\/{$comment_id}/", t('For @user there should be an edit this comment-link on the page: @page', array(
'@user' => $this->loggedInUser ? t('this user') : t('anonymous'),
'@page' => $this
->getUrl(),
)))) {
$this
->testForumAccessDumpDebugInfo('comment', $comment_id);
}
}
else {
if (!$this
->assertNoPattern("/comment\\/edit\\/{$comment_id}/", t('For @user there should NOT be an edit this comment-link on the page: @page', array(
'@user' => $this->loggedInUser ? t('this user') : t('anonymous'),
'@page' => $this
->getUrl(),
)))) {
$this
->testForumAccessDumpDebugInfo('comment', $comment_id);
}
}
// Check to see if the user/anonymous is allowed to open the reply page
$page_opened = FALSE;
$this
->drupalGet('comment/edit/' . $comment_id);
if ($allowed) {
if (!$this
->assertNoText("not authorized", t('@user should be allowed to open the edit page for this comment: @page', array(
'@user' => $this->loggedInUser ? t('The user') : t('Anonymous'),
'@page' => $this
->getUrl(),
)))) {
$this
->testForumAccessDumpDebugInfo('comment', $comment_id);
}
else {
$page_opened = TRUE;
}
}
else {
if (!$this
->assertText("not authorized", t('@user should NOT be allowed to open the edit page for this comment: @page', array(
'@user' => $this->loggedInUser ? t('The user') : t('Anonymous'),
'@page' => $this
->getUrl(),
)))) {
$this
->testForumAccessDumpDebugInfo('comment', $comment_id);
$page_opened = TRUE;
}
}
if ($page_opened) {
// Check to see if the user/anonymous is allowed to edit the comment
$comment_options = array(
'subject' => 'Comment subject: ' . $this
->randomName(32),
'comment' => 'Comment comment: ' . $this
->randomName(64),
);
$this
->drupalPost('comment/edit/' . $comment_id, $comment_options, t('Preview'));
$this
->drupalPost(NULL, $comment_options, t('Save'));
if ($allowed) {
if (!$this
->assertNoText("not authorized", t('@user should be allowed to edit this comment: @page', array(
'@user' => $this->loggedInUser ? t('The user') : t('Anonymous'),
'@page' => $this
->getUrl(),
)))) {
$this
->testForumAccessDumpDebugInfo('comment', $comment_id);
}
}
else {
if (!$this
->assertText("not authorized", t('@user should NOT be allowed to edit this comment: @page', array(
'@user' => $this->loggedInUser ? t('The user') : t('Anonymous'),
'@page' => $this
->getUrl(),
)))) {
$this
->testForumAccessDumpDebugInfo('comment', $comment_id);
}
}
}
}
}