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