You are here

function BirthdaysTestCase::testHideYearOption in Birthdays 6

Test the year of birth visibility options.

File

./birthdays.test, line 102
Tests for the Birthdays module.

Class

BirthdaysTestCase
@file Tests for the Birthdays module.

Code

function testHideYearOption() {
  $this
    ->drupalLogin($this->web_user);

  // Set birthday of user.
  $birthday = array(
    $this->field->name . '[month]' => 3,
    $this->field->name . '[day]' => 23,
    $this->field->name . '[year]' => 1980,
  );
  $age = _birthdays_calculate_age(23, 3, 1980);
  $this
    ->drupalPost('user/' . $this->web_user->uid . '/edit/' . $this->field->category, $birthday, t('Save'));

  // Confirm there is no checkbox "Hide age and birth year", it's the default
  $this
    ->drupalGet('user/' . $this->web_user->uid . '/edit/' . $this->field->category);
  $this
    ->assertNoField('birthdays_user_hide_year', '"Hide age and birth year" option not present.');

  // Globally hide year of birth and age.
  variable_set('birthdays_hide_year', BIRTHDAYS_HIDE_YEAR_YES);

  // Confirm age and year are hidden, but the date of birth isn't.
  $this
    ->drupalGet('user');
  $this
    ->assertText('03/23', 'Date of birth visible.');
  $this
    ->assertNoText('1980', 'Year hidden.');
  $this
    ->assertNoText('(' . $age . ')', 'Age hidden.');

  // Set hiding year of birth and age as user option.
  variable_set('birthdays_hide_year', BIRTHDAYS_HIDE_YEAR_USER);

  // Confirm age and year are not hidden.
  $this
    ->drupalGet('user');
  $this
    ->assertText('1980', 'Year not hidden.');
  $this
    ->assertText('(' . $age . ')', 'Age not hidden.');

  // Hide year of birth and age for this user.
  $this
    ->drupalPost('user/' . $this->web_user->uid . '/edit/' . $this->field->category, array(
    'birthdays_user_hide_year' => BIRTHDAYS_HIDE_YEAR_USER_YES,
  ), t('Save'));

  // Confirm age and year are hidden, but the date of birth isn't.
  $this
    ->drupalGet('user');
  $this
    ->assertText('03/23', 'Date of birth visible.');
  $this
    ->assertNoText('1980', 'Year of birth hidden.');
  $this
    ->assertNoText('(' . $age . ')', 'Age hidden.');
}