MDL-20636 Merge remote-tracking branch 'moodle/master' into upgrade

Conflicts:
	lib/filestorage/file_storage.php
	mod/quiz/attemptlib.php
	mod/quiz/lib.php
	mod/quiz/mod_form.php
	mod/quiz/report/overview/overview_table.php
	mod/quiz/report/overview/report.php
	mod/quiz/report/responses/report.php
	mod/quiz/report/responses/responses_table.php
	mod/quiz/report/statistics/db/install.xml
	mod/quiz/report/statistics/qstats.php
	mod/quiz/report/statistics/report.php
	mod/quiz/report/statistics/statistics_question_table.php
	mod/quiz/report/statistics/statistics_table.php
	mod/quiz/report/statistics/version.php
	mod/quiz/review.php
	mod/quiz/reviewquestion.php
	mod/quiz/startattempt.php
	mod/quiz/styles.css
	mod/quiz/view.php
	question/type/essay/questiontype.php
	question/type/match/backup/moodle2/backup_qtype_match_plugin.class.php
	question/type/match/backup/moodle2/restore_qtype_match_plugin.class.php
	question/type/numerical/display.html
	question/type/numerical/questiontype.php
	question/type/questiontype.php
	question/type/random/questiontype.php
	question/type/shortanswer/questiontype.php
	theme/base/style/question.css
This commit is contained in:
Tim Hunt
2011-05-11 20:29:49 +01:00
1225 changed files with 22803 additions and 8568 deletions
+115
View File
@@ -58,6 +58,121 @@ class componentlib_test extends UnitTestCase {
//check if correct files were downloaded
$this->assertEqual('2af180e813dc3f446a9bb7b6af87ce24', md5_file($destpath.'/'.'test.jpg'));
$this->assertEqual('47250a973d1b88d9445f94db4ef2c97a', md5_file($destpath.'/'.'test.html'));
}
/**
* Test the public API of the {@link lang_installer} class
*/
public function test_lang_installer() {
// test the manipulation with the download queue
$installer = new testable_lang_installer();
$this->assertFalse($installer->protected_is_queued());
$installer->protected_add_to_queue('cs');
$installer->protected_add_to_queue(array('cs', 'sk'));
$this->assertTrue($installer->protected_is_queued());
$this->assertTrue($installer->protected_is_queued('cs'));
$this->assertTrue($installer->protected_is_queued('sk'));
$this->assertFalse($installer->protected_is_queued('de_kids'));
$installer->set_queue('de_kids');
$this->assertFalse($installer->protected_is_queued('cs'));
$this->assertFalse($installer->protected_is_queued('sk'));
$this->assertFalse($installer->protected_is_queued('de'));
$this->assertFalse($installer->protected_is_queued('de_du'));
$this->assertTrue($installer->protected_is_queued('de_kids'));
$installer->set_queue(array('cs', 'de_kids'));
$this->assertTrue($installer->protected_is_queued('cs'));
$this->assertFalse($installer->protected_is_queued('sk'));
$this->assertFalse($installer->protected_is_queued('de'));
$this->assertFalse($installer->protected_is_queued('de_du'));
$this->assertTrue($installer->protected_is_queued('de_kids'));
$installer->set_queue(array());
$this->assertFalse($installer->protected_is_queued());
unset($installer);
// install a set of lang packs
$installer = new testable_lang_installer(array('cs', 'de_kids', 'xx'));
$result = $installer->run();
$this->assertEqual($result['cs'], lang_installer::RESULT_UPTODATE);
$this->assertEqual($result['de_kids'], lang_installer::RESULT_INSTALLED);
$this->assertEqual($result['xx'], lang_installer::RESULT_DOWNLOADERROR);
// the following two were automatically added to the queue
$this->assertEqual($result['de_du'], lang_installer::RESULT_INSTALLED);
$this->assertEqual($result['de'], lang_installer::RESULT_UPTODATE);
// exception throwing
$installer = new testable_lang_installer(array('yy'));
$this->expectException('lang_installer_exception');
$installer->run();
}
}
/**
* Testable lang_installer subclass that does not actually install anything
* and provides access to the protected methods of the parent class
*
* @copyright 2011 David Mudrak <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class testable_lang_installer extends lang_installer {
/**
* @see parent::is_queued()
*/
public function protected_is_queued($langcode = '') {
return $this->is_queued($langcode);
}
/**
* @see parent::add_to_queue()
*/
public function protected_add_to_queue($langcodes) {
return $this->add_to_queue($langcodes);
}
/**
* Simulate lang pack installation via component_installer
*
* Language packages 'de_du' and 'de_kids' reported as installed
* Language packages 'cs' and 'de' reported as up-to-date
* Language package 'xx' returns download error
* All other language packages will throw an unknown exception
*
* @see parent::install_language_pack()
*/
protected function install_language_pack($langcode) {
switch ($langcode) {
case 'de_du':
case 'de_kids':
return self::RESULT_INSTALLED;
case 'cs':
case 'de':
return self::RESULT_UPTODATE;
case 'xx':
return self::RESULT_DOWNLOADERROR;
default:
throw new lang_installer_exception('testing-unknown-exception', $langcode);
}
}
/**
* Simulate detection of parent languge
*
* @see parent::get_parent_language()
*/
protected function get_parent_language($langcode) {
switch ($langcode) {
case 'de_kids':
return 'de_du';
case 'de_du':
return 'de';
default:
return '';
}
}
}
Executable → Regular
View File
Executable → Regular
View File
+4 -37
View File
@@ -167,10 +167,10 @@ class navigation_node_test extends UnitTestCase {
$this->node->find_expandable($expandable);
$this->assertEqual(count($expandable), 4);
if (count($expandable) === 4) {
$name = $expandable[0]['branchid'];
$name .= $expandable[1]['branchid'];
$name .= $expandable[2]['branchid'];
$name .= $expandable[3]['branchid'];
$name = $expandable[0]['key'];
$name .= $expandable[1]['key'];
$name .= $expandable[2]['key'];
$name .= $expandable[3]['key'];
$this->assertEqual($name, 'demo1demo2demo4hiddendemo2');
}
}
@@ -345,39 +345,6 @@ class global_navigation_test extends UnitTestCase {
$this->assertFalse($this->node->exposed_format_display_course_content('scorm'));
$this->assertTrue($this->node->exposed_format_display_course_content('dummy'));
}
public function test_load_section_activities() {
$node = $this->node->find('5', navigation_node::TYPE_COURSE);
$course = new stdClass;
$course->id = '5';
$course->numsections = 10;
$section = $node->add('Test Section 1', null, navigation_node::TYPE_SECTION, null, $this->cache->coursesections5[1]->id);
$modinfo = $this->cache->modinfo5;
$modinfo->sections[1] = array(289, 290);
$modinfo->cms[289] = clone($modinfo->cms[288]);
$modinfo->cms[289]->id = 289;
$modinfo->cms[289]->sectionnum = 1;
$modinfo->cms[290]->modname = 'forum';
$modinfo->cms[289]->instance = 20;
$modinfo->cms[290] = clone($modinfo->cms[288]);
$modinfo->cms[290]->id = 290;
$modinfo->cms[290]->modname = 'resource';
$modinfo->cms[290]->sectionnum = 1;
$modinfo->cms[290]->instance = 21;
$modinfo->instances['forum'][20] = clone($modinfo->instances['forum'][19]);
$modinfo->instances['forum'][20]->id = 20;
$modinfo->instances['resource'] = array();
$modinfo->instances['resource'][21] = clone($modinfo->instances['forum'][19]);
$modinfo->instances['resource'][21]->id = 21;
$this->cache->modinfo5 = $modinfo;
$course->modinfo = serialize($modinfo);
$activities = $this->node->exposed_load_section_activities($section, 1, $modinfo);
foreach ($activities as $activity) {
if ($this->assertIsA($activity, 'navigation_node')) {
$this->assertEqual($activity->type, navigation_node::TYPE_ACTIVITY);
$this->assertReference($activity, $section->get($activity->key));
}
}
}
public function test_module_extends_navigation() {
$this->cache->test1_extends_navigation = true;
$this->cache->test2_extends_navigation = false;
+18 -23
View File
@@ -525,7 +525,7 @@ class moodle_page_cm_test extends UnitTestCaseUsingDatabase {
parent::setUp();
$this->originalcourse = $COURSE;
$this->testpage = new moodle_page();
$this->create_test_tables(array('course', 'context'), 'lib');
$this->create_test_tables(array('course', 'context', 'modules', 'course_modules', 'course_modules_availability', 'grade_items', 'course_sections'), 'lib');
$this->create_test_table('forum', 'mod/forum');
$this->switch_to_test_db();
@@ -551,6 +551,7 @@ class moodle_page_cm_test extends UnitTestCaseUsingDatabase {
$course->fullname = 'Anonymous test course';
$course->shortname = 'ANON';
$course->summary = '';
$course->modinfo = null;
$course->id = $this->testdb->insert_record('course', $course);
$forum = new stdClass;
@@ -559,12 +560,23 @@ class moodle_page_cm_test extends UnitTestCaseUsingDatabase {
$forum->intro = '';
$forum->id = $this->testdb->insert_record('forum', $forum);
$module = new stdClass;
$module->name = 'forum';
$module->id = $this->testdb->insert_record('modules', $module);
$cm = new stdClass;
$cm->id = 13;
$cm->course = $course->id;
$cm->instance = $forum->id;
$cm->modname = 'forum';
$cm->module = $module->id;
$cm->name = $forum->name;
$cm->id = $this->testdb->insert_record('course_modules', $cm);
$section = new stdClass;
$section->course = $course->id;
$section->section = 0;
$section->sequence = $cm->id;
$section->id = $this->testdb->insert_record('course_sections', $section);
$context = new stdClass;
$context->contextlevel = CONTEXT_MODULE;
@@ -590,26 +602,6 @@ class moodle_page_cm_test extends UnitTestCaseUsingDatabase {
$this->assert(new CheckSpecifiedFieldsExpectation($cm), $this->testpage->cm);
}
public function test_cannot_set_cm_without_name() {
// Setup fixture
list($cm) = $this->create_a_forum_with_context();
// Set expectation
$this->expectException();
// Exercise SUT
unset($cm->name);
$this->testpage->set_cm($cm);
}
public function test_cannot_set_cm_without_modname() {
// Setup fixture
list($cm) = $this->create_a_forum_with_context();
// Set expectation
$this->expectException();
// Exercise SUT
unset($cm->modname);
$this->testpage->set_cm($cm);
}
public function test_cannot_set_activity_record_before_cm() {
// Setup fixture
list($cm, $course, $forum) = $this->create_a_forum_with_context();
@@ -672,18 +664,21 @@ class moodle_page_cm_test extends UnitTestCaseUsingDatabase {
$this->testpage->set_activity_record($forum);
}
public function test_settin_cm_sets_course() {
public function test_setting_cm_sets_course() {
// Setup fixture
list($cm, $course) = $this->create_a_forum_with_context();
// Exercise SUT
$this->testpage->set_cm($cm);
// Validate
unset($course->modinfo); // This changed, but we don't care
$this->assert(new CheckSpecifiedFieldsExpectation($course), $this->testpage->course);
}
public function test_set_cm_with_course_and_activity_no_db() {
// Setup fixture
list($cm, $course, $forum) = $this->create_a_forum_with_context();
// This only works without db if we already have modinfo cache
$modinfo = get_fast_modinfo($course);
$this->drop_test_table('forum');
$this->drop_test_table('course');
// Exercise SUT
View File
+133
View File
@@ -0,0 +1,133 @@
<?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 the HTMLPurifier integration
*
* @package core
* @subpackage simpletest
* @copyright 2011 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
class purifier_test extends UnitTestCase {
public static $includecoverage = array('lib/htmlpurifier/HTMLPurifier.php');
private $enablehtmlpurifier = null;
private $cachetext = null;
function setUp() {
global $CFG;
$this->enablehtmlpurifier = $CFG->enablehtmlpurifier;
$CFG->enablehtmlpurifier = 1;
$this->cachetext = $CFG->cachetext;
$CFG->cachetext = 0;
}
function tearDown() {
global $CFG;
$CFG->enablehtmlpurifier = $this->enablehtmlpurifier;
$CFG->cachetext = $this->cachetext;
}
/**
* Verify _blank target is allowed
* @return void
*/
public function test_allow_blank_target() {
$text = '<a href="http://moodle.org" target="_blank">Some link</a>';
$result = format_text($text, FORMAT_HTML);
$this->assertIdentical($text, $result);
$result = format_text('<a href="http://moodle.org" target="some">Some link</a>', FORMAT_HTML);
$this->assertIdentical('<a href="http://moodle.org">Some link</a>', $result);
}
/**
* Verify our nolink tag accepted
* @return void
*/
public function test_nolink() {
// we can not use format text because nolink changes result
$text = '<nolink><div>no filters</div></nolink>';
$result = purify_html($text, array());
$this->assertIdentical($text, $result);
}
/**
* Verify our tex tag accepted
* @return void
*/
public function test_tex() {
$text = '<tex>a+b=c</tex>';
$result = purify_html($text, array());
$this->assertIdentical($text, $result);
}
/**
* Verify our algebra tag accepted
* @return void
*/
public function test_algebra() {
$text = '<algebra>a+b=c</algebra>';
$result = purify_html($text, array());
$this->assertIdentical($text, $result);
}
/**
* Verify our hacky multilang works
* @return void
*/
public function test_multilang() {
$text = '<lang lang="en">hmmm</lang><lang lang="anything">hm</lang>';
$result = purify_html($text, array());
$this->assertIdentical($text, $result);
$text = '<span lang="en" class="multilang">hmmm</span><span lang="anything" class="multilang">hm</span>';
$result = purify_html($text, array());
$this->assertIdentical($text, $result);
$text = '<span lang="en">hmmm</span>';
$result = purify_html($text, array());
$this->assertNotIdentical($text, $result);
}
/**
* Tests the 'allowid' option for format_text.
*/
public function test_format_text_allowid() {
// Start off by not allowing ids (default)
$options = array(
'nocache' => true
);
$result = format_text('<div id="example">Frog</div>', FORMAT_HTML, $options);
$this->assertIdentical('<div>Frog</div>', $result);
// Now allow ids
$options['allowid'] = true;
$result = format_text('<div id="example">Frog</div>', FORMAT_HTML, $options);
$this->assertIdentical('<div id="example">Frog</div>', $result);
}
//TODO: add XSS smoke tests here
}
+1
View File
@@ -143,6 +143,7 @@ class web_test extends UnitTestCase {
$this->assertEqual('lala xx', clean_text($text, FORMAT_MOODLE));
$this->assertEqual('lala xx', clean_text($text, FORMAT_HTML));
}
}