You are here

public function ContactSitewideTest::deleteContactForms in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/contact/tests/src/Functional/ContactSitewideTest.php \Drupal\Tests\contact\Functional\ContactSitewideTest::deleteContactForms()
  2. 9 core/modules/contact/tests/src/Functional/ContactSitewideTest.php \Drupal\Tests\contact\Functional\ContactSitewideTest::deleteContactForms()

Deletes all forms.

File

core/modules/contact/tests/src/Functional/ContactSitewideTest.php, line 603

Class

ContactSitewideTest
Tests site-wide contact form functionality.

Namespace

Drupal\Tests\contact\Functional

Code

public function deleteContactForms() {
  $contact_forms = ContactForm::loadMultiple();
  foreach ($contact_forms as $id => $contact_form) {
    if ($id == 'personal') {

      // Personal form could not be deleted.
      $this
        ->drupalGet("admin/structure/contact/manage/{$id}/delete");
      $this
        ->assertSession()
        ->statusCodeEquals(403);
    }
    else {
      $this
        ->drupalGet("admin/structure/contact/manage/{$id}/delete");
      $this
        ->submitForm([], 'Delete');
      $this
        ->assertSession()
        ->pageTextContains("The contact form {$contact_form->label()} has been deleted.");
      $this
        ->assertNull(ContactForm::load($id), new FormattableMarkup('Form %contact_form not found', [
        '%contact_form' => $contact_form
          ->label(),
      ]));
    }
  }
}