You are here

public function HttpPurgerConfigFormTestBase::testSaveConfigurationSubmit in Generic HTTP Purger 8

Test posting data to the HTTP Purger settings form.

Overrides PluginConfigFormTestBase::testSaveConfigurationSubmit

File

tests/src/Functional/HttpPurgerConfigFormTestBase.php, line 143

Class

HttpPurgerConfigFormTestBase
Testbase for testing \Drupal\purge_purger_http\Form\HttpPurgerFormBase.

Namespace

Drupal\Tests\purge_purger_http\Functional

Code

public function testSaveConfigurationSubmit() : void {

  // Assert that all (simple) fields submit as intended.
  $this
    ->drupalLogin($this->adminUser);
  $edit = [
    'name' => 'foobar',
    'invalidationtype' => 'wildcardurl',
    'hostname' => 'example.com',
    'port' => 8080,
    'path' => 'node/1',
    'request_method' => 1,
    'scheme' => 0,
    'verify' => TRUE,
    'show_body_form' => 1,
    'body_content_type' => 'foo/bar',
    'body' => 'baz',
    'timeout' => 6,
    'runtime_measurement' => 1,
    'connect_timeout' => 0.5,
    'cooldown_time' => 0.8,
    'max_requests' => 25,
    'http_errors' => 1,
  ];
  $this
    ->drupalPostForm($this
    ->getPath(), $edit, 'Save configuration');
  $this
    ->drupalGet($this
    ->getPath());
  foreach ($edit as $field => $value) {
    $this
      ->assertSession()
      ->fieldValueEquals('edit-' . str_replace('_', '-', $field), $value);
  }

  // Assert headers behavior.
  $form = $this
    ->getFormInstance();
  $form_state = $this
    ->getFormStateInstance();
  $form_state
    ->addBuildInfo('args', $this->formArgs);
  $form_state
    ->setValue('headers', [
    [
      'field' => 'foo',
      'value' => 'bar',
    ],
  ]);
  $this
    ->formBuilder()
    ->submitForm($form, $form_state);
  $this
    ->assertEquals(0, count($form_state
    ->getErrors()));
  $this
    ->drupalGet($this
    ->getPath());
  $this
    ->assertSession()
    ->fieldValueEquals('edit-headers-0-field', 'foo');
  $this
    ->assertSession()
    ->fieldValueEquals('edit-headers-0-value', 'bar');
}