Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
integration
prechecker
Commits
935ee1c6
Commit
935ee1c6
authored
Apr 11, 2016
by
Eric Merrill
Browse files
MDL-53167 search: Adding unit tests for external API change
parent
427e3cbc
Changes
2
Hide whitespace changes
Inline
Side-by-side
course/externallib.php
View file @
935ee1c6
...
...
@@ -2221,7 +2221,7 @@ class core_course_external extends external_api {
foreach
(
$courses
as
$course
)
{
if
(
!
empty
(
$limittoenrolled
))
{
// Filter out not enrolled courses.
if
(
empty
(
$enrolled
[
$course
->
id
]))
{
if
(
!
isset
(
$enrolled
[
$course
->
id
]))
{
$totalcount
--
;
continue
;
}
...
...
course/tests/externallib_test.php
View file @
935ee1c6
...
...
@@ -652,6 +652,14 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
// Now as a normal user.
$user
=
self
::
getDataGenerator
()
->
create_user
();
// Add a 3rd, hidden, course we shouldn't see, even when enrolled as student.
$coursedata3
[
'fullname'
]
=
'HIDDEN COURSE'
;
$coursedata3
[
'visible'
]
=
0
;
$course3
=
self
::
getDataGenerator
()
->
create_course
(
$coursedata3
);
$this
->
getDataGenerator
()
->
enrol_user
(
$user
->
id
,
$course3
->
id
,
'student'
);
$this
->
getDataGenerator
()
->
enrol_user
(
$user
->
id
,
$course2
->
id
,
'student'
);
$this
->
setUser
(
$user
);
$results
=
core_course_external
::
search_courses
(
'search'
,
'FIRST'
);
...
...
@@ -660,6 +668,19 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
$this
->
assertEquals
(
1
,
$results
[
'total'
]);
$this
->
assertEquals
(
$coursedata1
[
'fullname'
],
$results
[
'courses'
][
0
][
'fullname'
]);
// Check that we can see both without the limit to enrolled setting.
$results
=
core_course_external
::
search_courses
(
'search'
,
'COURSE'
,
0
,
0
,
array
(),
0
);
$results
=
external_api
::
clean_returnvalue
(
core_course_external
::
search_courses_returns
(),
$results
);
$this
->
assertCount
(
2
,
$results
[
'courses'
]);
$this
->
assertEquals
(
2
,
$results
[
'total'
]);
// Check that we only see our enrolled course when limiting.
$results
=
core_course_external
::
search_courses
(
'search'
,
'COURSE'
,
0
,
0
,
array
(),
1
);
$results
=
external_api
::
clean_returnvalue
(
core_course_external
::
search_courses_returns
(),
$results
);
$this
->
assertCount
(
1
,
$results
[
'courses'
]);
$this
->
assertEquals
(
1
,
$results
[
'total'
]);
$this
->
assertEquals
(
$coursedata2
[
'fullname'
],
$results
[
'courses'
][
0
][
'fullname'
]);
// Search by block (use news_items default block). Should fail (only admins allowed).
$this
->
setExpectedException
(
'required_capability_exception'
);
$results
=
core_course_external
::
search_courses
(
'blocklist'
,
$blockid
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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