Merge branch 'w32_MDL-40901_m26_phpunitcleanup2' of https://github.com/skodak/moodle

This commit is contained in:
Sam Hemelryk 2013-08-06 08:53:24 +12:00
commit b09abb05ab
51 changed files with 357 additions and 273 deletions

View File

@ -34,7 +34,7 @@ require_once($CFG->libdir . '/authlib.php');
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class auth_testcase extends advanced_testcase {
class core_auth_testcase extends advanced_testcase {
public function test_user_loggedin_event() {
global $USER;

View File

@ -30,7 +30,7 @@ require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
/*
* controller tests (all)
*/
class backup_controller_testcase extends advanced_testcase {
class core_backup_controller_testcase extends advanced_testcase {
protected $moduleid; // course_modules id used for testing
protected $sectionid; // course_sections id used for testing

View File

@ -30,7 +30,7 @@ global $CFG;
require_once($CFG->dirroot . '/backup/converter/moodle1/lib.php');
class moodle1_converter_testcase extends advanced_testcase {
class core_backup_moodle1_converter_testcase extends advanced_testcase {
/** @var string the name of the directory containing the unpacked Moodle 1.9 backup */
protected $tempdir;

View File

@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->libdir . '/badgeslib.php');
class badges_testcase extends advanced_testcase {
class core_badgeslib_testcase extends advanced_testcase {
protected $badgeid;
protected function setUp() {

View File

@ -31,7 +31,7 @@ require_once($CFG->dirroot . '/blog/lib.php');
/**
* Test functions that rely on the DB tables
*/
class bloglib_testcase extends advanced_testcase {
class core_bloglib_testcase extends advanced_testcase {
private $courseid; // To store important ids to be used in tests
private $cmid;

View File

@ -0,0 +1,236 @@
<?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 tests for the cache API and in particular things in locallib.php
*
* This file is part of Moodle's cache API, affectionately called MUC.
* It contains the components that are requried in order to use caching.
*
* @package core
* @category cache
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
// Include the necessary evils.
global $CFG;
require_once($CFG->dirroot.'/cache/locallib.php');
require_once($CFG->dirroot.'/cache/tests/fixtures/lib.php');
/**
* PHPunit tests for the cache API and in particular the cache_administration_helper
*
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_cache_administration_helper_testcase extends advanced_testcase {
/**
* Set things back to the default before each test.
*/
public function setUp() {
parent::setUp();
cache_factory::reset();
cache_config_phpunittest::create_default_configuration();
}
/**
* Final task is to reset the cache system
*/
public static function tearDownAfterClass() {
parent::tearDownAfterClass();
cache_factory::reset();
}
/**
* Test the numerous summaries the helper can produce.
*/
public function test_get_summaries() {
// First the preparation.
$config = cache_config_writer::instance();
$this->assertTrue($config->add_store_instance('summariesstore', 'file'));
$config->set_definition_mappings('core/eventinvalidation', array('summariesstore'));
$this->assertTrue($config->set_mode_mappings(array(
cache_store::MODE_APPLICATION => array('summariesstore'),
cache_store::MODE_SESSION => array('default_session'),
cache_store::MODE_REQUEST => array('default_request'),
)));
$storesummaries = cache_administration_helper::get_store_instance_summaries();
$this->assertInternalType('array', $storesummaries);
$this->assertArrayHasKey('summariesstore', $storesummaries);
$summary = $storesummaries['summariesstore'];
// Check the keys
$this->assertArrayHasKey('name', $summary);
$this->assertArrayHasKey('plugin', $summary);
$this->assertArrayHasKey('default', $summary);
$this->assertArrayHasKey('isready', $summary);
$this->assertArrayHasKey('requirementsmet', $summary);
$this->assertArrayHasKey('mappings', $summary);
$this->assertArrayHasKey('modes', $summary);
$this->assertArrayHasKey('supports', $summary);
// Check the important/known values
$this->assertEquals('summariesstore', $summary['name']);
$this->assertEquals('file', $summary['plugin']);
$this->assertEquals(0, $summary['default']);
$this->assertEquals(1, $summary['isready']);
$this->assertEquals(1, $summary['requirementsmet']);
$this->assertEquals(1, $summary['mappings']);
$definitionsummaries = cache_administration_helper::get_definition_summaries();
$this->assertInternalType('array', $definitionsummaries);
$this->assertArrayHasKey('core/eventinvalidation', $definitionsummaries);
$summary = $definitionsummaries['core/eventinvalidation'];
// Check the keys
$this->assertArrayHasKey('id', $summary);
$this->assertArrayHasKey('name', $summary);
$this->assertArrayHasKey('mode', $summary);
$this->assertArrayHasKey('component', $summary);
$this->assertArrayHasKey('area', $summary);
$this->assertArrayHasKey('mappings', $summary);
// Check the important/known values
$this->assertEquals('core/eventinvalidation', $summary['id']);
$this->assertInstanceOf('lang_string', $summary['name']);
$this->assertEquals(cache_store::MODE_APPLICATION, $summary['mode']);
$this->assertEquals('core', $summary['component']);
$this->assertEquals('eventinvalidation', $summary['area']);
$this->assertInternalType('array', $summary['mappings']);
$this->assertContains('summariesstore', $summary['mappings']);
$pluginsummaries = cache_administration_helper::get_store_plugin_summaries();
$this->assertInternalType('array', $pluginsummaries);
$this->assertArrayHasKey('file', $pluginsummaries);
$summary = $pluginsummaries['file'];
// Check the keys
$this->assertArrayHasKey('name', $summary);
$this->assertArrayHasKey('requirementsmet', $summary);
$this->assertArrayHasKey('instances', $summary);
$this->assertArrayHasKey('modes', $summary);
$this->assertArrayHasKey('supports', $summary);
$this->assertArrayHasKey('canaddinstance', $summary);
$locksummaries = cache_administration_helper::get_lock_summaries();
$this->assertInternalType('array', $locksummaries);
$this->assertTrue(count($locksummaries) > 0);
$mappings = cache_administration_helper::get_default_mode_stores();
$this->assertInternalType('array', $mappings);
$this->assertCount(3, $mappings);
$this->assertArrayHasKey(cache_store::MODE_APPLICATION, $mappings);
$this->assertInternalType('array', $mappings[cache_store::MODE_APPLICATION]);
$this->assertContains('summariesstore', $mappings[cache_store::MODE_APPLICATION]);
$potentials = cache_administration_helper::get_definition_store_options('core', 'eventinvalidation');
$this->assertInternalType('array', $potentials); // Currently used, suitable, default
$this->assertCount(3, $potentials);
$this->assertArrayHasKey('summariesstore', $potentials[0]);
$this->assertArrayHasKey('summariesstore', $potentials[1]);
$this->assertArrayHasKey('default_application', $potentials[1]);
}
/**
* Test instantiating an add store form.
*/
public function test_get_add_store_form() {
$form = cache_administration_helper::get_add_store_form('file');
$this->assertInstanceOf('moodleform', $form);
try {
$form = cache_administration_helper::get_add_store_form('somethingstupid');
$this->fail('You should not be able to create an add form for a store plugin that does not exist.');
} catch (moodle_exception $e) {
$this->assertInstanceOf('coding_exception', $e, 'Needs to be: ' .get_class($e)." ::: ".$e->getMessage());
}
}
/**
* Test instantiating a form to edit a store instance.
*/
public function test_get_edit_store_form() {
$config = cache_config_writer::instance();
$this->assertTrue($config->add_store_instance('summariesstore', 'file'));
$form = cache_administration_helper::get_edit_store_form('file', 'summariesstore');
$this->assertInstanceOf('moodleform', $form);
try {
$form = cache_administration_helper::get_edit_store_form('somethingstupid', 'moron');
$this->fail('You should not be able to create an edit form for a store plugin that does not exist.');
} catch (moodle_exception $e) {
$this->assertInstanceOf('coding_exception', $e);
}
try {
$form = cache_administration_helper::get_edit_store_form('file', 'blisters');
$this->fail('You should not be able to create an edit form for a store plugin that does not exist.');
} catch (moodle_exception $e) {
$this->assertInstanceOf('coding_exception', $e);
}
}
/**
* Test the hash_key functionality.
*/
public function test_hash_key() {
global $CFG;
$currentdebugging = $CFG->debug;
$CFG->debug = E_ALL;
// First with simplekeys
$instance = cache_config_phpunittest::instance(true);
$instance->phpunit_add_definition('phpunit/hashtest', array(
'mode' => cache_store::MODE_APPLICATION,
'component' => 'phpunit',
'area' => 'hashtest',
'simplekeys' => true
));
$factory = cache_factory::instance();
$definition = $factory->create_definition('phpunit', 'hashtest');
$result = cache_helper::hash_key('test', $definition);
$this->assertEquals('test-'.$definition->generate_single_key_prefix(), $result);
try {
cache_helper::hash_key('test/test', $definition);
$this->fail('Invalid key was allowed, you should see this.');
} catch (coding_exception $e) {
$this->assertEquals('test/test', $e->debuginfo);
}
// Second without simple keys
$instance->phpunit_add_definition('phpunit/hashtest2', array(
'mode' => cache_store::MODE_APPLICATION,
'component' => 'phpunit',
'area' => 'hashtest2',
'simplekeys' => false
));
$definition = $factory->create_definition('phpunit', 'hashtest2');
$result = cache_helper::hash_key('test', $definition);
$this->assertEquals(sha1($definition->generate_single_key_prefix().'-test'), $result);
$result = cache_helper::hash_key('test/test', $definition);
$this->assertEquals(sha1($definition->generate_single_key_prefix().'-test/test'), $result);
$CFG->debug = $currentdebugging;
}
}

View File

@ -39,7 +39,7 @@ require_once($CFG->dirroot.'/cache/tests/fixtures/lib.php');
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class cache_phpunit_tests extends advanced_testcase {
class core_cache_testcase extends advanced_testcase {
/**
* Set things back to the default before each test.

View File

@ -39,7 +39,7 @@ require_once($CFG->dirroot.'/cache/tests/fixtures/lib.php');
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class cache_config_writer_phpunit_tests extends advanced_testcase {
class core_cache_config_writer_testcase extends advanced_testcase {
/**
* Set things back to the default before each test.
@ -288,204 +288,3 @@ class cache_config_writer_phpunit_tests extends advanced_testcase {
}
}
}
/**
* PHPunit tests for the cache API and in particular the cache_administration_helper
*
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class cache_administration_helper_phpunit_tests extends advanced_testcase {
/**
* Set things back to the default before each test.
*/
public function setUp() {
parent::setUp();
cache_factory::reset();
cache_config_phpunittest::create_default_configuration();
}
/**
* Final task is to reset the cache system
*/
public static function tearDownAfterClass() {
parent::tearDownAfterClass();
cache_factory::reset();
}
/**
* Test the numerous summaries the helper can produce.
*/
public function test_get_summaries() {
// First the preparation.
$config = cache_config_writer::instance();
$this->assertTrue($config->add_store_instance('summariesstore', 'file'));
$config->set_definition_mappings('core/eventinvalidation', array('summariesstore'));
$this->assertTrue($config->set_mode_mappings(array(
cache_store::MODE_APPLICATION => array('summariesstore'),
cache_store::MODE_SESSION => array('default_session'),
cache_store::MODE_REQUEST => array('default_request'),
)));
$storesummaries = cache_administration_helper::get_store_instance_summaries();
$this->assertInternalType('array', $storesummaries);
$this->assertArrayHasKey('summariesstore', $storesummaries);
$summary = $storesummaries['summariesstore'];
// Check the keys
$this->assertArrayHasKey('name', $summary);
$this->assertArrayHasKey('plugin', $summary);
$this->assertArrayHasKey('default', $summary);
$this->assertArrayHasKey('isready', $summary);
$this->assertArrayHasKey('requirementsmet', $summary);
$this->assertArrayHasKey('mappings', $summary);
$this->assertArrayHasKey('modes', $summary);
$this->assertArrayHasKey('supports', $summary);
// Check the important/known values
$this->assertEquals('summariesstore', $summary['name']);
$this->assertEquals('file', $summary['plugin']);
$this->assertEquals(0, $summary['default']);
$this->assertEquals(1, $summary['isready']);
$this->assertEquals(1, $summary['requirementsmet']);
$this->assertEquals(1, $summary['mappings']);
$definitionsummaries = cache_administration_helper::get_definition_summaries();
$this->assertInternalType('array', $definitionsummaries);
$this->assertArrayHasKey('core/eventinvalidation', $definitionsummaries);
$summary = $definitionsummaries['core/eventinvalidation'];
// Check the keys
$this->assertArrayHasKey('id', $summary);
$this->assertArrayHasKey('name', $summary);
$this->assertArrayHasKey('mode', $summary);
$this->assertArrayHasKey('component', $summary);
$this->assertArrayHasKey('area', $summary);
$this->assertArrayHasKey('mappings', $summary);
// Check the important/known values
$this->assertEquals('core/eventinvalidation', $summary['id']);
$this->assertInstanceOf('lang_string', $summary['name']);
$this->assertEquals(cache_store::MODE_APPLICATION, $summary['mode']);
$this->assertEquals('core', $summary['component']);
$this->assertEquals('eventinvalidation', $summary['area']);
$this->assertInternalType('array', $summary['mappings']);
$this->assertContains('summariesstore', $summary['mappings']);
$pluginsummaries = cache_administration_helper::get_store_plugin_summaries();
$this->assertInternalType('array', $pluginsummaries);
$this->assertArrayHasKey('file', $pluginsummaries);
$summary = $pluginsummaries['file'];
// Check the keys
$this->assertArrayHasKey('name', $summary);
$this->assertArrayHasKey('requirementsmet', $summary);
$this->assertArrayHasKey('instances', $summary);
$this->assertArrayHasKey('modes', $summary);
$this->assertArrayHasKey('supports', $summary);
$this->assertArrayHasKey('canaddinstance', $summary);
$locksummaries = cache_administration_helper::get_lock_summaries();
$this->assertInternalType('array', $locksummaries);
$this->assertTrue(count($locksummaries) > 0);
$mappings = cache_administration_helper::get_default_mode_stores();
$this->assertInternalType('array', $mappings);
$this->assertCount(3, $mappings);
$this->assertArrayHasKey(cache_store::MODE_APPLICATION, $mappings);
$this->assertInternalType('array', $mappings[cache_store::MODE_APPLICATION]);
$this->assertContains('summariesstore', $mappings[cache_store::MODE_APPLICATION]);
$potentials = cache_administration_helper::get_definition_store_options('core', 'eventinvalidation');
$this->assertInternalType('array', $potentials); // Currently used, suitable, default
$this->assertCount(3, $potentials);
$this->assertArrayHasKey('summariesstore', $potentials[0]);
$this->assertArrayHasKey('summariesstore', $potentials[1]);
$this->assertArrayHasKey('default_application', $potentials[1]);
}
/**
* Test instantiating an add store form.
*/
public function test_get_add_store_form() {
$form = cache_administration_helper::get_add_store_form('file');
$this->assertInstanceOf('moodleform', $form);
try {
$form = cache_administration_helper::get_add_store_form('somethingstupid');
$this->fail('You should not be able to create an add form for a store plugin that does not exist.');
} catch (moodle_exception $e) {
$this->assertInstanceOf('coding_exception', $e, 'Needs to be: ' .get_class($e)." ::: ".$e->getMessage());
}
}
/**
* Test instantiating a form to edit a store instance.
*/
public function test_get_edit_store_form() {
$config = cache_config_writer::instance();
$this->assertTrue($config->add_store_instance('summariesstore', 'file'));
$form = cache_administration_helper::get_edit_store_form('file', 'summariesstore');
$this->assertInstanceOf('moodleform', $form);
try {
$form = cache_administration_helper::get_edit_store_form('somethingstupid', 'moron');
$this->fail('You should not be able to create an edit form for a store plugin that does not exist.');
} catch (moodle_exception $e) {
$this->assertInstanceOf('coding_exception', $e);
}
try {
$form = cache_administration_helper::get_edit_store_form('file', 'blisters');
$this->fail('You should not be able to create an edit form for a store plugin that does not exist.');
} catch (moodle_exception $e) {
$this->assertInstanceOf('coding_exception', $e);
}
}
/**
* Test the hash_key functionality.
*/
public function test_hash_key() {
global $CFG;
$currentdebugging = $CFG->debug;
$CFG->debug = E_ALL;
// First with simplekeys
$instance = cache_config_phpunittest::instance(true);
$instance->phpunit_add_definition('phpunit/hashtest', array(
'mode' => cache_store::MODE_APPLICATION,
'component' => 'phpunit',
'area' => 'hashtest',
'simplekeys' => true
));
$factory = cache_factory::instance();
$definition = $factory->create_definition('phpunit', 'hashtest');
$result = cache_helper::hash_key('test', $definition);
$this->assertEquals('test-'.$definition->generate_single_key_prefix(), $result);
try {
cache_helper::hash_key('test/test', $definition);
$this->fail('Invalid key was allowed, you should see this.');
} catch (coding_exception $e) {
$this->assertEquals('test/test', $e->debuginfo);
}
// Second without simple keys
$instance->phpunit_add_definition('phpunit/hashtest2', array(
'mode' => cache_store::MODE_APPLICATION,
'component' => 'phpunit',
'area' => 'hashtest2',
'simplekeys' => false
));
$definition = $factory->create_definition('phpunit', 'hashtest2');
$result = cache_helper::hash_key('test', $definition);
$this->assertEquals(sha1($definition->generate_single_key_prefix().'-test'), $result);
$result = cache_helper::hash_key('test/test', $definition);
$this->assertEquals(sha1($definition->generate_single_key_prefix().'-test/test'), $result);
$CFG->debug = $currentdebugging;
}
}

View File

@ -38,7 +38,7 @@ require_once($CFG->dirroot . '/webservice/tests/helpers.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.5
*/
class core_calendar_external_testcase extends externallib_advanced_testcase {
class core_calendar_externallib_testcase extends externallib_advanced_testcase {
/**
* Tests set up

View File

@ -37,7 +37,7 @@ require_once("$CFG->dirroot/cohort/lib.php");
* @copyright 2012 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class cohort_testcase extends advanced_testcase {
class core_cohort_cohortlib_testcase extends advanced_testcase {
public function test_cohort_add_cohort() {
global $DB;

View File

@ -30,7 +30,7 @@ global $CFG;
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
require_once($CFG->dirroot . '/cohort/externallib.php');
class core_cohort_external_testcase extends externallib_advanced_testcase {
class core_cohort_externallib_testcase extends externallib_advanced_testcase {
/**
* Test create_cohorts

View File

@ -28,7 +28,7 @@ defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot.'/course/lib.php');
class courselib_testcase extends advanced_testcase {
class core_course_courselib_testcase extends advanced_testcase {
/**
* Set forum specific test values for calling create_module().

View File

@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot.'/course/lib.php');
class courserequest_testcase extends advanced_testcase {
class core_course_courserequest_testcase extends advanced_testcase {
public function test_create_request() {
global $DB, $USER;

View File

@ -37,7 +37,7 @@ require_once($CFG->dirroot . '/webservice/tests/helpers.php');
* @copyright 2012 Jerome Mouneyrac
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_course_external_testcase extends externallib_advanced_testcase {
class core_course_externallib_testcase extends externallib_advanced_testcase {
/**
* Tests set up

View File

@ -34,7 +34,7 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2012 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_enrol_testcase extends advanced_testcase {
class core_enrollib_testcase extends advanced_testcase {
public function test_enrol_get_all_users_courses() {
global $DB, $CFG;

View File

@ -30,7 +30,7 @@ require_once($CFG->dirroot . '/enrol/externallib.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.4
*/
class core_enrol_external_testcase extends externallib_advanced_testcase {
class core_enrol_externallib_testcase extends externallib_advanced_testcase {
/**
* Test get_enrolled_users

View File

@ -30,7 +30,7 @@ require_once($CFG->dirroot . '/enrol/externallib.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.4
*/
class core_role_external_testcase extends externallib_advanced_testcase {
class core_enrol_role_external_testcase extends externallib_advanced_testcase {
/**
* Tests set up

View File

@ -31,7 +31,7 @@ global $CFG;
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
require_once($CFG->dirroot . '/files/externallib.php');
class test_external_files extends advanced_testcase {
class core_files_externallib_testcase extends advanced_testcase {
/*
* Test core_files_external::upload().

View File

@ -49,7 +49,7 @@ class testable_grading_manager extends grading_manager {
* @copyright 2011 David Mudrak <david@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class grading_manager_testcase extends advanced_testcase {
class core_grade_grading_manager_testcase extends advanced_testcase {
public function test_basic_instantiation() {
$manager1 = get_grading_manager();

View File

@ -32,7 +32,7 @@ require_once($CFG->dirroot.'/grade/edit/tree/lib.php');
/**
* Tests grade_edit_tree (deals with the data on the categories and items page in the gradebook)
*/
class gradeedittreelib_testcase extends basic_testcase {
class core_grade_edittreelib_testcase extends basic_testcase {
var $courseid = 1;
var $context = null;
var $grade_edit_tree = null;

View File

@ -28,7 +28,7 @@ require_once($CFG->dirroot . '/webservice/tests/helpers.php');
* @copyright 2013 Paul Charsley
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_grade_external_testcase extends externallib_advanced_testcase {
class core_grade_externallib_testcase extends externallib_advanced_testcase {
/**
* Tests set up

View File

@ -30,7 +30,7 @@ require_once($CFG->libdir.'/gradelib.php');
require_once($CFG->dirroot.'/grade/querylib.php');
class grade_querylib_testcase extends advanced_testcase {
class core_grade_querylib_testcase extends advanced_testcase {
public function test_grade_get_gradable_activities() {
$this->resetAfterTest(true);

View File

@ -32,7 +32,7 @@ require_once($CFG->dirroot.'/grade/report/grader/lib.php');
/**
* Tests grade_report_grader (the grader report)
*/
class grade_report_graderlib_testcase extends advanced_testcase {
class core_grade_report_graderlib_testcase extends advanced_testcase {
/**
* Tests grade_report_grader::process_data()

View File

@ -61,7 +61,7 @@ class grade_report_test extends grade_report {
/**
* Tests grade_report, the parent class for all grade reports.
*/
class gradereportlib_testcase extends advanced_testcase {
class core_grade_reportlib_testcase extends advanced_testcase {
/**
* Tests grade_report::blank_hidden_total()

View File

@ -33,7 +33,7 @@ require_once($CFG->dirroot.'/grade/report/user/lib.php');
/**
* Tests grade_report_user (the gradebook's user report)
*/
class gradereportuserlib_testcase extends advanced_testcase {
class core_grade_reportuserlib_testcase extends advanced_testcase {
/**
* Tests grade_report_user::inject_rowspans()

View File

@ -32,7 +32,7 @@ require_once($CFG->dirroot . '/webservice/tests/helpers.php');
require_once($CFG->dirroot . '/group/externallib.php');
require_once($CFG->dirroot . '/group/lib.php');
class core_group_external_testcase extends externallib_advanced_testcase {
class core_group_externallib_testcase extends externallib_advanced_testcase {
/**
* Test create_groups

View File

@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die();
/**
* GeoIp data file parsing test.
*/
class geoip_testcase extends advanced_testcase {
class core_iplookup_geoip_testcase extends advanced_testcase {
public function test_geoip() {
global $CFG;

View File

@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die();
/**
* GeoIp data file parsing test.
*/
class geoplugin_testcase extends advanced_testcase {
class core_iplookup_geoplugin_testcase extends advanced_testcase {
public function test_geoip() {
global $CFG;

View File

@ -35,7 +35,7 @@ require_once($CFG->libdir . '/ajax/ajaxlib.php');
* @copyright 2008 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class ajax_testcase extends advanced_testcase {
class core_ajaxlib_testcase extends advanced_testcase {
var $user_agents = array(
'MSIE' => array(

View File

@ -25,7 +25,7 @@
defined('MOODLE_INTERNAL') || die();
class ddl_testcase extends database_driver_testcase {
class core_ddl_testcase extends database_driver_testcase {
private $tables = array();
private $records= array();

View File

@ -25,7 +25,7 @@
defined('MOODLE_INTERNAL') || die();
class dml_testcase extends database_driver_testcase {
class core_dml_testcase extends database_driver_testcase {
protected function setUp() {
parent::setUp();

View File

@ -31,7 +31,7 @@ require_once($CFG->libdir . '/filelib.php');
require_once($CFG->dirroot . '/repository/lib.php');
require_once($CFG->libdir . '/filestorage/stored_file.php');
class filestoragelib_testcase extends advanced_testcase {
class core_files_file_storage_testcase extends advanced_testcase {
/**
* Files can be created from strings.

View File

@ -26,7 +26,7 @@
defined('MOODLE_INTERNAL') || die();
class zip_packer_testcase extends advanced_testcase {
class core_files_zip_packer_testcase extends advanced_testcase {
protected $testfile;
protected $files;

View File

@ -26,7 +26,7 @@ defined('MOODLE_INTERNAL') || die();
require_once(__DIR__.'/fixtures/lib.php');
class grade_category_testcase extends grade_base_testcase {
class core_grade_category_testcase extends grade_base_testcase {
public function test_grade_category() {
$this->sub_test_grade_category_construct();

View File

@ -26,7 +26,7 @@ defined('MOODLE_INTERNAL') || die();
require_once(__DIR__.'/fixtures/lib.php');
class grade_grade_testcase extends grade_base_testcase {
class core_grade_grade_testcase extends grade_base_testcase {
public function test_grade_grade() {
$this->sub_test_grade_grade_construct();

View File

@ -25,7 +25,7 @@ defined('MOODLE_INTERNAL') || die();
require_once(__DIR__.'/fixtures/lib.php');
class grade_item_testcase extends grade_base_testcase {
class core_grade_item_testcase extends grade_base_testcase {
public function test_grade_item() {
$this->sub_test_grade_item_construct();
$this->sub_test_grade_item_insert();

View File

@ -26,7 +26,7 @@ defined('MOODLE_INTERNAL') || die();
require_once(__DIR__.'/fixtures/lib.php');
class grade_outcome_testcase extends grade_base_testcase {
class core_grade_outcome_testcase extends grade_base_testcase {
public function test_grade_outcome() {
$this->sub_test_grade_outcome_construct();

View File

@ -26,7 +26,7 @@ defined('MOODLE_INTERNAL') || die();
require_once(__DIR__.'/fixtures/lib.php');
class grade_scale_testcase extends grade_base_testcase {
class core_grade_scale_testcase extends grade_base_testcase {
public function test_grade_scale() {
$this->sub_test_scale_construct();

View File

@ -44,6 +44,7 @@
*/
class phpunit_autoloader implements PHPUnit_Runner_TestSuiteLoader {
public function load($suiteClassName, $suiteClassFile = '') {
global $CFG;
// Let's guess what user entered on the commandline...
if ($suiteClassFile) {
@ -94,6 +95,7 @@ class phpunit_autoloader implements PHPUnit_Runner_TestSuiteLoader {
} else {
$component = $component . '_' . array_shift($parts);
}
// Try standard plugin and core subsystem locations.
if ($fulldir = core_component::get_component_directory($component)) {
$testfile = implode('_', $parts);
$fullpath = "{$fulldir}/tests/{$testfile}_test.php";
@ -106,6 +108,51 @@ class phpunit_autoloader implements PHPUnit_Runner_TestSuiteLoader {
}
}
}
// The last option is testsuite directories in main phpunit.xml file.
$xmlfile = "$CFG->dirroot/phpunit.xml";
if (is_readable($xmlfile) and $xml = file_get_contents($xmlfile)) {
$dom = new DOMDocument();
$dom->loadXML($xml);
$nodes = $dom->getElementsByTagName('testsuite');
foreach ($nodes as $node) {
/** @var DOMNode $node */
$suitename = trim($node->attributes->getNamedItem('name')->nodeValue);
if (strpos($suitename, 'core') !== 0 or strpos($suitename, ' ') !== false) {
continue;
}
// This is a nasty hack: testsuit names are sometimes used as prefix for testcases
// in non-standard core subsystem locations.
if (strpos($suiteClassName, $suitename) !== 0) {
continue;
}
foreach ($node->childNodes as $dirnode) {
/** @var DOMNode $dirnode */
$dir = trim($dirnode->textContent);
if (!$dir) {
continue;
}
$dir = $CFG->dirroot.'/'.$dir;
$parts = explode('_', $suitename);
$prefix = '';
while ($parts) {
if ($prefix) {
$prefix = $prefix.'_'.array_shift($parts);
} else {
$prefix = array_shift($parts);
}
$filename = substr($suiteClassName, strlen($prefix)+1);
$filename = preg_replace('/testcase$/', 'test', $filename);
if (is_readable("$dir/$filename.php")) {
include_once("$dir/$filename.php");
if (class_exists($suiteClassName, false)) {
$class = new ReflectionClass($suiteClassName);
return $class;
}
}
}
}
}
}
}
throw new PHPUnit_Framework_Exception(

View File

@ -666,7 +666,7 @@ class core_accesslib_testcase extends advanced_testcase {
$this->resetAfterTest();
$allroles = get_all_roles();
$this->assertEquals('array', gettype($allroles));
$this->assertInternalType('array', $allroles);
$this->assertCount(8, $allroles); // There are 8 roles is standard install.
$role = reset($allroles);
@ -689,7 +689,7 @@ class core_accesslib_testcase extends advanced_testcase {
$renames = $DB->get_records_menu('role_names', array('contextid'=>$coursecontext->id), '', 'roleid, name');
$allroles = get_all_roles($coursecontext);
$this->assertEquals('array', gettype($allroles));
$this->assertInternalType('array', $allroles);
$this->assertCount(9, $allroles);
$role = reset($allroles);
$role = (array)$role;
@ -849,13 +849,13 @@ class core_accesslib_testcase extends advanced_testcase {
foreach ($archetypes as $archetype) {
$result = get_default_role_archetype_allows('assign', $archetype);
$this->assertEquals('array', gettype($result));
$this->assertInternalType('array', $result);
$result = get_default_role_archetype_allows('override', $archetype);
$this->assertEquals('array', gettype($result));
$this->assertInternalType('array', $result);
$result = get_default_role_archetype_allows('switch', $archetype);
$this->assertEquals('array', gettype($result));
$this->assertInternalType('array', $result);
}
$result = get_default_role_archetype_allows('assign', '');
@ -1194,7 +1194,7 @@ class core_accesslib_testcase extends advanced_testcase {
$alllevels = context_helper::get_all_levels();
foreach ($archetypes as $archetype) {
$defaults = get_default_contextlevels($archetype);
$this->assertEquals('array', gettype($defaults));
$this->assertInternalType('array', $defaults);
foreach ($defaults as $level) {
$this->assertTrue(isset($alllevels[$level]));
}

View File

@ -1898,37 +1898,37 @@ class core_moodlelib_testcase extends advanced_testcase {
$yes = get_string('yes');
$yesexpected = 'Yes';
$this->assertSame('string', gettype($yes));
$this->assertInternalType('string', $yes);
$this->assertSame($yesexpected, $yes);
$yes = get_string('yes', 'moodle');
$this->assertSame('string', gettype($yes));
$this->assertInternalType('string', $yes);
$this->assertSame($yesexpected, $yes);
$yes = get_string('yes', 'core');
$this->assertSame('string', gettype($yes));
$this->assertInternalType('string', $yes);
$this->assertSame($yesexpected, $yes);
$yes = get_string('yes', '');
$this->assertSame('string', gettype($yes));
$this->assertInternalType('string', $yes);
$this->assertSame($yesexpected, $yes);
$yes = get_string('yes', null);
$this->assertSame('string', gettype($yes));
$this->assertInternalType('string', $yes);
$this->assertSame($yesexpected, $yes);
$yes = get_string('yes', null, 1);
$this->assertSame('string', gettype($yes));
$this->assertInternalType('string', $yes);
$this->assertSame($yesexpected, $yes);
$days = 1;
$numdays = get_string('numdays', 'core', '1');
$numdaysexpected = $days.' days';
$this->assertSame('string', gettype($numdays));
$this->assertInternalType('string', $numdays);
$this->assertSame($numdaysexpected, $numdays);
$yes = get_string('yes', null, null, true);
$this->assertSame('lang_string', get_class($yes));
$this->assertInstanceOf('lang_string', $yes);
$this->assertSame($yesexpected, (string)$yes);
// Test using a lang_string object as the $a argument for a normal
@ -1936,7 +1936,7 @@ class core_moodlelib_testcase extends advanced_testcase {
$test = new lang_string('yes', null, null, true);
$testexpected = get_string('numdays', 'core', get_string('yes'));
$testresult = get_string('numdays', null, $test);
$this->assertSame('string', gettype($testresult));
$this->assertInternalType('string', $testresult);
$this->assertSame($testexpected, $testresult);
// Test using a lang_string object as the $a argument for an object
@ -1944,7 +1944,7 @@ class core_moodlelib_testcase extends advanced_testcase {
$test = new lang_string('yes', null, null, true);
$testexpected = get_string('numdays', 'core', get_string('yes'));
$testresult = get_string('numdays', null, $test, true);
$this->assertSame('lang_string', get_class($testresult));
$this->assertInstanceOf('lang_string', $testresult);
$this->assertSame($testexpected, "$testresult");
// Make sure that object properties that can't be converted don't cause

View File

@ -52,7 +52,7 @@ class core_plugin_manager_testcase extends advanced_testcase {
public function test_get_plugins_of_type() {
$pluginman = testable_plugin_manager::instance();
$mods = $pluginman->get_plugins_of_type('mod');
$this->assertSame('array', gettype($mods));
$this->assertInternalType('array', $mods);
$this->assertCount(5, $mods);
$this->assertInstanceOf('testable_plugininfo_mod', $mods['foo']);
$this->assertInstanceOf('testable_plugininfo_mod', $mods['bar']);
@ -76,7 +76,7 @@ class core_plugin_manager_testcase extends advanced_testcase {
public function test_get_plugins() {
$pluginman = testable_plugin_manager::instance();
$plugins = $pluginman->get_plugins();
$this->assertSame('array', gettype($plugins));
$this->assertInternalType('array', $plugins);
$this->assertTrue(isset($plugins['mod']['foo']));
$this->assertTrue(isset($plugins['mod']['bar']));
$this->assertTrue(isset($plugins['mod']['baz']));
@ -98,16 +98,16 @@ class core_plugin_manager_testcase extends advanced_testcase {
$this->assertSame(array(), $pluginman->get_subplugins_of_plugin('mod_missing'));
$this->assertSame(array(), $pluginman->get_subplugins_of_plugin('mod_bar'));
$foosubs = $pluginman->get_subplugins_of_plugin('mod_foo');
$this->assertSame('array', gettype($foosubs));
$this->assertInternalType('array', $foosubs);
$this->assertCount(2, $foosubs);
$this->assertInstanceOf('testable_pluginfo_foolish', $foosubs['foolish_frog']);
$this->assertInstanceOf('testable_pluginfo_foolish', $foosubs['foolish_hippo']);
$bazsubs = $pluginman->get_subplugins_of_plugin('mod_baz');
$this->assertSame('array', gettype($bazsubs));
$this->assertInternalType('array', $bazsubs);
$this->assertCount(1, $bazsubs);
$this->assertInstanceOf('testable_pluginfo_bazmeg', $bazsubs['bazmeg_one']);
$quxsubs = $pluginman->get_subplugins_of_plugin('mod_qux');
$this->assertSame('array', gettype($quxsubs));
$this->assertInternalType('array', $quxsubs);
$this->assertCount(1, $quxsubs);
$this->assertInstanceOf('testable_pluginfo_quxcat', $quxsubs['quxcat_one']);
}
@ -229,7 +229,7 @@ class core_plugin_manager_testcase extends advanced_testcase {
$pluginman = testable_plugin_manager::instance();
$plugins = $pluginman->get_plugins();
$this->assertNull($plugins['mod']['bar']->available_updates());
$this->assertSame('array', gettype($plugins['mod']['foo']->available_updates()));
$this->assertInternalType('array', $plugins['mod']['foo']->available_updates());
foreach ($plugins['mod']['foo']->available_updates() as $availableupdate) {
$this->assertInstanceOf('available_update_info', $availableupdate);
}
@ -377,7 +377,7 @@ class core_available_update_checker_testcase extends advanced_testcase {
$old = array();
$new = array();
$cmp = $provider->compare_responses($old, $new);
$this->assertSame('array', gettype($cmp));
$this->assertInternalType('array', $cmp);
$this->assertEmpty($cmp);
}
@ -394,7 +394,7 @@ class core_available_update_checker_testcase extends advanced_testcase {
)
);
$cmp = $provider->compare_responses($old, $new);
$this->assertSame('array', gettype($cmp));
$this->assertInternalType('array', $cmp);
$this->assertNotEmpty($cmp);
$this->assertTrue(isset($cmp['core'][0]['version']));
$this->assertEquals(2012060103, $cmp['core'][0]['version']);
@ -420,7 +420,7 @@ class core_available_update_checker_testcase extends advanced_testcase {
)
);
$cmp = $provider->compare_responses($old, $new);
$this->assertSame('array', gettype($cmp));
$this->assertInternalType('array', $cmp);
$this->assertEmpty($cmp);
}
@ -453,7 +453,7 @@ class core_available_update_checker_testcase extends advanced_testcase {
)
);
$cmp = $provider->compare_responses($old, $new);
$this->assertSame('array', gettype($cmp));
$this->assertInternalType('array', $cmp);
$this->assertNotEmpty($cmp);
$this->assertCount(1, $cmp);
$this->assertCount(1, $cmp['core']);
@ -481,7 +481,7 @@ class core_available_update_checker_testcase extends advanced_testcase {
)
);
$cmp = $provider->compare_responses($old, $new);
$this->assertSame('array', gettype($cmp));
$this->assertInternalType('array', $cmp);
$this->assertNotEmpty($cmp);
$this->assertCount(1, $cmp);
$this->assertCount(1, $cmp['mod_foo']);

View File

@ -30,7 +30,7 @@ global $CFG;
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
require_once($CFG->dirroot . '/message/externallib.php');
class core_message_external_testcase extends externallib_advanced_testcase {
class core_message_externallib_testcase extends externallib_advanced_testcase {
/**
* Send a fake message.

View File

@ -30,7 +30,7 @@ global $CFG;
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
require_once($CFG->dirroot . '/notes/externallib.php');
class core_notes_external_testcase extends externallib_advanced_testcase {
class core_notes_externallib_testcase extends externallib_advanced_testcase {
/**
* Test create_notes

View File

@ -31,11 +31,13 @@
<testsuite name="core_test">
<directory suffix="_test.php">lib/testing/tests</directory>
</testsuite>
<testsuite name="core_db">
<testsuite name="core_ddl">
<directory suffix="_test.php">lib/ddl/tests</directory>
</testsuite>
<testsuite name="core_dml">
<directory suffix="_test.php">lib/dml/tests</directory>
</testsuite>
<testsuite name="core_lib">
<testsuite name="core">
<directory suffix="_test.php">lib/tests</directory>
<directory suffix="_test.php">lib/ajax/tests</directory>
<directory suffix="_test.php">lib/form/tests</directory>

View File

@ -33,7 +33,7 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class repository_generator_testcase extends advanced_testcase {
class core_repository_generator_testcase extends advanced_testcase {
/**
* Basic test of creation of repository types.

View File

@ -28,7 +28,7 @@ defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once("$CFG->dirroot/repository/lib.php");
class repositorylib_testcase extends advanced_testcase {
class core_repositorylib_testcase extends advanced_testcase {
/**
* Installing repository tests

View File

@ -31,7 +31,7 @@ global $CFG;
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
require_once($CFG->dirroot . '/user/externallib.php');
class core_user_external_testcase extends externallib_advanced_testcase {
class core_user_externallib_testcase extends externallib_advanced_testcase {
/**
* Test get_users

View File

@ -28,7 +28,7 @@ require_once($CFG->dirroot . '/webservice/tests/helpers.php');
* @copyright 2012 Paul Charsley
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_webservice_external_testcase extends externallib_advanced_testcase {
class core_webservice_externallib_testcase extends externallib_advanced_testcase {
public function setUp() {
// Calling parent is good, always