You are here

protected function WebhooksTest::setUp in Webhooks 8

Overrides BrowserTestBase::setUp

File

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

Class

WebhooksTest
Test description.

Namespace

Drupal\Tests\webhooks\Functional

Code

protected function setUp() : void {
  parent::setUp();
  $this->state = $this->container
    ->get('state');
  $this->uuid = $this->container
    ->get('uuid');
  $this->webhookService = $this->container
    ->get('webhooks.service');

  // Create an incoming webhook.
  WebhookConfig::create([
    'id' => self::WEBHOOK_ID_INCOMING,
    'label' => 'Webhook Incoming',
    'uuid' => $this->uuid
      ->generate(),
    'payload_url' => '',
    'type' => 'incoming',
    'events' => [],
    'content_type' => WebhookConfig::CONTENT_TYPE_JSON,
    'secret' => '',
    'status' => 1,
  ])
    ->save();

  // Create an outgoing webhook.
  WebhookConfig::create([
    'id' => self::WEBHOOK_ID_OUTGOING,
    'label' => 'Webhook Outgoing',
    'uuid' => $this->uuid
      ->generate(),
    'payload_url' => Url::fromRoute('webhooks.webhook_receive', [
      'incoming_webhook_name' => self::WEBHOOK_ID_INCOMING,
    ])
      ->setAbsolute(TRUE)
      ->toString(),
    'type' => 'outgoing',
    'events' => [],
    'content_type' => WebhookConfig::CONTENT_TYPE_JSON,
    'secret' => '',
    'status' => 1,
  ])
    ->save();

  // Create an incoming webhook.
  WebhookConfig::create([
    'id' => self::WEBHOOK_ID_INCOMING_VERIFIED,
    'label' => 'Webhook Incoming Verified',
    'uuid' => $this->uuid
      ->generate(),
    'payload_url' => '',
    'type' => 'incoming',
    'events' => [],
    'content_type' => WebhookConfig::CONTENT_TYPE_JSON,
    'secret' => self::WEBHOOK_SECRET,
    'status' => 1,
  ])
    ->save();

  // Create an outgoing webhook.
  WebhookConfig::create([
    'id' => self::WEBHOOK_ID_OUTGOING_VERIFIED,
    'label' => 'Webhook Outgoing Verified',
    'uuid' => $this->uuid
      ->generate(),
    'payload_url' => Url::fromRoute('webhooks.webhook_receive', [
      'incoming_webhook_name' => self::WEBHOOK_ID_INCOMING_VERIFIED,
    ])
      ->setAbsolute(TRUE)
      ->toString(),
    'type' => 'outgoing',
    'events' => [],
    'content_type' => WebhookConfig::CONTENT_TYPE_JSON,
    'secret' => self::WEBHOOK_SECRET,
    'status' => 1,
  ])
    ->save();

  // Create an incoming webhook.
  WebhookConfig::create([
    'id' => self::WEBHOOK_ID_INCOMING_XML,
    'label' => 'Webhook Incoming XML',
    'uuid' => $this->uuid
      ->generate(),
    'payload_url' => '',
    'type' => 'incoming',
    'events' => [],
    'content_type' => WebhookConfig::CONTENT_TYPE_XML,
    'secret' => '',
    'status' => 1,
  ])
    ->save();

  // Create an outgoing webhook.
  WebhookConfig::create([
    'id' => self::WEBHOOK_ID_OUTGOING_XML,
    'label' => 'Webhook Outgoing XML',
    'uuid' => $this->uuid
      ->generate(),
    'payload_url' => Url::fromRoute('webhooks.webhook_receive', [
      'incoming_webhook_name' => self::WEBHOOK_ID_INCOMING_XML,
    ])
      ->setAbsolute(TRUE)
      ->toString(),
    'type' => 'outgoing',
    'events' => [],
    'content_type' => WebhookConfig::CONTENT_TYPE_XML,
    'secret' => '',
    'status' => 1,
  ])
    ->save();
}