MDL-19077 Added requires->yui_lib('event') to required_event_handler constructor
[moodle.git] / lib / simpletest / testsimpletestlib.php
CommitLineData
821e4ecf 1<?php
2/**
b1bc1263 3 * Unit tests for (some of) ../simpletestlib.php.
821e4ecf 4 *
821e4ecf 5 * @author T.J.Hunt@open.ac.uk
6 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
b1bc1263 7 * @package SimpleTestEx
821e4ecf 8 */
9
10if (!defined('MOODLE_INTERNAL')) {
11 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
12}
13
58fa5d6f 14class simpletestlib_test extends FakeDBUnitTestCase {
821e4ecf 15
b1bc1263 16 function test_load_delete_test_data() {
821e4ecf 17 global $DB;
821e4ecf 18 $contexts = $this->load_test_data('context',
19 array('contextlevel', 'instanceid', 'path', 'depth'), array(
20 array(10, 666, '', 1),
21 array(40, 666, '', 2),
22 array(50, 666, '', 3),
23 ));
821e4ecf 24
25 // Just test load_test_data and delete_test_data for now.
26 $this->assertTrue($DB->record_exists('context', array('id' => $contexts[1]->id)));
b1bc1263 27 $this->assertTrue($DB->get_field('context', 'contextlevel', array('id' => $contexts[2]->id)), $contexts[2]->contextlevel);
821e4ecf 28 $this->delete_test_data('context', $contexts);
29 $this->assertFalse($DB->record_exists('context', array('id' => $contexts[1]->id)));
30 }
31}
b1bc1263 32
8954245a 33
34/**
35 * Unit tests for the ContainsTagWithAttribute_test class.
36 *
37 * @copyright 2009 Tim Hunt
38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39 */
40class ContainsTagWithAttribute_test extends UnitTestCase {
41 function test_simple() {
42 $expectation = new ContainsTagWithAttribute('span', 'class', 'error');
43 $this->assertTrue($expectation->test('<span class="error">message</span>'));
44 }
45
46 function test_other_attrs() {
47 $expectation = new ContainsTagWithAttribute('span', 'class', 'error');
48 $this->assertTrue($expectation->test('<span otherattr="thingy" class = "error" otherattr="thingy">message</span>'));
49 }
50
51 function test_fails() {
52 $expectation = new ContainsTagWithAttribute('span', 'class', 'error');
53 $this->assertFalse($expectation->test('<span class="mismatch">message</span>'));
54 }
5daf5d35 55
56 function test_link() {
57 $expectation = new ContainsTagWithAttribute('a', 'href', 'http://www.test.com');
58 $this->assertTrue($expectation->test('<a href="http://www.test.com">Click Here</a>'));
59 }
8954245a 60}
61
62/**
63 * Unit tests for the ContainsTagWithAttribute_test class.
64 *
65 * @copyright 2009 Tim Hunt
66 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
67 */
68class ContainsTagWithContents_test extends UnitTestCase {
69 function test_simple() {
70 $expectation = new ContainsTagWithContents('span', 'message');
71 $this->assertTrue($expectation->test('<span class="error">message</span>'));
72 }
73
74 function test_no_end() {
75 $expectation = new ContainsTagWithContents('span', 'message');
76 $this->assertFalse($expectation->test('<span class="error">message'));
77 }
78}
79
821e4ecf 80?>