|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00027 // Prevent direct access to this file 00028 if (!defined('MOODLE_INTERNAL')) { 00029 die('Direct access to this script is forbidden.'); 00030 } 00031 00032 require_once($CFG->dirroot . '/backup/util/structure/base_atom.class.php'); 00033 require_once($CFG->dirroot . '/backup/util/structure/base_attribute.class.php'); 00034 require_once($CFG->dirroot . '/backup/util/structure/base_final_element.class.php'); 00035 require_once($CFG->dirroot . '/backup/util/structure/base_nested_element.class.php'); 00036 require_once($CFG->dirroot . '/backup/util/structure/simpletest/fixtures/structuremocks.php'); 00037 00042 class base_attribute_test extends UnitTestCase { 00043 00044 public static $includecoverage = array('backup/util/structure/base_attribute.class.php'); 00045 00049 function test_base_attribute() { 00050 $name_with_all_chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_'; 00051 $value_to_test = 'Some <value> to test'; 00052 00053 // Create instance with correct names 00054 $instance = new mock_base_attribute($name_with_all_chars); 00055 $this->assertIsA($instance, 'base_attribute'); 00056 $this->assertEqual($instance->get_name(), $name_with_all_chars); 00057 $this->assertNull($instance->get_value()); 00058 00059 // Set value 00060 $instance->set_value($value_to_test); 00061 $this->assertEqual($instance->get_value(), $value_to_test); 00062 00063 // Get to_string() results (with values) 00064 $instance = new mock_base_attribute($name_with_all_chars); 00065 $instance->set_value($value_to_test); 00066 $tostring = $instance->to_string(true); 00067 $this->assertTrue(strpos($tostring, '@' . $name_with_all_chars) !== false); 00068 $this->assertTrue(strpos($tostring, ' => ') !== false); 00069 $this->assertTrue(strpos($tostring, $value_to_test) !== false); 00070 } 00071 }