MDL-32149 add basic file picker test and new way to set current user via int

Please note that testing of individual plugins should not be done in repositorylib_test.php.
This commit is contained in:
Petr Skoda
2012-04-03 22:31:01 +02:00
parent f4fd0a13d1
commit e72ea4a5e4
2 changed files with 64 additions and 5 deletions
+7 -5
View File
@@ -845,18 +845,20 @@ class advanced_testcase extends PHPUnit_Framework_TestCase {
/**
* Set current $USER, reset access cache.
* @static
* @param null|\stdClass $user user record, null means none
* @param null|int|stdClass $user user record, null means non-logged-in, integer means userid
* @return void
*/
public static function setUser(stdClass $user = null) {
global $CFG;
public static function setUser($user = null) {
global $CFG, $DB;
if (!$user) {
if (is_object($user)) {
$user = clone($user);
} else if (!$user) {
$user = new stdClass();
$user->id = 0;
$user->mnethostid = $CFG->mnet_localhost_id;
} else {
$user = clone($user);
$user = $DB->get_record('user', array('id'=>$user));
}
unset($user->description);
unset($user->access);
+57
View File
@@ -0,0 +1,57 @@
<?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/>.
/**
* Unit tests for ../repositorylib.php.
*
* @package core_repository
* @category phpunit
* @author [email protected]
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once("$CFG->dirroot/repository/lib.php");
class repositorylib_testcase extends advanced_testcase {
public function test_initialise_filepicker() {
global $PAGE, $SITE;
$this->resetAfterTest(true);
$PAGE->set_url('/');
$PAGE->set_course($SITE);
$this->setUser(2);
$args = new stdClass();
$args->accepted_types = '*';
$args->return_types = array(FILE_EXTERNAL);
$info = initialise_filepicker($args);
$this->assertInstanceOf('stdClass', $info);
$this->assertObjectHasAttribute('defaultlicense', $info);
$this->assertObjectHasAttribute('licenses', $info);
$this->assertObjectHasAttribute('author', $info);
$this->assertObjectHasAttribute('externallink', $info);
$this->assertObjectHasAttribute('accepted_types', $info);
$this->assertObjectHasAttribute('return_types', $info);
}
}