Skip to content

Commit

Permalink
Blog: Deleted by user name not shown after deleting comment #603245
Browse files Browse the repository at this point in the history
  • Loading branch information
Emanoil Manoylov authored and sammarshallou committed Jan 3, 2023
1 parent d0de9c6 commit 03b16df
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 27 deletions.
18 changes: 18 additions & 0 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3031,6 +3031,24 @@ function oublog_get_posts_by_id($oublog, $ids) {
return $rs;
}

/**
* Gets post ids.
*
* @param int $oublogid.
* @return array
* @throws coding_exception
* @throws dml_exception
*/
function oublog_get_post_ids($oublogid) {
global $DB;
$sql = "SELECT p.id
FROM {oublog_posts} p
INNER JOIN {oublog_instances} bi ON bi.id = p.oubloginstancesid
INNER JOIN {oublog} b ON b.id = bi.oublogid
WHERE b.id = ?";
return $DB->get_fieldset_sql($sql, [$oublogid]);
}

class oublog_portfolio_caller extends portfolio_module_caller_base {

protected $postid;
Expand Down
1 change: 1 addition & 0 deletions module.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ M.mod_oublog.init_deleteandemail = function(Y, cmid, postid) {
delbtns.set('disabled', false);
var content = M.util.get_string('deleteemailpostdescription', 'oublog');
var panel = new M.core.dialogue({
headerContent: M.util.get_string('confirm', 'moodle'),
bodyContent: content,
width: 400,
centered: true,
Expand Down
8 changes: 4 additions & 4 deletions renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1042,13 +1042,13 @@ public function render_comments($post, $oublog, $canaudit, $canmanagecomments, $
$deluser = new stdClass();
$fields = \core_user\fields::get_name_fields();
foreach ($fields as $field) {
$field = 'del' . $field;
$deluser->$field = $comment->$field;
$dfield = 'del' . $field;
$deluser->$field = $comment->$dfield;
}

$a = new stdClass();
$a->fullname = '<a href="../../user/view.php?id=' . $comment->deletedby . '">' .
fullname($deluser) . '</a>';
$a->fullname = html_writer::tag('a', fullname($deluser),
array('href' => $CFG->wwwroot . '/user/view.php?id=' . $comment->deletedby));
$a->timedeleted = oublog_date($comment->timedeleted);

$output .= html_writer::tag('div', get_string('deletedby', 'oublog', $a),
Expand Down
122 changes: 99 additions & 23 deletions tests/behat/basic.feature
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,7 @@ Feature: Test Post and Comment on OUBlog entry
@javascript @_file_upload
Scenario: Check tag sorting and filter by tag as student
Given I log in as "teacher1"
And I am on homepage
And I am on "Course 1" course homepage
When I follow "Test oublog basics"
When I am on the "Test oublog basics" "oublog activity" page
And I press "New blog post"
# Before the 'Set' tags restriction
And I should not see "You may only enter the 'Set' tags:"
Expand All @@ -392,7 +390,6 @@ Feature: Test Post and Comment on OUBlog entry

# Student tests without Set tags restrictions.
Given I log in as "student1"
And I am on "Course 1" course homepage
And I am on the "Test oublog basics" "oublog activity" page
And I press "New blog post"
# Before the 'Set' tags restriction
Expand Down Expand Up @@ -439,21 +436,8 @@ Feature: Test Post and Comment on OUBlog entry
And I click on ".oublog-post-editsummary a" "css_element"
Then I should not see "SC02 Student OUBlog post02 content filtered by tag edited post body"

# Delete student post01 the second post made.
And I am on the "Test oublog basics" "oublog activity" page
When I click on "Delete" "link" in the ".oublog-post:nth-child(2) .oublog-post-links" "css_element"
And I wait to be redirected
Then I should see "Are you sure you want to delete this post?"
And I press "Delete"
And I wait to be redirected
Then I should see "SC02 OUBlog post02 from student edited post subject"
And ".oublog-deleted" "css_element" should exist
And ".oublog-post-deletedby" "css_element" should exist
And I should see "Deleted by"
And "Delete" "link" should not exist in the ".oublog-deleted" "css_element"
And "Add your comment" "link" should not exist in the ".oublog-deleted" "css_element"

# Check post comments with comments enabled.
Given I am on the "Test oublog basics" "oublog activity" page
Then I should see "SC02 OUBlog post02 from student edited post subject"
And I should see "SC02 Student OUBlog post02 content filtered by tag edited post body"
Given I follow "Add your comment"
Expand All @@ -466,7 +450,6 @@ Feature: Test Post and Comment on OUBlog entry

# Check post with restrictions enabled as Teacher.
Given I log in as "teacher1"
And I am on "Course 1" course homepage
And I am on the "Test oublog basics" "oublog activity" page
And I navigate to "Settings" in current page administration
# Add the 'Set' tags restriction
Expand All @@ -493,9 +476,102 @@ Feature: Test Post and Comment on OUBlog entry
And I should see "SC02 OUBlog post02 teacher content"

# Should see tags in default Alphabetical order.
Then I should see "ctag3sc02(2) dogtag(1) dtag3sc02(1)"
Then I should see "ctag3sc02(3) dogtag(1) dtag3sc02(1)"

@javascript
Scenario: Check deleting posts
Given I create "2" sample posts for blog with id "oublog1"
And I log in as "teacher1"
And I am on the "Test oublog basics" "oublog activity" page
And I should see "Test post 0"
And I should see "Test post 1"

# Delete a post as teacher1.
When I click on "Delete" "link" in the ".oublog-post:nth-child(1) .oublog-post-links" "css_element"
And I wait to be redirected
Then I should see "Select to delete the post"
And I click on "Delete" "button" in the "Confirm" "dialogue"
And I wait to be redirected
# Check deleted post details.
Then I should see "Test post 0"
And I should see "Test post 1"
And ".oublog-deleted" "css_element" should exist
And ".oublog-post-deletedby" "css_element" should exist
And I should see "Deleted by Teacher 1"
And "Delete" "link" should not exist in the ".oublog-deleted" "css_element"
And "Add your comment" "link" should not exist in the ".oublog-deleted" "css_element"
And I log out

# Check posts as student1.
Given I log in as "student1"
And I am on the "Test oublog basics" "oublog activity" page
And I should see "Test post 0"
And I should not see "Test post 1"
And I log out

# Check posts as admin.
Given I log in as "admin"
And I am on the "Test oublog basics" "oublog activity" page
And I should see "Test post 0"
And I should see "Test post 1"
And I should see "Deleted by Teacher 1"

# Delete a post as admin.
When I click on "Delete" "link" in the ".oublog-post:nth-child(2) .oublog-post-links" "css_element"
And I wait to be redirected
Then I should see "Are you sure you want to delete this post?"
And I press "Delete"
And I wait to be redirected
And I should see "Deleted by Admin User"

@javascript
Scenario: Check deleting comments
Given I create "1" sample posts for blog with id "oublog1"
And I create "2" sample comments for blog with id "oublog1"
And I log in as "teacher1"
And I am on the "Test oublog basics" "oublog activity" page
And I follow "2 comments"
And I should see "Post 0 - Test comment 0"
And I should see "Post 0 - Test comment 1"

# Delete a comment.
When I click on "Delete" "link" in the ".oublog-comment:nth-child(1) .oublog-post-links" "css_element"
And I wait to be redirected
Then I should see "Are you sure you want to delete this comment?"
And I click on "Continue" "button" in the "Confirm" "dialogue"
And I wait to be redirected
# Check deleted comment details.
Then I should see "Post 0 - Test comment 0"
And I should see "Post 0 - Test comment 1"
And ".oublog-deleted" "css_element" should exist
And ".oublog-comment-deletedby" "css_element" should exist
And I should see "Deleted by Teacher 1"
And "Delete" "link" should not exist in the ".oublog-deleted" "css_element"
And I log out

# Check comments as student1.
Given I log in as "student1"
And I am on the "Test oublog basics" "oublog activity" page
And I follow "1 comment"
And I should not see "Post 0 - Test comment 0"
And I should see "Post 0 - Test comment 1"
And I log out

# Check comments as admin.
And I log in as "admin"
And I am on the "Test oublog basics" "oublog activity" page
And I follow "1 comment"
And I should see "Post 0 - Test comment 0"
And I should see "Post 0 - Test comment 1"
And I should see "Deleted by Teacher 1"

# Delete a comment as admin.
When I click on "Delete" "link" in the ".oublog-comment:nth-child(2) .oublog-post-links" "css_element"
And I wait to be redirected
Then I should see "Are you sure you want to delete this comment?"
And I click on "Continue" "button" in the "Confirm" "dialogue"
And I wait to be redirected
And I should see "Deleted by Admin User"

Scenario: Further standard regression/basic tests - non-js.
# Check post with comments disabled as Teacher.
Expand Down Expand Up @@ -777,9 +853,9 @@ Feature: Test Post and Comment on OUBlog entry
And I follow "Test oublog basics"
And I press "New blog post"
And I set the following fields to these values:
| Title | Teacher1 blog 1|
| Message | Teacher1 post |
| Tags | tag1 |
| Title | Teacher1 blog 1 |
| Message | Teacher1 post |
| Tags | tag1 |
And I press "Add post"
And I press "New blog post"
And I set the following fields to these values:
Expand Down
32 changes: 32 additions & 0 deletions tests/behat/behat_mod_oublog.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public function i_create_n_posts_with_form_data($number, $idnumber) {
$course = get_course($oublog->course);
for ($i = 0; $i < $number; $i++) {
$post = new stdClass();
$post->timeposted = time() + $i * 2;
$post->oublogid = $oublog->id;
$post->userid = $USER->id;
$post->groupid = 0;
Expand All @@ -78,6 +79,37 @@ public function i_create_n_posts_with_form_data($number, $idnumber) {
}
}

/**
* Create sample comments.
*
* @Given /^I create "(?P<number>[^"]+)" sample comments for blog with id "(?P<idnumber_string>(?:[^"]|\\")*)"$/
*
* @param int number
* @param string idnumber
*/
public function i_create_n_comments_with_form_data($number, $idnumber) {
global $CFG, $USER;
require_once($CFG->dirroot . '/mod/oublog/locallib.php');
$oublog = $this->get_oublog_by_idnumber($idnumber);
$cm = get_coursemodule_from_instance('oublog', $oublog->id);
$course = get_course($oublog->course);
$postids = oublog_get_post_ids($oublog->id);
$p = 0;
foreach ($postids as $postid) {
for ($i = 0; $i < $number; $i++) {
$comment = new stdClass();
$comment->timeposted = time() + $i * 2;
$comment->title = "Post $p - Test comment $i";
$comment->messagecomment = array();
$comment->messagecomment['text'] = "Post $p - Test comment $i content";
$comment->postid = $postid;
$comment->userid = $USER->id;
oublog_add_comment($course, $cm, $oublog, $comment);
}
$p++;
}
}

private function get_oublog_by_idnumber($idnumber) {
global $DB;
$query = "SELECT blog.*, cm.id as cmid
Expand Down

0 comments on commit 03b16df

Please sign in to comment.