function BirthdaysTestCase::testDeleteOption in Birthdays 6
Test the delete permission and its effects in the profile.
File
- ./
birthdays.test, line 57 - Tests for the Birthdays module.
Class
- BirthdaysTestCase
- @file Tests for the Birthdays module.
Code
function testDeleteOption() {
$this
->drupalLogin($this->web_user);
// Try to insert empty birthday, while required.
$this
->drupalPost('user/' . $this->web_user->uid . '/edit/' . $this->field->category, array(), t('Save'));
$this
->assertText($this->field->title . ' field is required.', t('Birthday field is required.'));
// Set birthday of user.
$birthday = array(
$this->field->name . '[month]' => 3,
$this->field->name . '[day]' => 23,
$this->field->name . '[year]' => 1980,
);
$this
->drupalPost('user/' . $this->web_user->uid . '/edit/' . $this->field->category, $birthday, t('Save'));
// Confirm that birthday is set correctly.
$this
->drupalGet('user/' . $this->web_user->uid);
$this
->assertText('03/23/1980', t('Birthday has been set.'));
// Try to delete birthday.
$birthday = array(
$this->field->name . '[month]' => '',
$this->field->name . '[day]' => '',
$this->field->name . '[year]' => '',
);
$this
->drupalPost('user/' . $this->web_user->uid . '/edit/' . $this->field->category, $birthday, t('Save'));
// Confirm deletion is not possible.
$this
->assertText($this->field->title . ' field is required.', t('Birthday deletion prevented.'));
// Set birthdays field optional, thus making deletion possible.
db_query('UPDATE {profile_fields} SET required = 0 WHERE fid = %d', $this->field->fid);
// Confirm deletion is possible.
$this
->drupalPost('user/' . $this->web_user->uid . '/edit/' . $this->field->category, $birthday, t('Save'));
$this
->assertNoText($this->field->title . ' field is required.', t('Birthday deletion allowed.'));
// Confirm birthday is deleted (not displayed on profile page).
$this
->drupalGet('user/' . $this->web_user->uid);
$this
->assertNoText($this->field->title, t('Birthday has been set.'));
}