You are here

public function WebhooksTest::testHeaders in Webhooks 8

Test webhook headers.

File

tests/src/Functional/WebhooksTest.php, line 233

Class

WebhooksTest
Test description.

Namespace

Drupal\Tests\webhooks\Functional

Code

public function testHeaders() {
  $webhook_config = WebhookConfig::load(self::WEBHOOK_ID_OUTGOING);
  $webhook = new Webhook($this->payload, $this->headers);
  $this->webhookService
    ->send($webhook_config, $webhook);

  /** @var \Drupal\webhooks\Webhook $webhook_received */
  $webhook_received = $this->state
    ->get('onWebhookReceive_webhook');
  $headers_received = $webhook_received
    ->getHeaders();

  // Additional custom headers.
  $intersection = array_intersect($headers_received, $this->headers);
  $this
    ->assertEqual($intersection, $this->headers);

  // Check for X-Drupal-Delivery header.
  $this
    ->assertEqual($headers_received['x-drupal-delivery'], $webhook
    ->getUuid());

  // Check for X-Drupal-Event header.
  $this
    ->assertEqual($headers_received['x-drupal-event'], $webhook
    ->getEvent());
}