Skip to content

Commit

Permalink
Use id selectors for buttons in forum tool
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelFQC committed May 5, 2016
1 parent ae816c6 commit 4c5f4c8
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 59 deletions.
66 changes: 39 additions & 27 deletions main/forum/viewthread_flat.inc.php
Expand Up @@ -63,27 +63,30 @@
) {
if ($_user['user_id'] || ($current_forum['allow_anonymous'] == 1 && !$_user['user_id'])) {
if (!api_is_anonymous() && api_is_allowed_to_session_edit(false, true)) {

$buttonReply = Display::tag(
'a',
'<em class="fa fa-reply"></em> ' . get_lang('ReplyToMessage'),
array(
'href' => 'reply.php?' . api_get_cidreq()
. "&forum=$clean_forum_id&thread=$clean_thread_id&post="
. "{$row['post_id']}&action=replymessage&origin=$origin",
'class' => 'btn btn-primary'
)
$buttonReply = Display::toolbarButton(
get_lang('ReplyToMessage'),
'reply.php?' . api_get_cidreq() . '&' . http_build_query([
'forum' => $clean_forum_id,
'thread' => $clean_thread_id,
'post' => $row['post_id'],
'action' => 'replymessage'
]),
'reply',
'primary',
['id' => "reply-to-post-{$row['post_id']}"]
);

$buttonQuote = Display::tag(
'a',
'<em class="fa fa-quote-left"></em> ' . get_lang('QuoteMessage'),
array(
'href' => 'reply.php?' . api_get_cidreq()
. "&forum=$clean_forum_id&thread=$clean_thread_id"
. "&post={$row['post_id']}&action=quote&origin=$origin",
'class' => 'btn btn-success'
)
$buttonQuote = Display::toolbarButton(
get_lang('QuoteMessage'),
'reply.php?' . api_get_cidreq() . '&' . http_build_query([
'forum' => $clean_forum_id,
'thread' => $clean_thread_id,
'post' => $row['post_id'],
'action' => 'quote'
]),
'quote-left',
'success',
['id' => "quote-post-{$row['post_id']}"]
);
}
}
Expand Down Expand Up @@ -190,14 +193,23 @@
) {

if ($locked == false) {
$iconEdit .= "<a href=\"" . api_get_self() . "?" . api_get_cidreq() . "&forum="
. $clean_forum_id . "&thread=" . $clean_thread_id
. "&action=delete&content=post&id=" . $row['post_id'] . "&origin="
. $origin . "\" onclick=\"javascript:if(!confirm('"
. addslashes(api_htmlentities(get_lang('DeletePost'), ENT_QUOTES))
. "')) return false;\">"
. Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL)
. "</a>";
$deleteUrl = api_get_self() . '?' . api_get_cidreq() . '&' . http_build_query([
'forum' => $clean_forum_id,
'thread' => $clean_thread_id,
'action' => 'delete',
'content' => 'post',
'id' => $row['post_id']
]);
$iconEdit .= Display::url(
Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL),
$deleteUrl,
[
'onclick' => "javascript:if(!confirm('"
. addslashes(api_htmlentities(get_lang('DeletePost'), ENT_QUOTES))
. "')) return false;",
'id' => "delete-post-{$row['post_id']}"
]
);
}
}
if (
Expand Down
64 changes: 39 additions & 25 deletions main/forum/viewthread_nested.inc.php
Expand Up @@ -138,12 +138,23 @@
!(api_is_course_coach() && $current_forum['session_id'] != $sessionId)
) {
if ($locked == false) {
$iconEdit .="<a href=\"" . api_get_self() . "?" . api_get_cidreq()
. "&forum=$clean_forum_id&thread=$clean_thread_id&action=delete&content=post&id={$post['post_id']}"
. "\" onclick=\"javascript:if(!confirm('"
. addslashes(api_htmlentities(get_lang('DeletePost'), ENT_QUOTES)) . "')) return false;\">"
. Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL)
. "</a>";
$deleteUrl = api_get_self() . '?' . api_get_cidreq() . '&' . http_build_query([
'forum' => $clean_forum_id,
'thread' => $clean_thread_id,
'action' => 'delete',
'content' => 'post',
'id' => $post['post_id']
]);
$iconEdit .= Display::url(
Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL),
$deleteUrl,
[
'onclick' => "javascript:if(!confirm('"
. addslashes(api_htmlentities(get_lang('DeletePost'), ENT_QUOTES))
. "')) return false;",
'id' => "delete-post-{$post['post_id']}"
]
);
}
}

Expand Down Expand Up @@ -204,27 +215,30 @@
) {
if ($userId || ($current_forum['allow_anonymous'] == 1 && !$userId)) {
if (!api_is_anonymous() && api_is_allowed_to_session_edit(false, true)) {

$buttonReply = Display::tag(
'a',
'<em class="fa fa-reply"></em> ' . get_lang('ReplyToMessage'),
array(
'href' => 'reply.php?' . api_get_cidreq()
. "&forum=$clean_forum_id'&thread=$clean_thread_id"
. "&post={$post['post_id']}&action=replymessage&origin=$origin",
'class' => 'btn btn-primary'
)
$buttonReply = Display::toolbarButton(
get_lang('ReplyToMessage'),
'reply.php?' . api_get_cidreq() . '&' . http_build_query([
'forum' => $clean_forum_id,
'thread' => $clean_thread_id,
'post' => $post['post_id'],
'action' => 'replymessage'
]),
'reply',
'primary',
['id' => "reply-to-post-{$post['post_id']}"]
);

$buttonQuote = Display::tag(
'a',
'<em class="fa fa-quote-left"></em> ' . get_lang('QuoteMessage'),
array(
'href' => 'reply.php?' . api_get_cidreq()
. "&forum=$clean_forum_id&thread=$clean_thread_id"
. "&post={$post['post_id']}&action=quote&origin=$origin",
'class' => 'btn btn-success'
)
$buttonQuote = Display::toolbarButton(
get_lang('QuoteMessage'),
'reply.php?' . api_get_cidreq() . '&' . http_build_query([
'forum' => $clean_forum_id,
'thread' => $clean_thread_id,
'post' => $post['post_id'],
'action' => 'quote'
]),
'quote-left',
'success',
['id' => "quote-post-{$post['post_id']}"]
);
}
}
Expand Down
19 changes: 12 additions & 7 deletions tests/features/forum.feature
Expand Up @@ -31,17 +31,22 @@ Feature: Forum tool
Then I should see "The new thread has been added"

Scenario: Reply to forum message
Given I am on "/main/forum/reply.php?forum=1&thread=1&post=1&action=replymessage"
When I fill in the following:
Given I am on "/main/forum/viewthread.php?forum=1&thread=1"
When I follow "reply-to-1"
And I fill in the following:
| post_text | This is a reply to the first message for test |
And I press "SubmitPost"
Then I should see "The reply has been added"

Scenario: Delete a forum message
Given I am on "/main/forum/viewthread.php?forum=1&thread=1&action=delete&content=post&id=2"
Given I am on "/main/forum/viewthread.php?forum=1&thread=1"
When I follow "delete-post-2"
Then I should see "Post has been deleted"

Scenario: Quote a forum message
Given I am on "/main/forum/reply.php?forum=1&thread=1&post=1&action=quote"
When I press "SubmitPost"
Then I should see "The reply has been added"
# This test is commented because to quote a message is necessary load HTML code inside of textarea.
# And this breaks the page for Behat
# Scenario: Quote a forum message
# Given I am on "/main/forum/viewthread.php?forum=1&thread=1"
# When I follow "quote-1"
# And I press "SubmitPost"
# Then I should see "The reply has been added"

0 comments on commit 4c5f4c8

Please sign in to comment.