Files
moodle/lib/tests/phpunit_test.php
T

103 lines
3.1 KiB
PHP

<?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/>.
/**
* PHPUnit integration unit tests
*
* @package core
* @category phpunit
* @copyright 2012 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Test basic_testcase extra features and PHPUnit Moodle integration.
*
* @package core
* @category phpunit
* @copyright 2012 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_phpunit_basic_testcase extends basic_testcase {
/**
* Tests that bootstrapping has occurred correctly
* @return void
*/
public function test_bootstrap() {
global $CFG;
$this->assertTrue(isset($CFG->httpswwwroot));
$this->assertEquals($CFG->httpswwwroot, $CFG->wwwroot);
$this->assertEquals($CFG->prefix, $CFG->phpunit_prefix);
}
/*
public function test_borked_tests() {
global $DB;
$DB->set_field('user', 'confirmed', 1, array('id'=>-1));
$CFG->xx = 'yy';
}
*/
}
/**
* Test advanced_testcase extra features.
*
* @package core
* @category phpunit
* @copyright 2012 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_phpunit_advanced_testcase extends advanced_testcase {
public function test_set_user() {
global $USER, $DB;
$this->assertEquals(0, $USER->id);
$this->assertSame($_SESSION['USER'], $USER);
$user = $DB->get_record('user', array('id'=>2));
$this->setUser($user);
$this->assertEquals(2, $USER->id);
$this->assertEquals(2, $_SESSION['USER']->id);
$this->assertSame($_SESSION['USER'], $USER);
$USER->id = 3;
$this->assertEquals(3, $USER->id);
$this->assertEquals(3, $_SESSION['USER']->id);
$this->assertSame($_SESSION['USER'], $USER);
session_set_user($user);
$this->assertEquals(2, $USER->id);
$this->assertEquals(2, $_SESSION['USER']->id);
$this->assertSame($_SESSION['USER'], $USER);
$USER = $DB->get_record('user', array('id'=>1));
$this->assertEquals(1, $USER->id);
$this->assertEquals(1, $_SESSION['USER']->id);
$this->assertSame($_SESSION['USER'], $USER);
$this->setUser(null);
$this->assertEquals(0, $USER->id);
$this->assertSame($_SESSION['USER'], $USER);
}
}