/[drupal]/drupal/modules/blog/blog.test
ViewVC logotype

Contents of /drupal/modules/blog/blog.test

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.21 - (show annotations) (download) (as text)
Sun Nov 1 21:26:44 2009 UTC (3 weeks, 6 days ago) by webchick
Branch: MAIN
Changes since 1.20: +8 -8 lines
File MIME type: text/x-php
#192056 by effulgentsia, Dave Cohen, andypost, hswong3i, geodaniel, pwolanin, and dahacouk: Ensure user's raw login name is never output directly.
1 <?php
2 // $Id: blog.test,v 1.20 2009/11/01 12:11:10 dries Exp $
3
4 class BlogTestCase extends DrupalWebTestCase {
5 protected $big_user;
6 protected $own_user;
7 protected $any_user;
8
9 public static function getInfo() {
10 return array(
11 'name' => 'Blog functionality',
12 'description' => 'Create, view, edit, delete, and change blog entries and verify its consistency in the database.',
13 'group' => 'Blog',
14 );
15 }
16
17 /**
18 * Enable modules and create users with specific permissions.
19 */
20 function setUp() {
21 parent::setUp('blog');
22 // Create users.
23 $this->big_user = $this->drupalCreateUser(array('administer blocks'));
24 $this->own_user = $this->drupalCreateUser(array('create blog content', 'edit own blog content', 'delete own blog content'));
25 $this->any_user = $this->drupalCreateUser(array('create blog content', 'edit any blog content', 'delete any blog content', 'access administration pages'));
26 }
27
28 /**
29 * Confirm that the "You are not allowed to post a new blog entry." message
30 * shows up if a user submitted blog entries, has been denied that
31 * permission, and goes to the blog page.
32 */
33 function testUnprivilegedUser() {
34 // Create a blog node for a user with no blog permissions.
35 $this->drupalCreateNode(array('type' => 'blog', 'uid' => $this->big_user->uid));
36
37 $this->drupalLogin($this->big_user);
38
39 $this->drupalGet('blog/' . $this->big_user->uid);
40 $this->assertResponse(200);
41 $this->assertTitle(t("@name's blog", array('@name' => format_username($this->big_user))) . ' | Drupal', t('Blog title was displayed'));
42 $this->assertText(t('You are not allowed to post a new blog entry.'), t('No new entries can be posted without the right permission'));
43 }
44
45 /**
46 * View the blog of a user with no blog entries as another user.
47 */
48 function testBlogPageNoEntries() {
49 $this->drupalLogin($this->big_user);
50
51 $this->drupalGet('blog/' . $this->own_user->uid);
52 $this->assertResponse(200);
53 $this->assertTitle(t("@name's blog", array('@name' => format_username($this->own_user))) . ' | Drupal', t('Blog title was displayed'));
54 $this->assertText(t('@author has not created any blog entries.', array('@author' => format_username($this->own_user))), t('Users blog displayed with no entries'));
55 }
56
57 /**
58 * Login users, create blog nodes, and test blog functionality through the admin and user interfaces.
59 */
60 function testBlog() {
61 // Login the admin user.
62 $this->drupalLogin($this->big_user);
63 // Enable the recent blog block.
64 $edit = array();
65 $edit['blog_recent[region]'] = 'sidebar_second';
66 $this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
67 $this->assertResponse(200);
68
69 // Do basic tests for each user.
70 $this->doBasicTests($this->any_user, TRUE);
71 $this->doBasicTests($this->own_user, FALSE);
72
73 // Create another blog node for the any blog user.
74 $node = $this->drupalCreateNode(array('type' => 'blog', 'uid' => $this->any_user->uid));
75 // Verify the own blog user only has access to the blog view node.
76 $this->verifyBlogs($this->any_user, $node, FALSE, 403);
77
78 // Create another blog node for the own blog user.
79 $node = $this->drupalCreateNode(array('type' => 'blog', 'uid' => $this->own_user->uid));
80 // Login the any blog user.
81 $this->drupalLogin($this->any_user);
82 // Verify the any blog user has access to all the blog nodes.
83 $this->verifyBlogs($this->own_user, $node, TRUE);
84 }
85
86 /**
87 * Run basic tests on the indicated user.
88 *
89 * @param object $user
90 * The logged in user.
91 * @param boolean $admin
92 * User has 'access administration pages' privilege.
93 */
94 private function doBasicTests($user, $admin) {
95 // Login the user.
96 $this->drupalLogin($user);
97 // Create blog node.
98 $node = $this->drupalCreateNode(array('type' => 'blog'));
99 // Verify the user has access to all the blog nodes.
100 $this->verifyBlogs($user, $node, $admin);
101 // Create one more node to test the blog page with more than one node
102 $this->drupalCreateNode(array('type' => 'blog', 'uid' => $user->uid));
103 // Verify the blog links are displayed.
104 $this->verifyBlogLinks($user);
105 }
106
107 /**
108 * Verify the logged in user has the desired access to the various blog nodes.
109 *
110 * @param object $node_user
111 * The user who creates the node.
112 * @param object $node
113 * A node object.
114 * @param boolean $admin
115 * User has 'access administration pages' privilege.
116 * @param integer $response
117 * HTTP response code.
118 */
119 private function verifyBlogs($node_user, stdClass $node, $admin, $response = 200) {
120 $crumb = '›';
121 $quote = '&#039;';
122
123 $response2 = ($admin) ? 200 : 403;
124
125 // View blog help node.
126 $this->drupalGet('admin/help/blog');
127 $this->assertResponse($response2);
128 if ($response2 == 200) {
129 $this->assertTitle(t('Blog | Drupal'), t('Blog help node was displayed'));
130 $this->assertText(t('Blog'), t('Blog help node was displayed'));
131 }
132
133 // Verify the blog block was displayed.
134 $this->drupalGet('');
135 $this->assertResponse(200);
136 $this->assertText(t('Recent blog posts'), t('Blog block was displayed'));
137
138 // View blog node.
139 $this->drupalGet('node/' . $node->nid);
140 $this->assertResponse(200);
141 $this->assertTitle($node->title[FIELD_LANGUAGE_NONE][0]['value'] . ' | Drupal', t('Blog node was displayed'));
142 $this->assertText(t('Home ' . $crumb . ' Blogs ' . $crumb . ' @name' . $quote . 's blog', array('@name' => format_username($node_user))), t('Breadcrumbs were displayed'));
143
144 // View blog edit node.
145 $this->drupalGet('node/' . $node->nid . '/edit');
146 $this->assertResponse($response);
147 if ($response == 200) {
148 $this->assertTitle('Edit Blog entry ' . $node->title[FIELD_LANGUAGE_NONE][0]['value'] . ' | Drupal', t('Blog edit node was displayed'));
149 }
150
151 if ($response == 200) {
152 // Edit blog node.
153 $edit = array();
154 $langcode = FIELD_LANGUAGE_NONE;
155 $edit["title[$langcode][0][value]"] = 'node/' . $node->nid;
156 $edit["body[$langcode][0][value]"] = $this->randomName(256);
157 $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
158 $this->assertRaw(t('Blog entry %title has been updated.', array('%title' => $edit["title[$langcode][0][value]"])), t('Blog node was edited'));
159
160 // Delete blog node.
161 $this->drupalPost('node/' . $node->nid . '/delete', array(), t('Delete'));
162 $this->assertResponse($response);
163 $this->assertRaw(t('Blog entry %title has been deleted.', array('%title' => $edit["title[$langcode][0][value]"])), t('Blog node was deleted'));
164 }
165 }
166
167 /**
168 * Verify the blog links are displayed to the logged in user.
169 *
170 * @param object $user
171 * The logged in user.
172 */
173 private function verifyBlogLinks($user) {
174 $crumb = '›';
175
176 // Confirm blog entries link exists on the user page.
177 $this->drupalGet('user/' . $user->uid);
178 $this->assertResponse(200);
179 $this->assertText(t('View recent blog entries'), t('View recent blog entries link was displayed'));
180
181 // Confirm the recent blog entries link goes to the user's blog page.
182 $this->clickLink('View recent blog entries');
183 $this->assertTitle(t("@name's blog | Drupal", array('@name' => format_username($user))), t('View recent blog entries link target was correct'));
184
185 // Confirm a blog page was displayed.
186 $this->drupalGet('blog');
187 $this->assertResponse(200);
188 $this->assertTitle('Blogs | Drupal', t('Blog page was displayed'));
189 $this->assertText(t('Home'), t('Breadcrumbs were displayed'));
190 $this->assertLink(t('Create new blog entry.'));
191
192 // Confirm a blog page was displayed per user.
193 $this->drupalGet('blog/' . $user->uid);
194 $this->assertTitle(t("@name's blog | Drupal", array('@name' => format_username($user))), t('User blog node was displayed'));
195
196 // Confirm a blog feed was displayed.
197 $this->drupalGet('blog/feed');
198 $this->assertTitle(t('Drupal blogs'), t('Blog feed was displayed'));
199
200 // Confirm a blog feed was displayed per user.
201 $this->drupalGet('blog/' . $user->uid . '/feed');
202 $this->assertTitle(t("@name's blog", array('@name' => format_username($user))), t('User blog feed was displayed'));
203 }
204 }

  ViewVC Help
Powered by ViewVC 1.1.2