Updated the HEAD build version to 20090716
[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 }
55}
56
57/**
58 * Unit tests for the ContainsTagWithAttribute_test class.
59 *
60 * @copyright 2009 Tim Hunt
61 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
62 */
63class ContainsTagWithContents_test extends UnitTestCase {
64 function test_simple() {
65 $expectation = new ContainsTagWithContents('span', 'message');
66 $this->assertTrue($expectation->test('<span class="error">message</span>'));
67 }
68
69 function test_no_end() {
70 $expectation = new ContainsTagWithContents('span', 'message');
71 $this->assertFalse($expectation->test('<span class="error">message'));
72 }
73}
74
821e4ecf 75?>