You are here

public function QuoteSettingsFormTest::testSettingsSaving in Quote 8.2

Tests settings save.

File

tests/src/Functional/QuoteSettingsFormTest.php, line 76

Class

QuoteSettingsFormTest
Tests settings form.

Namespace

Drupal\Tests\quote\Functional

Code

public function testSettingsSaving() {
  $types = [
    'page',
    'article',
  ];
  foreach ($types as $type_id) {
    $this
      ->drupalCreateContentType([
      'type' => $type_id,
    ]);
  }
  $this
    ->drupalLogin($this->user);
  $this
    ->drupalGet($this->settingsRoute);
  $expected_values = $edit = [
    'quote_modes_quote_sel' => random_int(0, 1),
    'quote_modes_quote_all' => random_int(0, 1),
    'quote_modes_quote_reply_all' => random_int(0, 1),
    'quote_modes_quote_reply_sel' => random_int(0, 1),
    'quote_allow_comments' => random_int(0, 1),
    'quote_selector' => $this
      ->randomString(),
    'quote_limit' => random_int(1, 999),
    'quote_selector_comment_quote_all' => $this
      ->randomString(),
    'quote_selector_node_quote_all' => $this
      ->randomString(),
  ];
  $allowed_types = array_slice($types, 0, random_int(0, 1));
  foreach ($allowed_types as $type_id) {
    $edit['quote_allow_types[' . $type_id . ']'] = $type_id;
    $expected_values['quote_allow_types'][$type_id] = $type_id;
  }
  $this
    ->drupalPostForm(NULL, $edit, t('Save configuration'));
  foreach ($expected_values as $field => $expected_value) {
    $actual_value = $this
      ->config('quote.settings')
      ->get($field);
    $this
      ->assertEquals($expected_value, $actual_value);
  }
}