cae83708 |
1 | <?php |
2 | |
3 | // This file is part of Moodle - http://moodle.org/ |
4 | // |
5 | // Moodle is free software: you can redistribute it and/or modify |
6 | // it under the terms of the GNU General Public License as published by |
7 | // the Free Software Foundation, either version 3 of the License, or |
8 | // (at your option) any later version. |
9 | // |
10 | // Moodle is distributed in the hope that it will be useful, |
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | // GNU General Public License for more details. |
14 | // |
15 | // You should have received a copy of the GNU General Public License |
16 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
17 | |
18 | |
19 | /** |
20 | * Unit tests for blog |
21 | * |
22 | * @package moodlecore |
23 | * @subpackage blog |
24 | * @copyright 2009 Nicolas Connault |
25 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
26 | */ |
27 | |
28 | require_once($CFG->dirroot . '/blog/locallib.php'); |
29 | |
30 | class bloglib_test extends UnitTestCaseUsingDatabase { |
31 | |
32 | public static $includecoverage = array('blog/locallib.php'); |
33 | |
34 | public function test_overrides() { |
35 | // Try all the filters at once: Only the entry filter is active |
36 | $blog_listing = new blog_listing(array('site' => 1, 'course' => 1, 'module' => 1, 'group' => 1, 'user' => 1, 'tag' => 1, 'entry' => 1)); |
37 | $this->assertFalse(array_key_exists('site', $blog_listing->filters)); |
38 | $this->assertFalse(array_key_exists('course', $blog_listing->filters)); |
39 | $this->assertFalse(array_key_exists('module', $blog_listing->filters)); |
40 | $this->assertFalse(array_key_exists('group', $blog_listing->filters)); |
41 | $this->assertFalse(array_key_exists('user', $blog_listing->filters)); |
42 | $this->assertFalse(array_key_exists('tag', $blog_listing->filters)); |
43 | $this->assertTrue(array_key_exists('entry', $blog_listing->filters)); |
44 | |
45 | // Again, but without the entry filter: This time, the tag, user and module filters are active |
46 | $blog_listing = new blog_listing(array('site' => 1, 'course' => 1, 'module' => 1, 'group' => 1, 'user' => 1, 'tag' => 1)); |
47 | $this->assertFalse(array_key_exists('site', $blog_listing->filters)); |
48 | $this->assertFalse(array_key_exists('course', $blog_listing->filters)); |
49 | $this->assertFalse(array_key_exists('group', $blog_listing->filters)); |
50 | $this->assertTrue(array_key_exists('module', $blog_listing->filters)); |
51 | $this->assertTrue(array_key_exists('user', $blog_listing->filters)); |
52 | $this->assertTrue(array_key_exists('tag', $blog_listing->filters)); |
53 | |
54 | // We should get the same result by removing the 3 inactive filters: site, course and group: |
55 | $blog_listing = new blog_listing(array('module' => 1, 'user' => 1, 'tag' => 1)); |
56 | $this->assertFalse(array_key_exists('site', $blog_listing->filters)); |
57 | $this->assertFalse(array_key_exists('course', $blog_listing->filters)); |
58 | $this->assertFalse(array_key_exists('group', $blog_listing->filters)); |
59 | $this->assertTrue(array_key_exists('module', $blog_listing->filters)); |
60 | $this->assertTrue(array_key_exists('user', $blog_listing->filters)); |
61 | $this->assertTrue(array_key_exists('tag', $blog_listing->filters)); |
62 | |
63 | // Now use the group and module together |
64 | $blog_listing = new blog_listing(array('module' => 1, 'group' => 1, 'tag' => 1)); |
65 | $this->assertTrue(array_key_exists('group', $blog_listing->filters)); |
66 | $this->assertTrue(array_key_exists('module', $blog_listing->filters)); |
67 | $this->assertFalse(array_key_exists('user', $blog_listing->filters)); |
68 | $this->assertTrue(array_key_exists('tag', $blog_listing->filters)); |
69 | |
70 | $blog_listing = new blog_listing(array('course' => 2)); |
71 | $this->assertTrue(array_key_exists('course', $blog_listing->filters)); |
72 | |
73 | $blog_listing = new blog_listing(array('course' => 2, 'group' => 12)); |
74 | $this->assertFalse(array_key_exists('course', $blog_listing->filters)); |
75 | $this->assertTrue(array_key_exists('group', $blog_listing->filters)); |
76 | |
77 | $blog_listing = new blog_listing(array('site' => 2, 'group' => 12)); |
78 | $this->assertFalse(array_key_exists('site', $blog_listing->filters)); |
79 | $this->assertTrue(array_key_exists('group', $blog_listing->filters)); |
80 | |
81 | $blog_listing = new blog_listing(array('user' => 2, 'group' => 12)); |
82 | $this->assertFalse(array_key_exists('group', $blog_listing->filters)); |
83 | $this->assertTrue(array_key_exists('user', $blog_listing->filters)); |
84 | |
85 | } |
86 | |
87 | /** |
88 | * Some user, course, module, group and blog sample data needs to be setup for this test |
89 | */ |
90 | public function test_blog_get_headers_case_1() { |
91 | global $CFG, $PAGE, $OUTPUT; |
92 | |
93 | $this->create_test_tables('post', 'tag', 'course', 'user', 'role', 'role_assignments', 'group', 'blog_associations', |
94 | 'course_modules', 'role_capabilities', 'assignment', 'tag_correlation', 'tag_instance'); |
95 | |
96 | $contexts = $this->load_test_data('context', |
97 | array('contextlevel', 'instanceid', 'path', 'depth'), array( |
98 | 1 => array(40, 666, '', 2), |
99 | 2 => array(50, 666, '', 3), |
100 | 3 => array(70, 666, '', 4), |
101 | )); |
102 | |
103 | $this->load_test_data('course', |
104 | array('id', 'fullname', 'shortname', 'format'), |
105 | array( |
106 | array(1, 'My Moodle Site', 'moodle', 'site'), |
107 | array(2, 'Course 1', 'course1', 'weeks'), |
108 | array(3, 'Course 2', 'course2', 'weeks') |
109 | ) |
110 | ); |
111 | $this->load_test_data('user', |
112 | array('id', 'confirmed', 'username', 'firstname', 'lastname'), |
113 | array( array(1, 1, 'joebloe', 'Joe', 'Bloe'))); |
114 | |
115 | $this->switch_to_test_db(); |
116 | |
117 | $userrole = create_role(get_string('authenticateduser'), 'user', get_string('authenticateduserdescription'), 'moodle/legacy:user'); |
118 | $student = $this->testdb->get_record('role', array('shortname' => 'student')); |
119 | |
120 | $ras = $this->load_test_data('role_assignments', array('userid', 'roleid', 'contextid'), |
121 | array(array(1, $student->id, $context[2]->id))); |
122 | |
123 | // Case 1: A single blog entry |
124 | $PAGE->url = new moodle_url($CFG->wwwroot . '/blog/index.php', array('entryid' => 1)); |
125 | $blog_headers = blog_get_headers(); |
126 | |
127 | $this->assertEqual($blog_headers['title'], ''); |
128 | } |
129 | } |