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
a04ad367
Commit
a04ad367
authored
Jan 16, 2017
by
Dan Poltawski
Browse files
Merge branch 'MDL-57554-master' of
git://github.com/crazyserver/moodle
parents
41dd0ac8
db3c9ff8
Changes
2
Hide whitespace changes
Inline
Side-by-side
mod/forum/externallib.php
View file @
a04ad367
...
...
@@ -680,7 +680,7 @@ class mod_forum_external extends external_api {
* @throws moodle_exception
*/
public
static
function
view_forum_discussion
(
$discussionid
)
{
global
$DB
,
$CFG
;
global
$DB
,
$CFG
,
$USER
;
require_once
(
$CFG
->
dirroot
.
"/mod/forum/lib.php"
);
$params
=
self
::
validate_parameters
(
self
::
view_forum_discussion_parameters
(),
...
...
@@ -702,6 +702,11 @@ class mod_forum_external extends external_api {
// Call the forum/lib API.
forum_discussion_view
(
$modcontext
,
$forum
,
$discussion
);
// Mark as read if required.
if
(
!
$CFG
->
forum_usermarksread
&&
forum_tp_is_tracked
(
$forum
))
{
forum_tp_mark_discussion_read
(
$USER
,
$discussion
->
id
);
}
$result
=
array
();
$result
[
'status'
]
=
true
;
$result
[
'warnings'
]
=
$warnings
;
...
...
mod/forum/tests/externallib_test.php
View file @
a04ad367
...
...
@@ -211,6 +211,12 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
$forum1
=
self
::
getDataGenerator
()
->
create_module
(
'forum'
,
$record
);
$forum1context
=
context_module
::
instance
(
$forum1
->
cmid
);
// Forum with tracking enabled.
$record
=
new
stdClass
();
$record
->
course
=
$course1
->
id
;
$forum2
=
self
::
getDataGenerator
()
->
create_module
(
'forum'
,
$record
);
$forum2context
=
context_module
::
instance
(
$forum2
->
cmid
);
// Add discussions to the forums.
$record
=
new
stdClass
();
$record
->
course
=
$course1
->
id
;
...
...
@@ -224,6 +230,12 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
$record
->
forum
=
$forum1
->
id
;
$discussion2
=
self
::
getDataGenerator
()
->
get_plugin_generator
(
'mod_forum'
)
->
create_discussion
(
$record
);
$record
=
new
stdClass
();
$record
->
course
=
$course1
->
id
;
$record
->
userid
=
$user2
->
id
;
$record
->
forum
=
$forum2
->
id
;
$discussion3
=
self
::
getDataGenerator
()
->
get_plugin_generator
(
'mod_forum'
)
->
create_discussion
(
$record
);
// Add 2 replies to the discussion 1 from different users.
$record
=
new
stdClass
();
$record
->
discussion
=
$discussion1
->
id
;
...
...
@@ -345,6 +357,31 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
$posts
=
external_api
::
clean_returnvalue
(
mod_forum_external
::
get_forum_discussion_posts_returns
(),
$posts
);
$this
->
assertEquals
(
1
,
count
(
$posts
[
'posts'
]));
// Test discussion tracking on not tracked forum.
$result
=
mod_forum_external
::
view_forum_discussion
(
$discussion1
->
id
);
$result
=
external_api
::
clean_returnvalue
(
mod_forum_external
::
view_forum_discussion_returns
(),
$result
);
$this
->
assertTrue
(
$result
[
'status'
]);
$this
->
assertEmpty
(
$result
[
'warnings'
]);
// Test posts have not been marked as read.
$posts
=
mod_forum_external
::
get_forum_discussion_posts
(
$discussion1
->
id
,
'modified'
,
'DESC'
);
$posts
=
external_api
::
clean_returnvalue
(
mod_forum_external
::
get_forum_discussion_posts_returns
(),
$posts
);
foreach
(
$posts
[
'posts'
]
as
$post
)
{
$this
->
assertFalse
(
$post
[
'postread'
]);
}
// Test discussion tracking on tracked forum.
$result
=
mod_forum_external
::
view_forum_discussion
(
$discussion3
->
id
);
$result
=
external_api
::
clean_returnvalue
(
mod_forum_external
::
view_forum_discussion_returns
(),
$result
);
$this
->
assertTrue
(
$result
[
'status'
]);
$this
->
assertEmpty
(
$result
[
'warnings'
]);
// Test posts have been marked as read.
$posts
=
mod_forum_external
::
get_forum_discussion_posts
(
$discussion3
->
id
,
'modified'
,
'DESC'
);
$posts
=
external_api
::
clean_returnvalue
(
mod_forum_external
::
get_forum_discussion_posts_returns
(),
$posts
);
foreach
(
$posts
[
'posts'
]
as
$post
)
{
$this
->
assertTrue
(
$post
[
'postread'
]);
}
}
/**
...
...
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