Starting to unit test - fixed bugs, things are... working!?!

This commit is contained in:
Mark Nielsen 2011-03-11 13:06:24 -08:00 committed by David Mudrak
parent 653bc98b0e
commit dda19810e0
4 changed files with 84 additions and 3 deletions

View File

@ -31,7 +31,38 @@ class moodle1_converter extends plan_converter {
$this->xmlprocessor = new convert_structure_parser_processor($this); // @todo Probably move this
$this->xmlparser->set_processor($this->xmlprocessor);
$this->get_plan()->add_task(new moodle1_course_task('courseinfo'));
}
}
$this->xmlparser->process(); // @todo When to really do this?
// @todo Where to store these classes?
class moodle1_course_task extends convert_task {
/**
* Create all the steps that will be part of this task
*/
public function build() {
$this->add_step(new moodle1_course_structure_step('course_info', $this));
// At the end, mark it as built
$this->built = true;
}
}
class moodle1_course_structure_step extends convert_structure_step {
/**
* Function that will return the structure to be processed by this convert_step.
* Must return one array of @convert_path_element elements
*/
protected function define_structure() {
$paths = array();
$paths[] = new convert_path_element('courseinfo', '/MOODLE_BACKUP/COURSE/HEADER');
return $paths;
}
public function convert_courseinfo($data) {
print_object($data);
}
}

View File

@ -0,0 +1,41 @@
<?php
require_once($CFG->dirroot.'/backup/util/includes/convert_includes.php');
class moodle1_converter_test extends UnitTestCase {
public static $includecoverage = array();
/**
* @var string
*/
protected $tempdir;
public function setUp() {
global $CFG;
$this->tempdir = convert_helper::generate_id('simpletest');
check_dir_exists("$CFG->dataroot/temp/backup/$this->tempdir");
copy(
$CFG->dirroot.'/backup/converter/moodle1/simpletest/files/moodle.xml',
"$CFG->dataroot/temp/backup/$this->tempdir/moodle.xml"
);
}
public function tearDown() {
global $CFG;
fulldelete("$CFG->dataroot/temp/backup/$this->tempdir");
}
public function test_can_convert() {
$converter = convert_factory::converter('moodle1', $this->tempdir);
$this->assertIsA($converter, 'moodle1_converter');
$this->assertTrue($converter->can_convert());
}
public function test_convert() {
$converter = convert_factory::converter('moodle1', $this->tempdir);
$this->assertIsA($converter, 'moodle1_converter');
$converter->convert();
}
}

View File

@ -22,16 +22,20 @@ abstract class plan_converter extends base_converter {
/**
* @var array
*/
protected $pathelements; // Array of pathelements to process
protected $pathelements = array(); // Array of pathelements to process
// @todo needed? redo?
protected $pathlock; // Path currently locking processing of children
// @todo IDK what this is really...
const SKIP_ALL_CHILDREN = -991399; // To instruct the dispatcher about to ignore
// all children below path processor returning it
/**
* @return convert_plan
*/
public function get_plan() {
if ($this->plan instanceof convert_plan) {
if (!$this->plan instanceof convert_plan) {
$this->plan = new convert_plan($this);
}
return $this->plan;
@ -42,6 +46,7 @@ abstract class plan_converter extends base_converter {
public function execute() {
$this->get_plan()->build(); // Ends up calling $this->build_plan()
$this->get_plan()->execute();
$this->xmlparser->process(); // @todo When to really do this?
}
public function destroy() {

View File

@ -17,4 +17,8 @@ abstract class convert_task extends base_task {
public function get_converter() {
return $this->plan->get_converter();
}
protected function define_settings() {
// None
}
}