You are here

public function SmsDevelMessageTest::testVerboseReports in SMS Framework 8

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

Tests verbose message output.

File

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

Class

SmsDevelMessageTest
Tests the message form.

Namespace

Drupal\Tests\sms_devel\Functional

Code

public function testVerboseReports() {
  $edit['gateway'] = $this->gateway
    ->id();
  $edit['number'] = $this
    ->randomPhoneNumbers(1)[0];
  $edit['message'] = $this
    ->randomString();
  $edit['skip_queue'] = TRUE;
  $edit['verbose'] = TRUE;
  $this
    ->drupalPostForm(Url::fromRoute('sms_devel.message'), $edit, t('Send'));
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->responseContains('Message was processed, 1 delivery reports were generated.');
  $first_row = '#edit-results > tbody > tr:nth-child(1)';

  // Result.
  $selector = $first_row . ' > td:nth-child(1)';
  $this
    ->assertSession()
    ->elementTextContains('css', $selector, '#0');

  // Error.
  $selector = $first_row . ' > td:nth-child(2)';
  $this
    ->assertSession()
    ->elementTextContains('css', $selector, 'Success');

  // Error Message.
  $selector = $first_row . ' > td:nth-child(3)';
  $this
    ->assertSession()
    ->elementTextContains('css', $selector, 'Undefined');

  // Credits Used.
  $selector = $first_row . ' > td:nth-child(4)';
  $this
    ->assertSession()
    ->elementTextContains('css', $selector, 'Undefined');

  // Credits Balance.
  $selector = $first_row . ' > td:nth-child(5)';
  $this
    ->assertSession()
    ->elementTextContains('css', $selector, 'Undefined');
  $message = $this
    ->getLastTestMessage($this->gateway);
  $report = $this
    ->getTestMessageReports($this->gateway)[0];
  $this
    ->assertEquals($edit['number'], $report
    ->getRecipient());
  $first_row_first_report = '#edit-results > tbody > tr:nth-child(2) > td > table > tbody > tr:nth-child(1)';

  // Recipient.
  $selector = $first_row_first_report . ' > td:nth-child(1)';
  $this
    ->assertSession()
    ->elementTextContains('css', $selector, $report
    ->getRecipient());

  // Message ID.
  $selector = $first_row_first_report . ' > td:nth-child(2)';
  $this
    ->assertSession()
    ->elementTextContains('css', $selector, $report
    ->getMessageId());

  // Status.
  $selector = $first_row_first_report . ' > td:nth-child(3)';
  $this
    ->assertSession()
    ->elementTextContains('css', $selector, $report
    ->getStatus());

  // Status Message.
  $selector = $first_row_first_report . ' > td:nth-child(4)';
  $this
    ->assertSession()
    ->elementTextContains('css', $selector, $report
    ->getStatusMessage());

  // Time Delivered.
  $date = DrupalDateTime::createFromTimestamp($report
    ->getTimeDelivered());
  $selector = $first_row_first_report . ' > td:nth-child(5)';
  $this
    ->assertSession()
    ->elementTextContains('css', $selector, $date
    ->format('c'));

  // Time Queued.
  $date = DrupalDateTime::createFromTimestamp($report
    ->getTimeQueued());
  $selector = $first_row_first_report . ' > td:nth-child(6)';
  $this
    ->assertSession()
    ->elementTextContains('css', $selector, $date
    ->format('c'));
}