You are here

public function SmsFrameworkGatewayAdminTest::testGatewayEdit in SMS Framework 2.1.x

Same name and namespace in other branches
  1. 8 tests/src/Functional/SmsFrameworkGatewayAdminTest.php \Drupal\Tests\sms\Functional\SmsFrameworkGatewayAdminTest::testGatewayEdit()
  2. 2.x tests/src/Functional/SmsFrameworkGatewayAdminTest.php \Drupal\Tests\sms\Functional\SmsFrameworkGatewayAdminTest::testGatewayEdit()

Tests configuring a gateway.

Ensures gateway plugin custom configuration form is shown, and new configuration is saved to the config entity.

File

tests/src/Functional/SmsFrameworkGatewayAdminTest.php, line 121

Class

SmsFrameworkGatewayAdminTest
Tests gateway administration user interface.

Namespace

Drupal\Tests\sms\Functional

Code

public function testGatewayEdit() {
  $this
    ->drupalLogin($this
    ->drupalCreateUser([
    'administer smsframework',
  ]));
  $test_gateway = $this
    ->createMemoryGateway();
  $this
    ->drupalGet(Url::fromRoute('entity.sms_gateway.edit_form', [
    'sms_gateway' => $test_gateway
      ->id(),
  ]));
  $this
    ->assertResponse(200);
  $this
    ->assertFieldByName('widget');
  $this
    ->assertNoFieldChecked('edit-skip-queue');
  $this
    ->assertFieldByName('retention_duration_incoming', '0');
  $this
    ->assertFieldByName('retention_duration_outgoing', '0');

  // Memory gateway supports pushed reports, so the URL should display.
  $this
    ->assertFieldByName('delivery_reports[push_path]', $test_gateway
    ->getPushReportPath());

  // Memory gateway has a decoy configuration form.
  $edit = [
    'widget' => $this
      ->randomString(),
    'skip_queue' => '1',
    'retention_duration_incoming' => '3600',
    'retention_duration_outgoing' => '-1',
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'Save');
  $this
    ->assertUrl(Url::fromRoute('sms.gateway.list'));
  $this
    ->assertResponse(200);
  $this
    ->assertRaw('Gateway saved.');

  // Reload the gateway, check configuration saved to config entity.

  /** @var \Drupal\sms\Entity\SmsGatewayInterface $test_gateway */
  $test_gateway = $this->smsGatewayStorage
    ->load($test_gateway
    ->id());

  // Gateway settings.
  $this
    ->assertEqual(TRUE, $test_gateway
    ->getSkipQueue());
  $this
    ->assertEqual($edit['retention_duration_incoming'], $test_gateway
    ->getRetentionDuration(Direction::INCOMING));
  $this
    ->assertEqual($edit['retention_duration_outgoing'], $test_gateway
    ->getRetentionDuration(Direction::OUTGOING));

  // Plugin form.
  $config = $test_gateway
    ->getPlugin()
    ->getConfiguration();
  $this
    ->assertEqual($edit['widget'], $config['widget'], 'Plugin configuration changed.');
}