Permalink
Browse files

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

  • Loading branch information...
1 parent 653bc98 commit dda19810e00eb41d37b42251d21b741fa5cb4861 @mrmark mrmark committed with mudrd8mz Mar 11, 2011
@@ -31,7 +31,38 @@ public function build_plan() {
$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'));
+ }
+}
+
+// @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;
+ }
- $this->xmlparser->process(); // @todo When to really do this?
+ public function convert_courseinfo($data) {
+ print_object($data);
}
}
@@ -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();
+ }
+}
@@ -22,16 +22,20 @@
/**
* @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 @@ public function get_plan() {
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() {
@@ -17,4 +17,8 @@ public function get_convertid() {
public function get_converter() {
return $this->plan->get_converter();
}
+
+ protected function define_settings() {
+ // None
+ }
}

0 comments on commit dda1981

Please sign in to comment.