weekly release 1.9.12+
[moodle.git] / lib / simpletest / testaccesslib.php
blobdb04a70ba551800be699945759b78f4ea2efb946
1 <?php
2 /**
3 * Unit tests for (some of) ../accesslib.php.
5 * @copyright &copy; 2006 The Open University
6 * @author T.J.Hunt@open.ac.uk
7 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
8 * @package moodlecore
9 */
11 if (!defined('MOODLE_INTERNAL')) {
12 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
15 class accesslib_test extends UnitTestCase {
17 function setUp() {
20 function tearDown() {
23 function test_get_parent_contexts() {
24 $context = get_context_instance(CONTEXT_SYSTEM);
25 $this->assertEqual(get_parent_contexts($context), array());
27 $context = new stdClass;
28 $context->path = '/1/25';
29 $this->assertEqual(get_parent_contexts($context), array(1));
31 $context = new stdClass;
32 $context->path = '/1/123/234/345/456';
33 $this->assertEqual(get_parent_contexts($context), array(345, 234, 123, 1));
36 function test_get_parent_contextid() {
37 $context = get_context_instance(CONTEXT_SYSTEM);
38 $this->assertFalse(get_parent_contextid($context));
40 $context = new stdClass;
41 $context->path = '/1/25';
42 $this->assertEqual(get_parent_contextid($context), 1);
44 $context = new stdClass;
45 $context->path = '/1/123/234/345/456';
46 $this->assertEqual(get_parent_contextid($context), 345);