You are here

public function SmsFrameworkIncomingBrowserTest::testIncomingRouteEndpoint in SMS Framework 8

Same name and namespace in other branches
  1. 2.x tests/src/Functional/SmsFrameworkIncomingBrowserTest.php \Drupal\Tests\sms\Functional\SmsFrameworkIncomingBrowserTest::testIncomingRouteEndpoint()
  2. 2.1.x tests/src/Functional/SmsFrameworkIncomingBrowserTest.php \Drupal\Tests\sms\Functional\SmsFrameworkIncomingBrowserTest::testIncomingRouteEndpoint()

Test incoming route endpoint provided by 'incoming' gateway.

File

tests/src/Functional/SmsFrameworkIncomingBrowserTest.php, line 45

Class

SmsFrameworkIncomingBrowserTest
Tests incoming route endpoint.

Namespace

Drupal\Tests\sms\Functional

Code

public function testIncomingRouteEndpoint() {
  $messages[0] = [
    'message' => $this
      ->randomString(),
    'recipients' => $this
      ->randomPhoneNumbers(),
  ];
  $messages[1] = [
    'message' => $this
      ->randomString(),
    'recipients' => $this
      ->randomPhoneNumbers(),
  ];
  $url = Url::fromRoute('sms.incoming.receive.' . $this->incomingGateway
    ->id())
    ->setRouteParameter('sms_gateway', $this->incomingGateway
    ->id())
    ->setAbsolute()
    ->toString();
  $options = [
    'json' => [
      'messages' => $messages,
    ],
  ];
  $this
    ->assertTrue(TRUE, sprintf('POST request to %s', $url));
  $response = $this->httpClient
    ->post($url, $options);
  $this
    ->assertEquals(204, $response
    ->getStatusCode(), 'HTTP code is 204');
  $this
    ->assertEmpty((string) $response
    ->getBody(), 'Response body is empty.');
  $incoming_messages = $this
    ->getIncomingMessages($this->incomingGateway);
  $this
    ->assertEquals(count($messages), count($incoming_messages), 'There are 2 messages');
  foreach ($messages as $i => $message) {
    $this
      ->assertEquals($message['message'], $incoming_messages[$i]
      ->getMessage(), "Message {$i} contents are same.");
    $this
      ->assertEquals($message['recipients'], $incoming_messages[$i]
      ->getRecipients(), "Message {$i} recipients are same.");
  }
}