[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Exporter class tests. 19 * 20 * @package core_competency 21 * @copyright 2015 Damyon Wiese 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 defined('MOODLE_INTERNAL') || die(); 26 global $CFG; 27 28 /** 29 * Exporter testcase. 30 * 31 * @package core_competency 32 * @copyright 2015 Damyon Wiese 33 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 34 */ 35 class core_competency_exporter_testcase extends advanced_testcase { 36 37 protected $validrelated = null; 38 protected $invalidrelated = null; 39 protected $validdata = null; 40 protected $invaliddata = null; 41 42 public function setUp() { 43 $s = new stdClass(); 44 $this->validrelated = array('simplestdClass' => $s, 'arrayofstdClass' => array($s, $s)); 45 $this->invalidrelated = array('simplestdClass' => 'a string', 'arrayofstdClass' => 5); 46 47 $this->validdata = array('stringA' => 'A string', 'stringAformat' => FORMAT_HTML, 'intB' => 4); 48 49 $this->invaliddata = array('stringA' => 'A string'); 50 } 51 52 public function test_get_read_structure() { 53 $structure = core_competency_testable_exporter::get_read_structure(); 54 55 $this->assertInstanceOf('external_single_structure', $structure); 56 $this->assertInstanceOf('external_value', $structure->keys['stringA']); 57 $this->assertInstanceOf('external_format_value', $structure->keys['stringAformat']); 58 $this->assertInstanceOf('external_value', $structure->keys['intB']); 59 $this->assertInstanceOf('external_value', $structure->keys['otherstring']); 60 $this->assertInstanceOf('external_multiple_structure', $structure->keys['otherstrings']); 61 } 62 63 public function test_get_create_structure() { 64 $structure = core_competency_testable_exporter::get_create_structure(); 65 66 $this->assertInstanceOf('external_single_structure', $structure); 67 $this->assertInstanceOf('external_value', $structure->keys['stringA']); 68 $this->assertInstanceOf('external_format_value', $structure->keys['stringAformat']); 69 $this->assertInstanceOf('external_value', $structure->keys['intB']); 70 $this->assertArrayNotHasKey('otherstring', $structure->keys); 71 $this->assertArrayNotHasKey('otherstrings', $structure->keys); 72 } 73 74 public function test_get_update_structure() { 75 $structure = core_competency_testable_exporter::get_update_structure(); 76 77 $this->assertInstanceOf('external_single_structure', $structure); 78 $this->assertInstanceOf('external_value', $structure->keys['stringA']); 79 $this->assertInstanceOf('external_format_value', $structure->keys['stringAformat']); 80 $this->assertInstanceOf('external_value', $structure->keys['intB']); 81 $this->assertArrayNotHasKey('otherstring', $structure->keys); 82 $this->assertArrayNotHasKey('otherstrings', $structure->keys); 83 } 84 85 /** 86 * @expectedException coding_exception 87 */ 88 public function test_invalid_data() { 89 global $PAGE; 90 $exporter = new core_competency_testable_exporter($this->invaliddata, $this->validrelated); 91 $output = $PAGE->get_renderer('tool_lp'); 92 93 $result = $exporter->export($output); 94 } 95 96 /** 97 * @expectedException coding_exception 98 */ 99 public function test_invalid_related() { 100 global $PAGE; 101 $exporter = new core_competency_testable_exporter($this->validdata, $this->invalidrelated); 102 $output = $PAGE->get_renderer('tool_lp'); 103 104 $result = $exporter->export($output); 105 } 106 107 public function test_valid_data_and_related() { 108 global $PAGE; 109 $exporter = new core_competency_testable_exporter($this->validdata, $this->validrelated); 110 111 $output = $PAGE->get_renderer('tool_lp'); 112 113 $result = $exporter->export($output); 114 } 115 } 116 117 /** 118 * Example persistent class. 119 * 120 * @package core_competency 121 * @copyright 2015 Frédéric Massart - FMCorz.net 122 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 123 */ 124 class core_competency_testable_exporter extends \core_competency\external\exporter { 125 126 protected static function define_related() { 127 // We cache the context so it does not need to be retrieved from the course. 128 return array('simplestdClass' => 'stdClass', 'arrayofstdClass' => 'stdClass[]'); 129 } 130 131 protected function get_other_values(renderer_base $output) { 132 return array( 133 'otherstring' => 'An other string', 134 'otherstrings' => array('String a', 'String b') 135 ); 136 } 137 138 public static function define_properties() { 139 return array( 140 'stringA' => array( 141 'type' => PARAM_RAW, 142 ), 143 'stringAformat' => array( 144 'type' => PARAM_INT, 145 ), 146 'intB' => array( 147 'type' => PARAM_INT, 148 ) 149 ); 150 } 151 152 public static function define_other_properties() { 153 return array( 154 'otherstring' => array( 155 'type' => PARAM_TEXT, 156 ), 157 'otherstrings' => array( 158 'type' => PARAM_TEXT, 159 'multiple' => true 160 ) 161 ); 162 } 163 164 165 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |