You are here

public function SettingsTest::testAdminSettingsForm in Acquia Lift Connector 8.4

File

tests/src/Functional/SettingsTest.php, line 88

Class

SettingsTest
Test Acquia Lift Settings.

Namespace

Drupal\Tests\acquia_lift\Functional

Code

public function testAdminSettingsForm() {

  // Check for setting page's presence.
  $this
    ->drupalGet('admin/config/services/acquia-lift');
  $this
    ->assertRaw(t('Acquia Lift Settings'), '[testAdminSettingsForm]: Settings page displayed.');

  // Get all the valid settings, and massage them into form $edit array.
  $credential_settings = $this
    ->getValidCredentialSettings();
  $identity_settings = $this
    ->getValidIdentitySettings();
  $field_mappings_settings = $this
    ->getValidFieldMappingsSettings();
  $udf_person_settings = $this
    ->getValidUdfPersonMappingsFormData();
  $udf_touch_settings = $this
    ->getValidUdfTouchMappingsFormData();
  $udf_event_settings = $this
    ->getValidUdfEventMappingsFormData();
  $visibility_settings = $this
    ->getValidVisibilitySettings();
  $advanced_settings = $this
    ->getValidAdvancedSettings();
  $edit = [];
  $edit += $this
    ->convertToPostFormSettings($credential_settings, 'credential');
  $edit += $this
    ->convertToPostFormSettings($identity_settings, 'identity');
  $edit += $this
    ->convertToPostFormSettings($field_mappings_settings, 'field_mappings');
  $edit += $this
    ->convertToPostFormSettings($udf_person_settings, 'udf_person_mappings');
  $edit += $this
    ->convertToPostFormSettings($udf_touch_settings, 'udf_touch_mappings');
  $edit += $this
    ->convertToPostFormSettings($udf_event_settings, 'udf_event_mappings');
  $edit += $this
    ->convertToPostFormSettings($visibility_settings, 'visibility');
  $edit += $this
    ->convertToPostFormSettings($advanced_settings, 'advanced');
  $edit_settings_count = count($edit);
  $expect_settings_count = 21;

  // Post the edits.
  $this
    ->drupalPostForm('admin/config/services/acquia-lift', $edit, new TranslatableMarkup('Save configuration'));

  // Assert error messages are set for required fields and unreachable URLs.
  $this
    ->assertText(t('The Acquia Lift module requires a valid Account ID, Site ID, and Assets URL to complete activation.'));
  $this
    ->assertText(t('Acquia Lift module could not reach the specified Assets URL.'));
  $this
    ->assertText(t('Acquia Lift module could not reach the specified Decision API URL.'));

  // Assert all other fields. Also count the asserted fields to make sure all are asserted.
  foreach ($edit as $name => $value) {
    $this
      ->assertFieldByName($name, $value, new FormattableMarkup('"@name" setting was saved into DB.', [
      '@name' => $name,
    ]));
  }
  $this
    ->assertEqual($expect_settings_count, $edit_settings_count, 'The exact numbers of settings that were asserted should be ' . $expect_settings_count . '.');

  // Assert metatags are loaded in the header.
  $this
    ->drupalGet('node/90210');
}