See Release Notes
Long Term Support Release
Differences Between: [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]
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 * @package core_backup 19 * @category phpunit 20 * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} 21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 */ 23 24 defined('MOODLE_INTERNAL') || die(); 25 26 // Include all the needed stuff 27 require_once (__DIR__.'/fixtures/structure_fixtures.php'); 28 29 30 /** 31 * Unit test case the base_atom class. Note: as it's abstract we are testing 32 * mock_base_atom instantiable class instead 33 */ 34 class backup_base_atom_testcase extends basic_testcase { 35 36 /** 37 * Correct base_atom_tests 38 */ 39 function test_base_atom() { 40 $name_with_all_chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_'; 41 $value_to_test = 'Some <value> to test'; 42 43 // Create instance with correct names 44 $instance = new mock_base_atom($name_with_all_chars); 45 $this->assertInstanceOf('base_atom', $instance); 46 $this->assertEquals($instance->get_name(), $name_with_all_chars); 47 $this->assertFalse($instance->is_set()); 48 $this->assertNull($instance->get_value()); 49 50 // Set value 51 $instance->set_value($value_to_test); 52 $this->assertEquals($instance->get_value(), $value_to_test); 53 $this->assertTrue($instance->is_set()); 54 55 // Clean value 56 $instance->clean_value(); 57 $this->assertFalse($instance->is_set()); 58 $this->assertNull($instance->get_value()); 59 60 // Get to_string() results (with values) 61 $instance = new mock_base_atom($name_with_all_chars); 62 $instance->set_value($value_to_test); 63 $tostring = $instance->to_string(true); 64 $this->assertTrue(strpos($tostring, $name_with_all_chars) !== false); 65 $this->assertTrue(strpos($tostring, ' => ') !== false); 66 $this->assertTrue(strpos($tostring, $value_to_test) !== false); 67 68 // Get to_string() results (without values) 69 $tostring = $instance->to_string(false); 70 $this->assertTrue(strpos($tostring, $name_with_all_chars) !== false); 71 $this->assertFalse(strpos($tostring, ' => ')); 72 $this->assertFalse(strpos($tostring, $value_to_test)); 73 } 74 75 /** 76 * Throwing exception base_atom tests 77 */ 78 function test_base_atom_exceptions() { 79 // empty names 80 try { 81 $instance = new mock_base_atom(''); 82 $this->fail("Expecting base_atom_struct_exception exception, none occurred"); 83 } catch (Exception $e) { 84 $this->assertTrue($e instanceof base_atom_struct_exception); 85 } 86 87 // whitespace names 88 try { 89 $instance = new mock_base_atom('TESTING ATOM'); 90 $this->fail("Expecting base_atom_struct_exception exception, none occurred"); 91 } catch (Exception $e) { 92 $this->assertTrue($e instanceof base_atom_struct_exception); 93 } 94 95 // ascii names 96 try { 97 $instance = new mock_base_atom('TESTING-ATOM'); 98 $this->fail("Expecting base_atom_struct_exception exception, none occurred"); 99 } catch (Exception $e) { 100 $this->assertTrue($e instanceof base_atom_struct_exception); 101 } 102 try { 103 $instance = new mock_base_atom('TESTING_ATOM_Á'); 104 $this->fail("Expecting base_atom_struct_exception exception, none occurred"); 105 } catch (Exception $e) { 106 $this->assertTrue($e instanceof base_atom_struct_exception); 107 } 108 109 // setting already set value 110 $instance = new mock_base_atom('TEST'); 111 $instance->set_value('test'); 112 try { 113 $instance->set_value('test'); 114 $this->fail("Expecting base_atom_content_exception exception, none occurred"); 115 } catch (Exception $e) { 116 $this->assertTrue($e instanceof base_atom_content_exception); 117 } 118 } 119 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body