forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'MDL-38582' of git://github.com/timhunt/moodle
- Loading branch information
Showing
8 changed files
with
239 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?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/>. | ||
|
||
/** | ||
* Component generator base class. | ||
* | ||
* @package core | ||
* @category test | ||
* @copyright 2013 The Open University | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
|
||
/** | ||
* Component generator base class. | ||
* | ||
* Extend in path/to/component/tests/generator/lib.php as | ||
* class type_plugin_generator extends component_generator_base | ||
* Note that there are more specific classes to extend for mods and blocks. | ||
* | ||
* @copyright 2013 The Open University | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
abstract class component_generator_base { | ||
|
||
/** | ||
* @var testing_data_generator | ||
*/ | ||
protected $datagenerator; | ||
|
||
/** | ||
* Constructor. | ||
* @param testing_data_generator $datagenerator | ||
*/ | ||
public function __construct(testing_data_generator $datagenerator) { | ||
$this->datagenerator = $datagenerator; | ||
} | ||
|
||
/** | ||
* To be called from data reset code only, | ||
* do not use in tests. | ||
* @return void | ||
*/ | ||
public function reset() { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?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/>. | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
/** | ||
* Quiz module test data generator class | ||
* | ||
* @package moodlecore | ||
* @subpackage question | ||
* @copyright 2013 The Open University | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class core_question_generator extends component_generator_base { | ||
|
||
/** | ||
* @var number of created instances | ||
*/ | ||
protected $categorycount = 0; | ||
|
||
public function reset() { | ||
$this->categorycount = 0; | ||
} | ||
|
||
/** | ||
* Create a new question category. | ||
* @param array|stdClass $record | ||
* @return stdClass question_categories record. | ||
*/ | ||
public function create_question_category($record = null) { | ||
global $DB; | ||
|
||
$this->categorycount++; | ||
|
||
$defaults = array( | ||
'name' => 'Test question category ' . $this->categorycount, | ||
'contextid' => context_system::instance()->id, | ||
'info' => '', | ||
'infoformat' => FORMAT_HTML, | ||
'stamp' => '', | ||
'parent' => 0, | ||
'sortorder' => 999, | ||
); | ||
|
||
$record = $this->datagenerator->combine_defaults_and_record($defaults, $record); | ||
$record['id'] = $DB->insert_record('question_categories', $record); | ||
return (object) $record; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?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/>. | ||
|
||
/** | ||
* Data generators tests | ||
* | ||
* @package moodlecore | ||
* @subpackage questionengine | ||
* @copyright 2013 The Open University | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
|
||
/** | ||
* Test data generator | ||
* | ||
* @copyright 2013 The Open University | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class core_question_generator_testcase extends advanced_testcase { | ||
public function test_create() { | ||
global $DB; | ||
|
||
$this->resetAfterTest(); | ||
$generator = $this->getDataGenerator()->get_plugin_generator('core_question'); | ||
|
||
$count = $DB->count_records('question_categories'); | ||
|
||
$cat = $generator->create_question_category(); | ||
$this->assertEquals($count + 1, $DB->count_records('question_categories')); | ||
|
||
$cat = $generator->create_question_category(array( | ||
'name' => 'My category', 'sortorder' => 1)); | ||
$this->assertSame('My category', $cat->name); | ||
$this->assertSame(1, $cat->sortorder); | ||
} | ||
} |