/[drupal]/contributions/modules/bio/tests/bio.test
ViewVC logotype

Diff of /contributions/modules/bio/tests/bio.test

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

revision 1.1, Fri Jan 25 05:57:11 2008 UTC revision 1.2, Sat Apr 11 01:32:11 2009 UTC
# Line 0  Line 1 
1    <?php
2    // $Id: bio.test,v 1.1.2.11 2008/01/28 08:45:37 webchick Exp $
3    
4    /**
5     * @file
6     * SimpleTests for Bio module.
7     */
8    
9    /**
10     * Bio test case.
11     */
12    class BioTest extends DrupalTestCase {
13    
14      /**
15       * User with minimal permissions.
16       */
17      var $basic_user;
18    
19      /**
20       * Administrative user.
21       */
22      var $admin_user;
23    
24      /**
25       * Drupal SimpleTest method: return metadata about the test.
26       */
27      function get_info() {
28        return array(
29          'name'  => t('Bio module tests'),
30          'desc'  => t('Tests functionality of Bio module.'),
31          'group' => t('Bio module'),
32        );
33      }
34    
35      /**
36       * SimpleTest core method: code run before each and every test method.
37       */
38      function setUp() {
39        parent::setUp();
40    
41        // Set the 'bio' node type as the Bio node type.
42        $this->drupalVariableSet('bio_nodetype', 'bio');
43    
44        // Create a basic user with minimal permissions.
45        $permissions = array(
46          'access content',
47          'create bio content',
48          'edit own bio content',
49          'create page content',
50          'create story content',
51          'access user profiles',
52        );
53        $this->basic_user = $this->drupalCreateUserRolePerm($permissions);
54    
55        // Create an administrative user with more extensive permissions.
56        $permissions = array(
57          'access content',
58          'administer nodes',
59        );
60        $this->admin_user = $this->drupalCreateUserRolePerm($permissions);
61      }
62    
63      /**
64       * SimpleTest core method: code run after each and every test method.
65       */
66      function tearDown() {
67        //
68    
69        parent::tearDown();
70      }
71    
72      /**
73       * Perform various tests related to basic adding/editing/deleting of bios.
74       *
75       * @todo Fill in stub function.
76       */
77      function testBioCrud() {
78        // Create a biography for the basic user.
79        $this->drupalLoginUser($this->basic_user);
80        $uid = $this->basic_user->uid;
81        $node = $this->bioCreateBio();
82    
83        // Test bio deletion on user deletion.
84        user_delete(array(), $uid);
85        $this->assertFalse(bio_for_user($uid), t('Checking that bio was deleted when user account was deleted.'));
86      }
87    
88      /**
89       * Ensure that basic users may create only one bio for themselves.
90       */
91      function testBioCreateBasicUserBio() {
92        // Create a biography for the basic user.
93        $this->drupalLoginUser($this->basic_user);
94        $node = $this->bioCreateBio();
95    
96        // Have user attempt to create another one; confirm they're redirected back
97        // to their existing bio node.
98        $html = $this->drupalGet('node/add/bio');
99        $content = $this->drupalGetContent();
100        $this->assertText($node->title, t('Checking for redirection to existing bio node'));
101        $this->assertWantedRaw("node/$node->nid/edit", t('Ensuring redirection to form'));
102      }
103    
104      /**
105       * Ensure that administrators can create bios for other users.
106       */
107      function testBioCreateAdminUserBio() {
108        // Create a bio for the admin user.
109        $this->drupalLoginUser($this->admin_user);
110        $node = $this->bioCreateBio();
111    
112        // Confirm that admin user is NOT redirected to their existing bio.
113        $this->drupalGet('node/add/bio');
114        $this->assertNoText($node->title, t('Checking for clean add form for admin user with bio node'));
115    
116        // Create a bio for the basic user.
117        $node = $this->bioCreateBio($this->basic_user);
118        $this->drupalGet("node/$node->nid");
119        $this->assertText($node->body, t('Checking for admin creation of basic user bio'));
120    
121        // Ensure admin user can NOT create two bios for themselves.
122        $this->bioCreateBio();
123        $this->assertText(t('This user already has a Biography.'), t('Checking for block of duplicate bio from admin user'));
124      }
125    
126      /**
127       * Ensure that the "Use bio for user profiles" option is working properly.
128       */
129      function testBioProfile() {
130        // Enable setting and login as basic user to test.
131        $this->drupalVariableSet('bio_profile', 1);
132        $this->drupalLoginUser($this->basic_user);
133        $uid = $this->basic_user->uid;
134    
135        // Check to see if link to edit bio shows up in user profile.
136        $this->drupalGet("user/$uid");
137        $this->assertWantedRaw("user/$uid/bio", t('Checking for link to edit bio on user profile'));
138    
139        // NOTE: I tried here to test the user/$uid/bio form itself, but I can't.
140        // Bio has a menu access check which fails because $user->uid is me, and
141        // not the fake SimpleTest user $uid. See http://drupal.org/node/214053 for
142        // all the boring, nitty-gritty details...
143        //
144        // Long story short, using the bioCreateBio() method instead.
145        // $edit['title'] = $this->randomName(32);
146        // $edit['body'] = $this->randomName(32);
147        // $this->drupalPostRequest("user/$uid/bio", $edit, t('Submit'));
148        // $this->drupalGet("user/$uid");
149        // $this->assertText($edit['body'], t('Checking for bio content on user profile'));
150    
151        // Create a bio for this user.
152        $node = $this->bioCreateBio();
153    
154        // Check for bio information on user profile page.
155        $this->drupalGet("user/$uid");
156        $this->assertText($node->body, t('Checking for bio content on user profile'));
157    
158        // Try to access bio node directly; should be redirected to profile page.
159        // TODO: This test fails. node/X yields an access denied. :(
160        // Might be related to http://drupal.org/node/214053 as well?
161        // $this->drupalGet("node/$node->nid");
162        // $this->assertText(t('Member for'), t('Checking for bio to profile redirect'));
163    
164        // Ensure an access denied error is generated when trying to go to another
165        // user's bio edit page.
166        $permissions = array(
167          'access content',
168          'create bio content',
169          'edit own bio content',
170          'access user profiles',
171        );
172        $this->basic_user2 = $this->drupalCreateUserRolePerm($permissions);
173    
174        // In order to login as second user, need to logout as first user.
175        // Keep tabs on http://drupal.org/node/213454 for updates.
176        // TODO: Why doesn't drupalGet() work for this?
177        $this->get(url('logout', NULL, NULL, TRUE));
178    
179        $this->drupalLoginUser($this->basic_user2);
180        $this->drupalGet("user/$uid/bio");
181        $this->assertText(t('Access denied'), t("Checking for access denied when basic user tries to edit another user's bio"));
182    
183        // As admin, make sure that the name field is not alterable from user/X/bio.
184        $this->get(url('logout', NULL, NULL, TRUE));
185        $this->drupalLoginUser($this->admin_user);
186        $this->drupalPostRequest("user/$uid/bio", array('name' => $this->admin_user->name), t('Submit'));
187        $nid = bio_for_user($this->admin_user->uid);
188        $this->assertFalse($nid, t('Checking for inability to edit author on bio node'));
189    
190        // TODO: Check with user who doesn't have access to node.
191      }
192    
193      /**
194       * Test "takeover profile" option.
195       */
196      function testBioTakeoverProfile() {
197        // "Use bio as user profile" option is also required.
198        $this->drupalVariableSet('bio_profile', 1);
199        $this->drupalVariableSet('bio_takeover', 1);
200    
201        // Create bio for basic user.
202        $this->drupalLoginUser($this->basic_user);
203        $this->bioCreateBio();
204    
205        // Ensure that on user profile, there's no remnants of the 'default'
206        // profile stuff.
207        $this->drupalGet('user');
208        $this->assertNoText(t('Member for'), t('Checking for profile takeover'));
209      }
210    
211      /**
212       * Test "bio link" setting.
213       */
214      function testBioLink() {
215        // Enable bio links on stories.
216        $this->drupalVariableSet('bio_link', array('story' => 1));
217    
218        // Login as basic user and create bio.
219        $this->drupalLoginUser($this->basic_user);
220        $bio = $this->bioCreateBio();
221    
222        // Create a story. Confirm link appears.
223        $edit['title'] = $this->randomName(32);
224        $edit['body'] = $this->randomName(32);
225        $this->drupalPostRequest('node/add/story', $edit, t('Submit'));
226        $node = node_load(array('title' => $edit['title']));
227        $this->drupalGet("node/$node->nid");
228        $this->assertText(t('by @user', array('@user' => $this->basic_user->name)), t('Checking for bio link when it should appear'));
229    
230        // Create a page. Confirm link does not appear.
231        $edit['title'] = $this->randomName(32);
232        $edit['body'] = $this->randomName(32);
233        $this->drupalPostRequest('node/add/page', $edit, t('Submit'));
234        $node = node_load(array('title' => $edit['title']));
235        $this->drupalGet("node/$node->nid");
236        $this->assertNoUnwantedRaw(t('by @user', array('@user' => $this->basic_user->name)), t('Checking for bio link when it should not appear'));
237      }
238    
239      /**
240       * Perform various tests related to the bio content type.
241       *
242       * @todo Fill in stub function.
243       */
244      function testBioContentType() {
245      }
246    
247      /**
248       * Perform various tets related to showing fields on registration form.
249       *
250       * @todo Fill in stub function.
251       */
252      function testBioRegistrationFormFields() {
253      }
254    
255      /**
256       * Perform various tets related to Views integration.
257       *
258       * @todo Fill in stub function.
259       */
260      function testBioViewsIntegration() {
261      }
262    
263      /**
264       * Perform various tets related to Panels integration.
265       *
266       * @todo Fill in stub function.
267       */
268      function testBioPanelsIntegration() {
269      }
270    
271      /**
272       * Create a biography for a given user.
273       *
274       * @param $uid
275       *   Optional; specify the user for whom to create the bio.
276       */
277      function bioCreateBio($account = NULL) {
278        $edit = array();
279        if ($account) {
280          $edit['name'] = $account->name;
281        }
282        $edit['title'] = $this->randomName(32);
283        $edit['body'] = $this->randomName(32);
284        $this->drupalPostRequest('node/add/bio', $edit, t('Submit'));
285        return node_load(array('title' => $edit['title']));
286      }
287    }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.2