function ContactUpdateTest::testPostUpdateContactFormFields

Tests contact_form updates.

See also

contact_post_update_add_message_redirect_field_to_contact_form()

File

core/modules/contact/tests/src/Functional/Update/ContactUpdateTest.php, line 29

Class

ContactUpdateTest
Tests contact update path.

Namespace

Drupal\Tests\contact\Functional\Update

Code

public function testPostUpdateContactFormFields() {
  // Check that contact_form does not have fields redirect and message.
  $config_factory = \Drupal::configFactory();
  // Check that contact_form entities are more than zero.
  $contact_forms = $config_factory->listAll('contact.form.');
  $this->assertGreaterThan(0, count($contact_forms), 'There are contact forms to update.');
  foreach ($contact_forms as $contact_config_name) {
    $contact_form_data = $config_factory->get($contact_config_name)
      ->get();
    $this->assertFalse(isset($contact_form_data['message']), 'Prior to running the update the "message" key does not exist.');
    $this->assertFalse(isset($contact_form_data['redirect']), 'Prior to running the update the "redirect" key does not exist.');
  }
  // Run updates.
  $this->runUpdates();
  // Check that the contact_form entities have been updated.
  foreach ($contact_forms as $contact_config_name) {
    $contact_form_data = $config_factory->get($contact_config_name)
      ->get();
    $this->assertTrue(isset($contact_form_data['message']), 'After running the update the "message" key exists.');
    $this->assertEqual('Your message has been sent.', $contact_form_data['message']);
    $this->assertTrue(isset($contact_form_data['redirect']), 'After running the update the "redirect" key exists.');
    $this->assertEqual('', $contact_form_data['redirect']);
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.