You are here

public function SmsDevelMessageTest::testDate in SMS Framework 2.x

Same name and namespace in other branches
  1. 8 modules/sms_devel/tests/src/Functional/SmsDevelMessageTest.php \Drupal\Tests\sms_devel\Functional\SmsDevelMessageTest::testDate()
  2. 2.1.x modules/sms_devel/tests/src/Functional/SmsDevelMessageTest.php \Drupal\Tests\sms_devel\Functional\SmsDevelMessageTest::testDate()

Tests adding send date.

File

modules/sms_devel/tests/src/Functional/SmsDevelMessageTest.php, line 145

Class

SmsDevelMessageTest
Tests the message form.

Namespace

Drupal\Tests\sms_devel\Functional

Code

public function testDate() {
  $edit['number'] = $this
    ->randomPhoneNumbers(1)[0];
  $edit['message'] = $this
    ->randomString();
  $edit['skip_queue'] = FALSE;
  $value = '2005-11-25 22:03:58';
  $date = new DrupalDateTime($value, 'UTC');

  // The user inputs field values in its own timezone, then it is auto
  // converted on field submission to UTC.
  $date_user = $date;
  $date_user
    ->setTimezone(new \DateTimeZone(date_default_timezone_get()));
  $edit['send_on[date]'] = $date_user
    ->format('Y-m-d');
  $edit['send_on[time]'] = $date_user
    ->format('H:i:s');
  $this
    ->drupalPostForm(Url::fromRoute('sms_devel.message'), $edit, t('Send'));
  $messages = SmsMessage::loadMultiple();
  $message = reset($messages);
  $this
    ->assertEquals($date
    ->format('U'), $message
    ->getSendTime(), 'Message has send time.');
}