mirror of
https://github.com/moodle/moodle.git
synced 2025-04-16 14:02:32 +02:00
MDL-49566 core: Write unittests for MDL-45898
This commit is contained in:
parent
d955a20926
commit
bef0d6b052
@ -28,6 +28,8 @@ defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once($CFG->libdir . '/badgeslib.php');
|
||||
require_once($CFG->dirroot . '/badges/lib.php');
|
||||
require_once($CFG->dirroot . '/user/tests/fixtures/myprofile_fixtures.php');
|
||||
|
||||
class core_badges_badgeslib_testcase extends advanced_testcase {
|
||||
protected $badgeid;
|
||||
@ -472,4 +474,54 @@ class core_badges_badgeslib_testcase extends advanced_testcase {
|
||||
$this->assertStringMatchesFormat($testassertion->class, json_encode($assertion->get_badge_class()));
|
||||
$this->assertStringMatchesFormat($testassertion->issuer, json_encode($assertion->get_issuer()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for core_badges_myprofile_navigation() api.
|
||||
*/
|
||||
public function test_core_badges_myprofile_navigation() {
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
$user = $this->user;
|
||||
$badge = new badge($this->badgeid);
|
||||
$badge->issue($user->id, true);
|
||||
$this->assertTrue($badge->is_issued($user->id));
|
||||
|
||||
// Disable badges.
|
||||
set_config('enablebadges', false);
|
||||
$tree = new phpunit_fixture_myprofile_tree();
|
||||
$user2 = $this->getDataGenerator()->create_user();
|
||||
$course = null;
|
||||
$iscurrentuser = false;
|
||||
|
||||
core_badges_myprofile_navigation($tree, $user, $iscurrentuser, $course);
|
||||
$nodes = $tree->get_nodes();
|
||||
$this->assertArrayNotHasKey('localbadges', $nodes);
|
||||
|
||||
// Enable badges.
|
||||
set_config('enablebadges', true);
|
||||
$this->setUser($user);
|
||||
$tree = new phpunit_fixture_myprofile_tree();
|
||||
$iscurrentuser = true;
|
||||
core_badges_myprofile_navigation($tree, $user, $iscurrentuser, $course);
|
||||
$nodes = $tree->get_nodes();
|
||||
$this->assertArrayHasKey('localbadges', $nodes);
|
||||
|
||||
$tree = new phpunit_fixture_myprofile_tree();
|
||||
$iscurrentuser = true;
|
||||
core_badges_myprofile_navigation($tree, $user, $iscurrentuser, $course);
|
||||
$nodes = $tree->get_nodes();
|
||||
$this->assertArrayHasKey('localbadges', $nodes);
|
||||
|
||||
// Course badge.
|
||||
$badge = new badge($this->coursebadge);
|
||||
$badge->issue($user->id, true);
|
||||
$this->assertTrue($badge->is_issued($user->id));
|
||||
$course = $this->course;
|
||||
$this->setUser($user2);
|
||||
$tree = new phpunit_fixture_myprofile_tree();
|
||||
$iscurrentuser = false;
|
||||
core_badges_myprofile_navigation($tree, $user, $iscurrentuser, $course);
|
||||
$nodes = $tree->get_nodes();
|
||||
$this->assertArrayHasKey('localbadges', $nodes);
|
||||
}
|
||||
}
|
||||
|
@ -26,11 +26,12 @@
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/blog/locallib.php');
|
||||
require_once($CFG->dirroot . '/blog/lib.php');
|
||||
require_once($CFG->dirroot . '/user/tests/fixtures/myprofile_fixtures.php');
|
||||
|
||||
/**
|
||||
* Test functions that rely on the DB tables
|
||||
*/
|
||||
class core_bloglib_testcase extends advanced_testcase {
|
||||
class core_blog_lib_testcase extends advanced_testcase {
|
||||
|
||||
private $courseid;
|
||||
private $cmid;
|
||||
@ -476,5 +477,39 @@ class core_bloglib_testcase extends advanced_testcase {
|
||||
$this->assertEquals($url, $event->get_url());
|
||||
$this->assertEventContextNotUsed($event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for core_blog_myprofile_navigation() api.
|
||||
*/
|
||||
public function test_core_blog_myprofile_navigation() {
|
||||
global $USER;
|
||||
|
||||
$this->resetAfterTest();
|
||||
$this->setGuestUser();
|
||||
|
||||
// No blogs for guest users.
|
||||
$tree = new phpunit_fixture_myprofile_tree();
|
||||
$course = null;
|
||||
$iscurrentuser = false;
|
||||
core_blog_myprofile_navigation($tree, $USER, $iscurrentuser, $course);
|
||||
$nodes = $tree->get_nodes();
|
||||
$this->assertArrayNotHasKey('blogs', $nodes);
|
||||
|
||||
// Disable blogs.
|
||||
$this->setAdminUser();
|
||||
set_config('enableblogs', false);
|
||||
$tree = new phpunit_fixture_myprofile_tree();
|
||||
core_blog_myprofile_navigation($tree, $USER, $iscurrentuser, $course);
|
||||
$nodes = $tree->get_nodes();
|
||||
$this->assertArrayNotHasKey('blogs', $nodes);
|
||||
|
||||
// Enable badges.
|
||||
set_config('enableblogs', true);
|
||||
$tree = new phpunit_fixture_myprofile_tree();
|
||||
$iscurrentuser = true;
|
||||
core_blog_myprofile_navigation($tree, $USER, $iscurrentuser, $course);
|
||||
$nodes = $tree->get_nodes();
|
||||
$this->assertArrayHasKey('blogs', $nodes);
|
||||
}
|
||||
}
|
||||
|
67
grade/report/user/tests/lib_test.php
Normal file
67
grade/report/user/tests/lib_test.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Tests for gradereport_user library functions.
|
||||
*
|
||||
* @package gradereport_user
|
||||
* @copyright 2015 onwards Ankit agarwal <ankit.agrr@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/user/tests/fixtures/myprofile_fixtures.php');
|
||||
require_once($CFG->dirroot . '/grade/report/user/lib.php');
|
||||
|
||||
/**
|
||||
* Class gradereport_user_lib_testcase.
|
||||
*
|
||||
* @package gradereport_user
|
||||
* @copyright 2015 onwards Ankit agarwal <ankit.agrr@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
|
||||
*/
|
||||
class gradereport_user_lib_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Tests for gradereport_user_myprofile_navigation() api.
|
||||
*/
|
||||
public function test_gradereport_user_myprofile_navigation() {
|
||||
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
// User with all permissions.
|
||||
$tree = new phpunit_fixture_myprofile_tree();
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$user2 = $this->getDataGenerator()->create_user();
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$iscurrentuser = false;
|
||||
|
||||
gradereport_user_myprofile_navigation($tree, $user, $iscurrentuser, $course);
|
||||
$nodes = $tree->get_nodes();
|
||||
$this->assertArrayHasKey('grade', $nodes);
|
||||
|
||||
// Try to see as a user without permission.
|
||||
$this->setUser($user2);
|
||||
$tree = new phpunit_fixture_myprofile_tree();
|
||||
$iscurrentuser = true;
|
||||
gradereport_user_myprofile_navigation($tree, $user, $iscurrentuser, $course);
|
||||
$nodes = $tree->get_nodes();
|
||||
$this->assertArrayNotHasKey('grade', $nodes);
|
||||
}
|
||||
}
|
189
lib/tests/myprofilelib_test.php
Normal file
189
lib/tests/myprofilelib_test.php
Normal file
@ -0,0 +1,189 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Tests for myprofilelib apis.
|
||||
*
|
||||
* @package core
|
||||
* @copyright 2015 onwards Ankit agarwal <ankit.agrr@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/user/tests/fixtures/myprofile_fixtures.php');
|
||||
require_once($CFG->dirroot . '/lib/myprofilelib.php');
|
||||
|
||||
/**
|
||||
* Tests for myprofilelib apis.
|
||||
*
|
||||
* @package core
|
||||
* @copyright 2015 onwards Ankit agarwal <ankit.agrr@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
|
||||
*/
|
||||
class core_myprofilelib_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Tests for report_log_myprofile_navigation() api.
|
||||
*/
|
||||
public function test_core_myprofile_navigation() {
|
||||
global $CFG;
|
||||
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
$tree = new phpunit_fixture_myprofile_tree();
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$user2 = $this->getDataGenerator()->create_user();
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$iscurrentuser = false;
|
||||
|
||||
// Test tree as admin user.
|
||||
core_myprofile_navigation($tree, $user, $iscurrentuser, $course);
|
||||
$cats = $tree->get_categories();
|
||||
$this->assertArrayHasKey('contact', $cats);
|
||||
$this->assertArrayHasKey('coursedetails', $cats);
|
||||
$this->assertArrayHasKey('miscellaneous', $cats);
|
||||
$this->assertArrayHasKey('reports', $cats);
|
||||
$this->assertArrayHasKey('administration', $cats);
|
||||
$this->assertArrayHasKey('loginactivity', $cats);
|
||||
|
||||
// Course node.
|
||||
$nodes = $tree->get_nodes();
|
||||
$this->assertArrayHasKey('fullprofile', $nodes);
|
||||
|
||||
// User without permission cannot access full course profile.
|
||||
$this->setUser($user2);
|
||||
$tree = new phpunit_fixture_myprofile_tree();
|
||||
core_myprofile_navigation($tree, $user, $iscurrentuser, $course);
|
||||
$nodes = $tree->get_nodes();
|
||||
$this->assertArrayNotHasKey('fullprofile', $nodes);
|
||||
|
||||
// Edit profile link.
|
||||
$this->setUser($user);
|
||||
$iscurrentuser = true;
|
||||
$tree = new phpunit_fixture_myprofile_tree();
|
||||
core_myprofile_navigation($tree, $user, $iscurrentuser, $course);
|
||||
$nodes = $tree->get_nodes();
|
||||
$this->assertArrayHasKey('editprofile', $nodes);
|
||||
|
||||
// Edit profile link as admin user.
|
||||
$this->setAdminUser();
|
||||
$iscurrentuser = false;
|
||||
$tree = new phpunit_fixture_myprofile_tree();
|
||||
core_myprofile_navigation($tree, $user, $iscurrentuser, $course);
|
||||
$nodes = $tree->get_nodes();
|
||||
$this->assertArrayHasKey('editprofile', $nodes);
|
||||
|
||||
// Preference page.
|
||||
$this->setAdminUser();
|
||||
$iscurrentuser = false;
|
||||
$tree = new phpunit_fixture_myprofile_tree();
|
||||
core_myprofile_navigation($tree, $user, $iscurrentuser, $course);
|
||||
$nodes = $tree->get_nodes();
|
||||
$this->assertArrayHasKey('preferences', $nodes);
|
||||
|
||||
// Login as.
|
||||
$this->setAdminUser();
|
||||
$iscurrentuser = false;
|
||||
$tree = new phpunit_fixture_myprofile_tree();
|
||||
core_myprofile_navigation($tree, $user, $iscurrentuser, $course);
|
||||
$nodes = $tree->get_nodes();
|
||||
$this->assertArrayHasKey('loginas', $nodes);
|
||||
|
||||
// Login as link for a user who doesn't have the cap.
|
||||
$this->setUser($user2);
|
||||
$tree = new phpunit_fixture_myprofile_tree();
|
||||
core_myprofile_navigation($tree, $user, $iscurrentuser, $course);
|
||||
$nodes = $tree->get_nodes();
|
||||
$this->assertArrayNotHasKey('loginas', $nodes);
|
||||
|
||||
// User contact fields.
|
||||
set_config("hiddenuserfields", "country,city,webpage,icqnumber,skypeid,yahooid,aimid,msnid");
|
||||
set_config("showuseridentity", "email,address,phone1,phone2,institution,department,idnumber");
|
||||
$hiddenfields = explode(',', $CFG->hiddenuserfields);
|
||||
$identityfields = explode(',', $CFG->showuseridentity);
|
||||
$this->setAdminUser();
|
||||
$iscurrentuser = false;
|
||||
|
||||
// Make sure fields are not empty.
|
||||
$fields = array(
|
||||
'country' => 'AU',
|
||||
'city' => 'Silent hill',
|
||||
'url' => 'Ghosts',
|
||||
'icq' => 'Wth is ICQ?',
|
||||
'skype' => 'derp',
|
||||
'yahoo' => 'are you living in the 90\'s?',
|
||||
'aim' => 'are you for real?',
|
||||
'msn' => '...',
|
||||
'email' => 'Rulelikeaboss@example.com',
|
||||
'address' => 'Didn\'t I mention silent hill already ?',
|
||||
'phone1' => '123',
|
||||
'phone2' => '234',
|
||||
'institution' => 'strange land',
|
||||
'department' => 'video game/movie',
|
||||
'idnumber' => 'SLHL'
|
||||
);
|
||||
foreach ($fields as $field => $value) {
|
||||
$user->$field = $value;
|
||||
}
|
||||
|
||||
// User with proper permissions.
|
||||
$tree = new phpunit_fixture_myprofile_tree();
|
||||
core_myprofile_navigation($tree, $user, $iscurrentuser, null);
|
||||
$nodes = $tree->get_nodes();
|
||||
foreach ($hiddenfields as $field) {
|
||||
$this->assertArrayHasKey($field, $nodes);
|
||||
}
|
||||
foreach ($identityfields as $field) {
|
||||
$this->assertArrayHasKey($field, $nodes);
|
||||
}
|
||||
|
||||
// User without permission.
|
||||
$this->setUser($user2);
|
||||
$tree = new phpunit_fixture_myprofile_tree();
|
||||
core_myprofile_navigation($tree, $user, $iscurrentuser, null);
|
||||
$nodes = $tree->get_nodes();
|
||||
foreach ($hiddenfields as $field) {
|
||||
$this->assertArrayNotHasKey($field, $nodes);
|
||||
}
|
||||
foreach ($identityfields as $field) {
|
||||
$this->assertArrayNotHasKey($field, $nodes);
|
||||
}
|
||||
|
||||
// First access, last access, last ip.
|
||||
$this->setAdminUser();
|
||||
$iscurrentuser = false;
|
||||
$tree = new phpunit_fixture_myprofile_tree();
|
||||
core_myprofile_navigation($tree, $user, $iscurrentuser, null);
|
||||
$nodes = $tree->get_nodes();
|
||||
$this->assertArrayHasKey('firstaccess', $nodes);
|
||||
$this->assertArrayHasKey('lastaccess', $nodes);
|
||||
$this->assertArrayHasKey('lastip', $nodes);
|
||||
|
||||
// User without permission.
|
||||
set_config("hiddenuserfields", "firstaccess,lastaccess,lastip");
|
||||
$this->setUser($user2);
|
||||
$iscurrentuser = false;
|
||||
$tree = new phpunit_fixture_myprofile_tree();
|
||||
core_myprofile_navigation($tree, $user, $iscurrentuser, null);
|
||||
$nodes = $tree->get_nodes();
|
||||
$this->assertArrayNotHasKey('firstaccess', $nodes);
|
||||
$this->assertArrayNotHasKey('lastaccess', $nodes);
|
||||
$this->assertArrayNotHasKey('lastip', $nodes);
|
||||
}
|
||||
}
|
@ -27,6 +27,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/mod/forum/lib.php');
|
||||
require_once($CFG->dirroot . '/rating/lib.php');
|
||||
require_once($CFG->dirroot . '/user/tests/fixtures/myprofile_fixtures.php');
|
||||
|
||||
class mod_forum_lib_testcase extends advanced_testcase {
|
||||
|
||||
@ -2114,4 +2115,44 @@ class mod_forum_lib_testcase extends advanced_testcase {
|
||||
$can = forum_user_can_post_discussion($forum, null, -1, $cm, $context);
|
||||
$this->assertTrue($can);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for mod_forum_myprofile_navigation() api.
|
||||
*/
|
||||
public function test_mod_forum_myprofile_navigation() {
|
||||
global $USER;
|
||||
|
||||
$this->resetAfterTest();
|
||||
$this->setGuestUser();
|
||||
|
||||
$tree = new phpunit_fixture_myprofile_tree();
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$user2 = $this->getDataGenerator()->create_user();
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$iscurrentuser = false;
|
||||
|
||||
// Nothing for guest users.
|
||||
mod_forum_myprofile_navigation($tree, $USER, $iscurrentuser, $course);
|
||||
$nodes = $tree->get_nodes();
|
||||
$this->assertArrayNotHasKey('forumposts', $nodes);
|
||||
$this->assertArrayNotHasKey('forumdiscussions', $nodes);
|
||||
|
||||
// Current user.
|
||||
$this->setUser($user);
|
||||
$tree = new phpunit_fixture_myprofile_tree();
|
||||
$iscurrentuser = true;
|
||||
mod_forum_myprofile_navigation($tree, $user, $iscurrentuser, $course);
|
||||
$nodes = $tree->get_nodes();
|
||||
$this->assertArrayHasKey('forumposts', $nodes);
|
||||
$this->assertArrayHasKey('forumdiscussions', $nodes);
|
||||
|
||||
// Different user's profile.
|
||||
$this->setUser($user2);
|
||||
$tree = new phpunit_fixture_myprofile_tree();
|
||||
$iscurrentuser = true;
|
||||
mod_forum_myprofile_navigation($tree, $user, $iscurrentuser, $course);
|
||||
$nodes = $tree->get_nodes();
|
||||
$this->assertArrayHasKey('forumposts', $nodes);
|
||||
$this->assertArrayHasKey('forumdiscussions', $nodes);
|
||||
}
|
||||
}
|
||||
|
72
notes/tests/lib_test.php
Normal file
72
notes/tests/lib_test.php
Normal file
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Tests for notes library functions.
|
||||
*
|
||||
* @package core_notes
|
||||
* @copyright 2015 onwards Ankit agarwal <ankit.agrr@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/notes/lib.php');
|
||||
require_once($CFG->dirroot . '/user/tests/fixtures/myprofile_fixtures.php');
|
||||
/**
|
||||
* Class core_notes_lib_testcase
|
||||
*
|
||||
* @package core_notes
|
||||
* @copyright 2015 onwards Ankit agarwal <ankit.agrr@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
|
||||
*/
|
||||
class core_notes_lib_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Tests for core_notes_myprofile_navigation() api.
|
||||
*/
|
||||
public function test_core_notes_myprofile_navigation() {
|
||||
global $USER;
|
||||
|
||||
$this->resetAfterTest();
|
||||
$this->setGuestUser();
|
||||
|
||||
// No notes for guest users.
|
||||
$tree = new phpunit_fixture_myprofile_tree();
|
||||
$course = null;
|
||||
$iscurrentuser = false;
|
||||
core_notes_myprofile_navigation($tree, $USER, $iscurrentuser, $course);
|
||||
$nodes = $tree->get_nodes();
|
||||
$this->assertArrayNotHasKey('blogs', $nodes);
|
||||
|
||||
// Disable notes.
|
||||
$this->setAdminUser();
|
||||
set_config('enablenotes', false);
|
||||
$tree = new phpunit_fixture_myprofile_tree();
|
||||
core_notes_myprofile_navigation($tree, $USER, $iscurrentuser, $course);
|
||||
$nodes = $tree->get_nodes();
|
||||
$this->assertArrayNotHasKey('notes', $nodes);
|
||||
|
||||
// Enable notes.
|
||||
set_config('enablenotes', true);
|
||||
$tree = new phpunit_fixture_myprofile_tree();
|
||||
$iscurrentuser = true;
|
||||
core_notes_myprofile_navigation($tree, $USER, $iscurrentuser, $course);
|
||||
$nodes = $tree->get_nodes();
|
||||
$this->assertArrayHasKey('notes', $nodes);
|
||||
}
|
||||
}
|
@ -24,6 +24,9 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/user/tests/fixtures/myprofile_fixtures.php');
|
||||
|
||||
/**
|
||||
* Class report_log_events_testcase.
|
||||
*
|
||||
@ -54,4 +57,34 @@ class report_log_lib_testcase extends advanced_testcase {
|
||||
$this->assertContains($expectedstore, $stores);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for report_log_myprofile_navigation() api.
|
||||
*/
|
||||
public function test_report_log_myprofile_navigation() {
|
||||
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
$tree = new phpunit_fixture_myprofile_tree();
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$user2 = $this->getDataGenerator()->create_user();
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$iscurrentuser = false;
|
||||
|
||||
// As user with permissions.
|
||||
report_log_myprofile_navigation($tree, $user, $iscurrentuser, $course);
|
||||
$nodes = $tree->get_nodes();
|
||||
$this->assertArrayHasKey('alllogs', $nodes);
|
||||
$this->assertArrayHasKey('todayslogs', $nodes);
|
||||
|
||||
// Try to see as a user without permission.
|
||||
$this->setUser($user2);
|
||||
$tree = new phpunit_fixture_myprofile_tree();
|
||||
$iscurrentuser = true;
|
||||
report_log_myprofile_navigation($tree, $user, $iscurrentuser, $course);
|
||||
$nodes = $tree->get_nodes();
|
||||
$this->assertArrayNotHasKey('alllogs', $nodes);
|
||||
$this->assertArrayNotHasKey('todayslogs', $nodes);
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,9 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/user/tests/fixtures/myprofile_fixtures.php');
|
||||
|
||||
/**
|
||||
* Class report_outline_lib_testcase
|
||||
*
|
||||
@ -53,4 +56,40 @@ class report_outline_lib_testcase extends advanced_testcase {
|
||||
$this->assertContains($expectedstore, $stores);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for report_outline_myprofile_navigation() api.
|
||||
*/
|
||||
public function test_report_outline_myprofile_navigation() {
|
||||
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
$tree = new phpunit_fixture_myprofile_tree();
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$user2 = $this->getDataGenerator()->create_user();
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$iscurrentuser = false;
|
||||
|
||||
report_outline_myprofile_navigation($tree, $user, $iscurrentuser, $course);
|
||||
$nodes = $tree->get_nodes();
|
||||
$this->assertArrayHasKey('outline', $nodes);
|
||||
$this->assertArrayHasKey('complete', $nodes);
|
||||
|
||||
$tree = new phpunit_fixture_myprofile_tree();
|
||||
$iscurrentuser = true;
|
||||
report_outline_myprofile_navigation($tree, $user, $iscurrentuser, $course);
|
||||
$nodes = $tree->get_nodes();
|
||||
$this->assertArrayHasKey('outline', $nodes);
|
||||
$this->assertArrayHasKey('complete', $nodes);
|
||||
|
||||
// Try to see as a user without permission.
|
||||
$this->setUser($user2);
|
||||
$tree = new phpunit_fixture_myprofile_tree();
|
||||
$iscurrentuser = true;
|
||||
report_outline_myprofile_navigation($tree, $user, $iscurrentuser, $course);
|
||||
$nodes = $tree->get_nodes();
|
||||
$this->assertArrayNotHasKey('outline', $nodes);
|
||||
$this->assertArrayNotHasKey('complete', $nodes);
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,9 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/user/tests/fixtures/myprofile_fixtures.php');
|
||||
|
||||
/**
|
||||
* Class report_stats_lib_testcase
|
||||
*
|
||||
@ -53,4 +56,50 @@ class report_stats_lib_testcase extends advanced_testcase {
|
||||
$this->assertContains($expectedstore, $stores);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for report_stats_myprofile_navigation() api.
|
||||
*/
|
||||
public function test_report_stats_myprofile_navigation() {
|
||||
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
// Enabling stats.
|
||||
set_config('enablestats', true);
|
||||
|
||||
$tree = new phpunit_fixture_myprofile_tree();
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$user2 = $this->getDataGenerator()->create_user();
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$iscurrentuser = false;
|
||||
|
||||
report_stats_myprofile_navigation($tree, $user, $iscurrentuser, $course);
|
||||
$nodes = $tree->get_nodes();
|
||||
$this->assertArrayHasKey('stats', $nodes);
|
||||
|
||||
$tree = new phpunit_fixture_myprofile_tree();
|
||||
$iscurrentuser = true;
|
||||
report_stats_myprofile_navigation($tree, $user, $iscurrentuser, $course);
|
||||
$nodes = $tree->get_nodes();
|
||||
$this->assertArrayHasKey('stats', $nodes);
|
||||
|
||||
// Disabling stats.
|
||||
set_config('enablestats', false);
|
||||
$tree = new phpunit_fixture_myprofile_tree();
|
||||
$iscurrentuser = true;
|
||||
report_stats_myprofile_navigation($tree, $user, $iscurrentuser, $course);
|
||||
$nodes = $tree->get_nodes();
|
||||
$this->assertArrayNotHasKey('stats', $nodes);
|
||||
|
||||
// Enabling stats.
|
||||
set_config('enablestats', true);
|
||||
|
||||
// Try to see as a user without permission.
|
||||
$this->setUser($user2);
|
||||
$tree = new phpunit_fixture_myprofile_tree();
|
||||
$iscurrentuser = true;
|
||||
report_stats_myprofile_navigation($tree, $user, $iscurrentuser, $course);
|
||||
$nodes = $tree->get_nodes();
|
||||
$this->assertArrayNotHasKey('stats', $nodes);
|
||||
}
|
||||
}
|
||||
|
82
report/usersessions/tests/lib_test.php
Normal file
82
report/usersessions/tests/lib_test.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Tests for report library functions.
|
||||
*
|
||||
* @package report_usersessions
|
||||
* @copyright 2015 onwards Ankit agarwal <ankit.agrr@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/user/tests/fixtures/myprofile_fixtures.php');
|
||||
require_once($CFG->dirroot. '/report/usersessions/lib.php');
|
||||
|
||||
/**
|
||||
* Class report_stats_lib_testcase
|
||||
*
|
||||
* @package report_usersessions
|
||||
* @copyright 2014 onwards Ankit agarwal <ankit.agrr@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
|
||||
*/
|
||||
class report_usersessions_lib_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Tests for report_userssesions_myprofile_navigation() api.
|
||||
*/
|
||||
public function test_report_usersessions_myprofile_navigation() {
|
||||
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
$tree = new phpunit_fixture_myprofile_tree();
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$user2 = $this->getDataGenerator()->create_user();
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$iscurrentuser = false;
|
||||
|
||||
// Not even admins allowed to pick at other user's sessions.
|
||||
report_usersessions_myprofile_navigation($tree, $user, $iscurrentuser, $course);
|
||||
$nodes = $tree->get_nodes();
|
||||
$this->assertArrayNotHasKey('usersessions', $nodes);
|
||||
|
||||
// Try as guest user.
|
||||
$this->setGuestUser();
|
||||
report_usersessions_myprofile_navigation($tree, $user, $iscurrentuser, $course);
|
||||
$nodes = $tree->get_nodes();
|
||||
$this->assertArrayNotHasKey('usersessions', $nodes);
|
||||
|
||||
// As current user.
|
||||
$this->setUser($user);
|
||||
$tree = new phpunit_fixture_myprofile_tree();
|
||||
$iscurrentuser = true;
|
||||
report_usersessions_myprofile_navigation($tree, $user, $iscurrentuser, $course);
|
||||
$nodes = $tree->get_nodes();
|
||||
$this->assertArrayHasKey('usersessions', $nodes);
|
||||
|
||||
// Try to see as a user without permission.
|
||||
$this->setUser($user2);
|
||||
$tree = new phpunit_fixture_myprofile_tree();
|
||||
$iscurrentuser = true;
|
||||
report_usersessions_myprofile_navigation($tree, $user, $iscurrentuser, $course);
|
||||
$nodes = $tree->get_nodes();
|
||||
$this->assertArrayNotHasKey('usersessions', $nodes);
|
||||
|
||||
}
|
||||
}
|
14
user/tests/fixtures/myprofile_fixtures.php
vendored
14
user/tests/fixtures/myprofile_fixtures.php
vendored
@ -70,4 +70,18 @@ class phpunit_fixture_myprofile_tree extends \core_user\output\myprofile\tree {
|
||||
public function find_categories_after($cat) {
|
||||
return parent::find_categories_after($cat);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \core_user\output\myprofile\category[]
|
||||
*/
|
||||
public function get_categories() {
|
||||
return $this->categories;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \core_user\output\myprofile\node[]
|
||||
*/
|
||||
public function get_nodes() {
|
||||
return $this->nodes;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user