You are here

public function BirthdaysBirthdayTestCase::testFromArray in Birthdays 7

Tests conversion from array.

File

./birthdays.test, line 53
Unit tests for the Birthdays module.

Class

BirthdaysBirthdayTestCase
Unit tests for the BirthdaysBirthday class.

Code

public function testFromArray() {
  $this
    ->assertIdentical(BirthdaysBirthday::fromArray(array(
    'month' => 0,
    'day' => 0,
  ))
    ->toString(), '');
  date_default_timezone_set('UTC');
  $this
    ->assertIdentical(BirthdaysBirthday::fromArray(array(
    'year' => 1970,
    'day' => 1,
    'month' => 1,
  ))
    ->toUnixtime(), 0);
  $this
    ->assertEqual(BirthdaysBirthday::fromArray(array(
    'month' => 3,
    'day' => 7,
  ))
    ->toArray(), array(
    'month' => 3,
    'day' => 7,
    'year' => 0,
  ));
  try {
    BirthdaysBirthday::fromArray(array(
      'foo' => 'bar',
    ));
    $this
      ->fail(t('Exception expected.'));
  } catch (InvalidArgumentException $e) {
    $this
      ->pass($e
      ->getMessage());
  }
  try {
    BirthdaysBirthday::fromArray(NULL);
    $this
      ->fail(t('Exception expected.'));
  } catch (InvalidArgumentException $e) {
    $this
      ->pass($e
      ->getMessage());
  }
}