/[drupal]/contributions/modules/birthdays/birthdays.test
ViewVC logotype

Contents of /contributions/modules/birthdays/birthdays.test

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


Revision 1.3 - (show annotations) (download) (as text)
Tue Sep 30 22:42:00 2008 UTC (13 months, 4 weeks ago) by maartenvg
Branch: MAIN
CVS Tags: DRUPAL-6--1-0, DRUPAL-6--1-0-RC1, HEAD
Branch point for: DRUPAL-6--1
Changes since 1.2: +24 -27 lines
File MIME type: text/x-php
#305113: Improved validation and 'required' status of the\nbirthdays field by introducing (defaulted) empty day, year and month fields.\nBecause of this, the 'delete birthday' permission and checkbox could be dropped.
1 <?php
2 // $Id: birthdays.test,v 1.2 2008/09/30 15:11:23 maartenvg Exp $
3 /**
4 * @file
5 * Tests for the Birthdays module.
6 */
7
8 class BirthdaysTestCase extends DrupalWebTestCase {
9 protected $admin_user;
10 protected $web_user;
11 protected $field;
12 /**
13 * Implementation of getInfo().
14 */
15 function getInfo() {
16 return array(
17 'name' => t('Birthdays module'),
18 'description' => t('Test all major and minor functions of the birthdays module.'),
19 'group' => t('Birthdays'),
20 );
21 }
22
23 /**
24 * Implementation of setUp().
25 */
26 function setUp() {
27 parent::setUp('birthdays', 'profile');
28
29 // Create users.
30 $this->admin_user = $this->drupalCreateUser(array('administer site configuration', 'access administration pages', 'administer users', 'administer permissions', 'access birthdays'));
31 $this->web_user = $this->drupalCreateUser(array('access birthdays'));
32 $this->drupalLogin($this->admin_user);
33
34 // Add profile field.
35 $field = array(
36 'category' => $this->randomName(8),
37 'title' => $this->randomName(8),
38 'name' => 'profile_'. $this->randomName(8),
39 'required' => 1,
40 );
41 $this->drupalPost('admin/user/profile/add/date', $field, t('Save field'));
42
43 // Get profile field ID.
44 $fid = db_result(db_query("SELECT fid FROM {profile_fields} WHERE name = '%s'", $field['name']));
45 // Set profile field as birthdays field.
46 $this->drupalPost('admin/settings/birthdays', array('birthdays_field_id' => $fid), t('Save configuration'));
47
48 // Confirm that the field_id has been set
49 $this->assertEqual(variable_get('birthdays_field_id', NULL), $fid, t('Birthdays field has been set successfully'));
50 $this->field = _birthdays_get_field(variable_get('birthdays_field_id', NULL));
51
52 $this->drupalLogout();
53 }
54
55 /**
56 * Test the delete permission and its effects in the profile.
57 */
58 function testDeleteOption() {
59 $this->drupalLogin($this->web_user);
60
61 // Try to insert empty birthday, while required.
62 $this->drupalPost('user/'. $this->web_user->uid .'/edit/'. $this->field->category, array(), t('Save'));
63 $this->assertText($this->field->title .' field is required.', t('Birthday field is required.'));
64
65 // Set birthday of user.
66 $birthday = array(
67 $this->field->name .'[month]' => 3,
68 $this->field->name .'[day]' => 23,
69 $this->field->name .'[year]' => 1980,
70 );
71 $this->drupalPost('user/'. $this->web_user->uid .'/edit/'. $this->field->category, $birthday, t('Save'));
72
73 // Confirm that birthday is set correctly.
74 $this->drupalGet('user/'. $this->web_user->uid);
75 $this->assertText('03/23/1980', t('Birthday has been set.'));
76
77 // Try to delete birthday.
78 $birthday = array(
79 $this->field->name .'[month]' => '',
80 $this->field->name .'[day]' => '',
81 $this->field->name .'[year]' => '',
82 );
83 $this->drupalPost('user/'. $this->web_user->uid .'/edit/'. $this->field->category, $birthday, t('Save'));
84
85 // Confirm deletion is not possible.
86 $this->assertText($this->field->title .' field is required.', t('Birthday deletion prevented.'));
87
88 // Set birthdays field optional, thus making deletion possible.
89 db_query('UPDATE {profile_fields} SET required = 0 WHERE fid = %d', $this->field->fid);
90
91 // Confirm deletion is possible.
92 $this->drupalPost('user/'. $this->web_user->uid .'/edit/'. $this->field->category, $birthday, t('Save'));
93 $this->assertNoText($this->field->title .' field is required.', t('Birthday deletion allowed.'));
94
95 // Confirm birthday is deleted (not displayed on profile page).
96 $this->drupalGet('user/'. $this->web_user->uid);
97 $this->assertNoText($this->field->title, t('Birthday has been set.'));
98 }
99
100 /**
101 * Test the year of birth visibility options.
102 */
103 function testHideYearOption() {
104 $this->drupalLogin($this->web_user);
105
106 // Set birthday of user.
107 $birthday = array(
108 $this->field->name .'[month]' => 3,
109 $this->field->name .'[day]' => 23,
110 $this->field->name .'[year]' => 1980,
111 );
112 $age = _birthdays_calculate_age(23, 3, 1980);
113 $this->drupalPost('user/'. $this->web_user->uid .'/edit/'. $this->field->category, $birthday, t('Save'));
114
115 // Confirm there is no checkbox "Hide age and birth year", it's the default
116 $this->drupalGet('user/'. $this->web_user->uid .'/edit/'. $this->field->category);
117 $this->assertNoField('birthdays_user_hide_year', '"Hide age and birth year" option not present.');
118
119 // Globally hide year of birth and age.
120 variable_set('birthdays_hide_year', BIRTHDAYS_HIDE_YEAR_YES);
121
122 // Confirm age and year are hidden, but the date of birth isn't.
123 $this->drupalGet('user');
124 $this->assertText('03/23', 'Date of birth visible.');
125 $this->assertNoText('1980', 'Year hidden.');
126 $this->assertNoText('('. $age .')', 'Age hidden.');
127
128 // Set hiding year of birth and age as user option.
129 variable_set('birthdays_hide_year', BIRTHDAYS_HIDE_YEAR_USER);
130 // Confirm age and year are not hidden.
131 $this->drupalGet('user');
132 $this->assertText('1980', 'Year not hidden.');
133 $this->assertText('('. $age .')', 'Age not hidden.');
134
135 // Hide year of birth and age for this user.
136 $this->drupalPost('user/'. $this->web_user->uid .'/edit/'. $this->field->category, array('birthdays_user_hide_year' => BIRTHDAYS_HIDE_YEAR_USER_YES), t('Save'));
137
138 // Confirm age and year are hidden, but the date of birth isn't.
139 $this->drupalGet('user');
140 $this->assertText('03/23', 'Date of birth visible.');
141 $this->assertNoText('1980', 'Year of birth hidden.');
142 $this->assertNoText('('. $age .')', 'Age hidden.');
143 }
144
145 /**
146 * Test the starsigns visibility options.
147 */
148 function testStarsigns() {
149 $this->drupalLogin($this->web_user);
150
151 // Set birthday of user.
152 $birthday = array(
153 $this->field->name .'[month]' => 3,
154 $this->field->name .'[day]' => 23,
155 $this->field->name .'[year]' => 1980,
156 );
157 $this->drupalPost('user/'. $this->web_user->uid .'/edit/'. $this->field->category, $birthday, t('Save'));
158
159 // Confirm absense of starsign.
160 $this->drupalGet('user');
161 $this->assertNoText('aries', 'Starsign is not displayed.');
162
163 // Set starsigns to visible, without link.
164 variable_set('birthdays_show_starsign', BIRTHDAYS_STARSIGN_NOLINK);
165
166 // Confirm presence of starsign, but absense of link.
167 $this->drupalGet('user');
168 $this->assertRaw('<span class="birthdays-starsign"><img src="'. base_path() . drupal_get_path('module', 'birthdays') .'/starsigns/aries.gif" alt="aries" /></span>', 'Starsign is displayed without link.');
169
170 // Set starsigns to visible, with link.
171 variable_set('birthdays_show_starsign', BIRTHDAYS_STARSIGN_LINK);
172
173 // Confirm presence of starsign, with link.
174 $this->drupalGet('user');
175 $this->assertRaw('<span class="birthdays-starsign"><a href="http://astrology.yahoo.com/astrology/general/dailyoverview/aries" target="_blank" title="aries"><img src="'. base_path() . drupal_get_path('module', 'birthdays') .'/starsigns/aries.gif" alt="aries" /></a></span>', 'Starsign is displayed with link.');
176 }
177
178 }

  ViewVC Help
Powered by ViewVC 1.1.2