123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- <?php
- class BlogTestCase extends DrupalWebTestCase {
- protected $big_user;
- protected $own_user;
- protected $any_user;
- public static function getInfo() {
- return array(
- 'name' => 'Blog functionality',
- 'description' => 'Create, view, edit, delete, and change blog entries and verify its consistency in the database.',
- 'group' => 'Blog',
- );
- }
-
- function setUp() {
- parent::setUp('blog');
-
- $this->big_user = $this->drupalCreateUser(array('administer blocks'));
- $this->own_user = $this->drupalCreateUser(array('create blog content', 'edit own blog content', 'delete own blog content'));
- $this->any_user = $this->drupalCreateUser(array('create blog content', 'edit any blog content', 'delete any blog content', 'access administration pages'));
- }
-
- function testUnprivilegedUser() {
-
- $this->drupalCreateNode(array('type' => 'blog', 'uid' => $this->big_user->uid));
- $this->drupalLogin($this->big_user);
- $this->drupalGet('blog/' . $this->big_user->uid);
- $this->assertResponse(200);
- $this->assertTitle(t("@name's blog", array('@name' => format_username($this->big_user))) . ' | Drupal', t('Blog title was displayed'));
- $this->assertText(t('You are not allowed to post a new blog entry.'), t('No new entries can be posted without the right permission'));
- }
-
- function testBlogPageNoEntries() {
- $this->drupalLogin($this->big_user);
- $this->drupalGet('blog/' . $this->own_user->uid);
- $this->assertResponse(200);
- $this->assertTitle(t("@name's blog", array('@name' => format_username($this->own_user))) . ' | Drupal', t('Blog title was displayed'));
- $this->assertText(t('@author has not created any blog entries.', array('@author' => format_username($this->own_user))), t('Users blog displayed with no entries'));
- }
-
- function testBlog() {
-
- $this->drupalLogin($this->big_user);
-
- $edit = array();
- $edit['blocks[blog_recent][region]'] = 'sidebar_second';
- $this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
- $this->assertResponse(200);
-
- $edit = array();
- $edit['blog_block_count'] = 5;
- $this->drupalPost('admin/structure/block/manage/blog/recent/configure', $edit, t('Save block'));
- $this->assertEqual(variable_get('blog_block_count', 10), 5, t('Number of recent blog posts changed.'));
-
- $this->doBasicTests($this->any_user, TRUE);
- $this->doBasicTests($this->own_user, FALSE);
-
- $node = $this->drupalCreateNode(array('type' => 'blog', 'uid' => $this->any_user->uid));
-
- $this->verifyBlogs($this->any_user, $node, FALSE, 403);
-
- $node = $this->drupalCreateNode(array('type' => 'blog', 'uid' => $this->own_user->uid));
-
- $this->drupalLogin($this->any_user);
-
- $this->verifyBlogs($this->own_user, $node, TRUE);
- }
-
- private function doBasicTests($user, $admin) {
-
- $this->drupalLogin($user);
-
- $node = $this->drupalCreateNode(array('type' => 'blog'));
-
- $this->verifyBlogs($user, $node, $admin);
-
- $this->drupalCreateNode(array('type' => 'blog', 'uid' => $user->uid));
-
- $this->verifyBlogLinks($user);
- }
-
- private function verifyBlogs($node_user, $node, $admin, $response = 200) {
- $response2 = ($admin) ? 200 : 403;
-
- $this->drupalGet('admin/help/blog');
- $this->assertResponse($response2);
- if ($response2 == 200) {
- $this->assertTitle(t('Blog | Drupal'), t('Blog help node was displayed'));
- $this->assertText(t('Blog'), t('Blog help node was displayed'));
- }
-
- $this->drupalGet('');
- $this->assertResponse(200);
- $this->assertText(t('Recent blog posts'), t('Blog block was displayed'));
-
- $this->drupalGet('node/' . $node->nid);
- $this->assertResponse(200);
- $this->assertTitle($node->title . ' | Drupal', t('Blog node was displayed'));
- $breadcrumb = array(
- l(t('Home'), NULL),
- l(t('Blogs'), 'blog'),
- l(t("!name's blog", array('!name' => format_username($node_user))), 'blog/' . $node_user->uid),
- );
- $this->assertRaw(theme('breadcrumb', array('breadcrumb' => $breadcrumb)), t('Breadcrumbs were displayed'));
-
- $this->drupalGet('node/' . $node->nid . '/edit');
- $this->assertResponse($response);
- if ($response == 200) {
- $this->assertTitle('Edit Blog entry ' . $node->title . ' | Drupal', t('Blog edit node was displayed'));
- }
- if ($response == 200) {
-
- $edit = array();
- $langcode = LANGUAGE_NONE;
- $edit["title"] = 'node/' . $node->nid;
- $edit["body[$langcode][0][value]"] = $this->randomName(256);
- $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
- $this->assertRaw(t('Blog entry %title has been updated.', array('%title' => $edit["title"])), t('Blog node was edited'));
-
- $this->drupalPost('node/' . $node->nid . '/delete', array(), t('Delete'));
- $this->assertResponse($response);
- $this->assertRaw(t('Blog entry %title has been deleted.', array('%title' => $edit["title"])), t('Blog node was deleted'));
- }
- }
-
- private function verifyBlogLinks($user) {
-
- $this->drupalGet('user/' . $user->uid);
- $this->assertResponse(200);
- $this->assertText(t('View recent blog entries'), t('View recent blog entries link was displayed'));
-
- $this->clickLink('View recent blog entries');
- $this->assertTitle(t("@name's blog | Drupal", array('@name' => format_username($user))), t('View recent blog entries link target was correct'));
-
- $this->drupalGet('blog');
- $this->assertResponse(200);
- $this->assertTitle('Blogs | Drupal', t('Blog page was displayed'));
- $this->assertText(t('Home'), t('Breadcrumbs were displayed'));
- $this->assertLink(t('Create new blog entry'));
-
- $this->drupalGet('blog/' . $user->uid);
- $this->assertTitle(t("@name's blog | Drupal", array('@name' => format_username($user))), t('User blog node was displayed'));
-
- $this->drupalGet('blog/feed');
- $this->assertTitle(t('Drupal blogs'), t('Blog feed was displayed'));
-
- $this->drupalGet('blog/' . $user->uid . '/feed');
- $this->assertTitle(t("@name's blog", array('@name' => format_username($user))), t('User blog feed was displayed'));
- }
- }
|