You are here

public function SettingsTest::testAdminSettingsForm in Acquia Lift Connector 8

Same name and namespace in other branches
  1. 8.3 src/Tests/SettingsTest.php \Drupal\acquia_lift\Tests\SettingsTest::testAdminSettingsForm()

File

src/Tests/SettingsTest.php, line 84
Contains \Drupal\acquia_lift\Tests\SettingsTest.

Class

SettingsTest
Test Acquia Lift Settings.

Namespace

Drupal\acquia_lift\Tests

Code

public function testAdminSettingsForm() {

  // Check for setting page's presence.
  $this
    ->drupalGet('admin/config/content/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();
  $visibility_settings = $this
    ->getValidVisibilitySettings();
  $edit = [];
  $edit += $this
    ->convertToPostFormSettings($credential_settings, 'credential');
  $edit += $this
    ->convertToPostFormSettings($identity_settings, 'identity');
  $edit += $this
    ->convertToPostFormSettings($field_mappings_settings, 'field_mappings');
  $edit += $this
    ->convertToPostFormSettings($visibility_settings, 'visibility');
  $edit_settings_count = count($edit);
  $expect_settings_count = 13;

  // Post the edits and assert that options are saved.
  $this
    ->drupalPostForm('admin/config/content/acquia_lift', $edit, t('Save configuration'));
  $this
    ->assertText(t('The configuration options have been saved.'));
  $this
    ->assertNoRaw('acquia_lift.js', '[testJavaScriptAndDrupalSettings]: acquia_lift.js is not loaded on the page, as visibility.path_patterns says should not attach.');

  // The saved secret key should not be shown.
  $actual_secret_key = $this
    ->config('acquia_lift.settings')
    ->get('credential.secret_key');
  $this
    ->assertEqual($edit['credential[secret_key]'], $actual_secret_key, 'Credential\'s secret key was saved into DB.');
  $edit['credential[secret_key]'] = '';
  $this
    ->assertText('Only necessary if updating');

  // Assert all other fields. Also count the asserted fields to make sure all are asserted.
  foreach ($edit as $name => $value) {
    $this
      ->assertFieldByName($name, $value, format_string('"@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 the Thumbnail URL shortcut links exist on the page.
  $this
    ->assertRaw('admin/structure/types/manage/article#edit-acquia-lift', '[testAdminSettingsForm]: Thumbnail URL shortcut links exist on the page.');

  // Assert the node type thumbnail form is actually loaded at the node type configuration page.
  $this
    ->drupalGet('admin/structure/types/manage/article');
  $this
    ->assertText(t('Acquia Lift'));
}