You are here

public function LoggingConfigFormTest::testSubmitForm in Purge 8.3

@covers \Drupal\purge_ui\Form\LoggingConfigForm::submitForm

File

modules/purge_ui/tests/src/Functional/Form/LoggingConfigFormTest.php, line 123

Class

LoggingConfigFormTest
Tests \Drupal\purge_ui\Form\LoggingConfigForm.

Namespace

Drupal\Tests\purge_ui\Functional\Form

Code

public function testSubmitForm() : void {
  $form = $this
    ->formInstance()
    ->buildForm([], $this
    ->getFormStateInstance());

  // Verify that the returned $has_resulted_in_changes is FALSE without data.
  $this
    ->assertSame(FALSE, $this
    ->formInstance()
    ->submitForm($form, $this
    ->getFormStateInstance()));

  // Verify that non-existent channels don't lead to saving anything.
  $submitted = $this
    ->getFormStateInstance();
  $submitted
    ->setValue('table', [
    'fake' => [
      "1",
    ],
  ]);
  $this
    ->assertSame(FALSE, $this
    ->formInstance()
    ->submitForm($form, $submitted));

  // Verify that correct data does lead to a write.
  $this->purgeLogger
    ->expects($this
    ->once())
    ->method('setChannel')
    ->with($this
    ->equalTo('testchannel'), $this
    ->equalTo([
    0,
    1,
  ]));
  $submitted = $this
    ->getFormStateInstance();
  $submitted
    ->setValue('table', [
    'testchannel' => [
      "1",
      "1",
      "0",
      0,
    ],
  ]);
  $this
    ->assertSame(TRUE, $this
    ->formInstance()
    ->submitForm($form, $submitted));
}