Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Plugins bot
moodle-plugins-snapshots
Commits
ee2af37e
Commit
ee2af37e
authored
Jan 23, 2017
by
Dan Poltawski
Browse files
Merge branch 'MDL-57677-master-usermodified' of
git://github.com/mudrd8mz/moodle
parents
c7f9bbf6
106f2373
Changes
2
Show whitespace changes
Inline
Side-by-side
mod/forum/lib.php
View file @
ee2af37e
...
...
@@ -4439,7 +4439,7 @@ function forum_update_post($newpost, $mform, $unused = null) {
// Last post modified tracking.
$discussion
->
timemodified
=
$post
->
modified
;
$discussion
->
usermodified
=
$
USER
->
id
;
$discussion
->
usermodified
=
$
post
->
user
id
;
if
(
!
$post
->
parent
)
{
// Post is a discussion starter - update discussion title and times too
$discussion
->
name
=
$post
->
subject
;
...
...
mod/forum/tests/lib_test.php
View file @
ee2af37e
...
...
@@ -3260,4 +3260,58 @@ class mod_forum_lib_testcase extends advanced_testcase {
],
];
}
/**
* Test that {@link forum_update_post()} keeps correct forum_discussions usermodified.
*/
public
function
test_forum_update_post_keeps_discussions_usermodified
()
{
global
$DB
;
$this
->
resetAfterTest
();
// Let there be light.
$teacher
=
self
::
getDataGenerator
()
->
create_user
();
$student
=
self
::
getDataGenerator
()
->
create_user
();
$course
=
self
::
getDataGenerator
()
->
create_course
();
$forum
=
self
::
getDataGenerator
()
->
create_module
(
'forum'
,
(
object
)[
'course'
=>
$course
->
id
,
]);
$generator
=
self
::
getDataGenerator
()
->
get_plugin_generator
(
'mod_forum'
);
// Let the teacher start a discussion.
$discussion
=
$generator
->
create_discussion
((
object
)[
'course'
=>
$course
->
id
,
'userid'
=>
$teacher
->
id
,
'forum'
=>
$forum
->
id
,
]);
// On this freshly created discussion, the teacher is the author of the last post.
$this
->
assertEquals
(
$teacher
->
id
,
$DB
->
get_field
(
'forum_discussions'
,
'usermodified'
,
[
'id'
=>
$discussion
->
id
]));
// Let the student reply to the teacher's post.
$reply
=
$generator
->
create_post
((
object
)[
'course'
=>
$course
->
id
,
'userid'
=>
$student
->
id
,
'forum'
=>
$forum
->
id
,
'discussion'
=>
$discussion
->
id
,
'parent'
=>
$discussion
->
firstpost
,
]);
// The student should now be the last post's author.
$this
->
assertEquals
(
$student
->
id
,
$DB
->
get_field
(
'forum_discussions'
,
'usermodified'
,
[
'id'
=>
$discussion
->
id
]));
// Let the teacher edit the student's reply.
$this
->
setUser
(
$teacher
->
id
);
$newpost
=
(
object
)[
'id'
=>
$reply
->
id
,
'itemid'
=>
0
,
'subject'
=>
'Amended subject'
,
];
forum_update_post
(
$newpost
,
null
);
// The student should be still the last post's author.
$this
->
assertEquals
(
$student
->
id
,
$DB
->
get_field
(
'forum_discussions'
,
'usermodified'
,
[
'id'
=>
$discussion
->
id
]));
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment