Skip to content

Commit

Permalink
Starting to unit test - fixed bugs, things are... working!?!
Browse files Browse the repository at this point in the history
  • Loading branch information
polothy authored and mudrd8mz committed May 10, 2011
1 parent 653bc98 commit dda1981
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 3 deletions.
33 changes: 32 additions & 1 deletion backup/converter/moodle1/converter.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
41 changes: 41 additions & 0 deletions backup/converter/moodle1/simpletest/testconverter.php
Original file line number Diff line number Diff line change
@@ -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();
}
}
9 changes: 7 additions & 2 deletions backup/util/converter/plan_converter.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -42,6 +46,7 @@ abstract public function build_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() {
Expand Down
4 changes: 4 additions & 0 deletions backup/util/plan/convert_task.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.