Simpletest Coverage - modules/blog/blog.pages.inc

1 <?php
2 // $Id: blog.pages.inc,v 1.22 2009/08/10 22:39:24 webchick Exp $
3
4 /**
5 * @file
6 * Page callback file for the blog module.
7 */
8
9 /**
10 * Menu callback; displays a Drupal page containing recent blog entries of a given user.
11 */
12 function blog_page_user($account) {
13 global $user;
14
15 drupal_set_title($title = t("@name's blog", array('@name' => $account->name)), PASS_THROUGH);
16
17 $items = array();
18
19 if (($account->uid == $user->uid) && user_access('create blog content')) {
20 $items[] = l(t('Post new blog entry.'), "node/add/blog");
21 }
22 elseif ($account->uid == $user->uid) {
23 $items[] = t('You are not allowed to post a new blog entry.');
24 }
25
26 $build['blog_actions'] = array(
27 '#items' => $items,
28 '#theme' => 'item_list',
29 '#weight' => -1,
30 );
31
32 $query = db_select('node', 'n')->extend('PagerDefault');
33 $nids = $query
34 ->fields('n', array('nid', 'sticky', 'created'))
35 ->condition('type', 'blog')
36 ->condition('uid', $account->uid)
37 ->condition('status', 1)
38 ->orderBy('sticky', 'DESC')
39 ->orderBy('created', 'DESC')
40 ->limit(variable_get('default_nodes_main', 10))
41 ->addTag('node_access')
42 ->execute()
43 ->fetchCol();
44
45 if (!empty($nids)) {
46 $nodes = node_load_multiple($nids);
47 $build += node_build_multiple($nodes);
48 $build['pager'] = array(
49 '#theme' => 'pager',
50 '#weight' => 5,
51 );
52 }
53 else {
54 if ($account->uid == $user->uid) {
55 drupal_set_message(t('You have not created any blog entries.'));
56 }
57 else {
58 drupal_set_message(t('!author has not created any blog entries.', array('!author' => theme('username', $account))));
59 }
60 }
61 drupal_add_feed(url('blog/' . $account->uid . '/feed'), t('RSS - !title', array('!title' => $title)));
62
63 return $build;
64 }
65
66 /**
67 * Menu callback; displays a Drupal page containing recent blog entries of all users.
68 */
69 function blog_page_last() {
70 global $user;
71 $build = array();
72
73 if (user_access('create blog content')) {
74 $items[] = l(t('Create new blog entry.'), "node/add/blog");
75 $build['blog_actions'] = array(
76 '#items' => $items,
77 '#theme' => 'item_list',
78 '#weight' => -1,
79 );
80 }
81
82 $query = db_select('node', 'n')->extend('PagerDefault');
83 $nids = $query
84 ->fields('n', array('nid', 'sticky', 'created'))
85 ->condition('type', 'blog')
86 ->condition('status', 1)
87 ->orderBy('sticky', 'DESC')
88 ->orderBy('created', 'DESC')
89 ->limit(variable_get('default_nodes_main', 10))
90 ->addTag('node_access')
91 ->execute()
92 ->fetchCol();
93
94 if (!empty($nids)) {
95 $nodes = node_load_multiple($nids);
96 $build += node_build_multiple($nodes);
97 $build['pager'] = array(
98 '#theme' => 'pager',
99 '#weight' => 5,
100 );
101 }
102 else {
103 drupal_set_message(t('No blog entries have been created.'));
104 }
105 drupal_add_feed(url('blog/feed'), t('RSS - blogs'));
106
107 return $build;
108 }
109
110 /**
111 * Menu callback; displays an RSS feed containing recent blog entries of a given user.
112 */
113 function blog_feed_user($account) {
114
115 $nids = db_select('node', 'n')
116 ->fields('n', array('nid', 'created'))
117 ->condition('type', 'blog')
118 ->condition('uid', $account->uid)
119 ->condition('status', 1)
120 ->orderBy('created', 'DESC')
121 ->range(0, variable_get('feed_default_items', 10))
122 ->addTag('node_access')
123 ->execute()
124 ->fetchCol();
125
126 $channel['title'] = t("!name's blog", array('!name' => $account->name));
127 $channel['link'] = url('blog/' . $account->uid, array('absolute' => TRUE));
128
129 node_feed($nids, $channel);
130 }
131
132 /**
133 * Menu callback; displays an RSS feed containing recent blog entries of all users.
134 */
135 function blog_feed_last() {
136 $nids = db_select('node', 'n')
137 ->fields('n', array('nid', 'created'))
138 ->condition('type', 'blog')
139 ->condition('status', 1)
140 ->orderBy('created', 'DESC')
141 ->range(0, variable_get('feed_default_items', 10))
142 ->addTag('node_access')
143 ->execute()
144 ->fetchCol();
145
146 $channel['title'] = t('!site_name blogs', array('!site_name' => variable_get('site_name', 'Drupal')));
147 $channel['link'] = url('blog', array('absolute' => TRUE));
148
149 node_feed($nids, $channel);
150 }
151

Legend

Missed
lines code that were not excersized during program execution.
Covered
lines code were excersized during program execution.
Comment/non executable
Comment or non-executable line of code.
Dead
lines of code that according to xdebug could not be executed. This is counted as coverage code because in almost all cases it is code that runnable.