a17ca8df359232cb6083e1d06f7468ed1f92ce1a
[moodle.git] / mod / data / simpletest / test_data_portfolio_callers.php
1 <?php
2 require_once("$CFG->libdir/simpletest/portfolio_testclass.php");
3 require_once("$CFG->dirroot/mod/data/lib.php");
4 require_once("$CFG->dirroot/$CFG->admin/generator.php");
6 Mock::generate('data_portfolio_caller', 'mock_caller');
7 Mock::generate('portfolio_exporter', 'mock_exporter');
9 class testDataPortfolioCallers extends portfoliolib_test {
10     public static $includecoverage = array('lib/portfoliolib.php', 'mod/data/lib.php');
11     public $module_type = 'data';
12     public $modules = array();
13     public $entries = array();
14     public $caller_single;
15     public $caller;
17     public function setUp() {
18         global $DB, $USER;
20         parent::setUp();
22         $settings = array('quiet' => 1,
24                           'pre_cleanup' => 0,
25                           'modules_list' => array($this->module_type),
26                           'number_of_students' => 5,
27                           'students_per_course' => 5,
28                           'number_of_sections' => 1,
29                           'number_of_modules' => 1,
30                           'questions_per_course' => 0);
32         generator_generate_data($settings);
34         $this->modules = $DB->get_records($this->module_type);
35         $first_module = reset($this->modules);
36         $cm = get_coursemodule_from_instance($this->module_type, $first_module->id);
38         $fields = $DB->get_records('data_fields', array('dataid' => $first_module->id));
39         $recordid = data_add_record($first_module);
40         foreach ($fields as $field) {
41             $content->recordid = $recordid;
42             $content->fieldid = $field->id;
43             $content->content = 'test content';
44             $content->content1 = 'test content 1';
45             $content->content2 = 'test content 2';
46             $DB->insert_record('data_content',$content);
47         }
49         // Callback args required: id, record, delimiter_name, exporttype
50         $this->caller_single = parent::setup_caller('data_portfolio_caller', array('id' => $cm->id, 'record' => $recordid));
51         $this->caller = parent::setup_caller('data_portfolio_caller', array('id' => $cm->id));
52     }
54     public function tearDown() {
55         parent::tearDown();
56     }
58     public function test_caller_sha1() {
59         $sha1 = $this->caller->get_sha1();
60         $this->caller->prepare_package();
61         $this->assertEqual($sha1, $this->caller->get_sha1());
63         $sha1 = $this->caller_single->get_sha1();
64         $this->caller_single->prepare_package();
65         $this->assertEqual($sha1, $this->caller_single->get_sha1());
66     }
68     public function test_caller_with_plugins() {
69         parent::test_caller_with_plugins();
70     }
71 }