You are here

public function BlockListOverrideTest::testBlockListConfigForm in Block List Override 1.0.x

Tests the config form.

File

tests/src/Functional/BlockListOverrideTest.php, line 105

Class

BlockListOverrideTest
Tests for the Block List Override module.

Namespace

Drupal\Tests\block_list_override\Functional

Code

public function testBlockListConfigForm() {

  // Login.
  $this
    ->drupalLogin($this->user);

  // Access config page.
  $this
    ->drupalGet('admin/config/block_list_override/settings');
  $this
    ->assertResponse(200);

  // Test the form elements exist and have default values.
  $config = $this
    ->config('block_list_override.settings');
  foreach (self::$replace as $field => $opt) {
    $this
      ->assertFieldByName($field, $config
      ->get('block_list_override.settings.' . $field), $field . ' field has the default value');
  }

  // Test form submission.
  $edit = [];
  foreach (self::$replace as $field => $opt) {
    $edit[$field] = $opt['rule'];
  }
  $edit['system_negate'] = 0;
  $edit['layout_negate'] = 0;
  $this
    ->drupalPostForm(NULL, $edit, t('Save configuration'));
  $this
    ->assertText('The configuration options have been saved.', 'The form was saved correctly.');

  // Test the new values are there.
  $this
    ->drupalGet('admin/config/block_list_override/settings');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  foreach (self::$replace as $field => $opt) {
    $string = strtr('//*[@name=":field_name"]', [
      ':field_name' => $field,
    ]);
    $elements = $this
      ->xpath($string);
    $value = count($elements) ? $elements[0]
      ->getValue() : NULL;
    $this
      ->assertEquals($value, $opt['rule']);
  }

  // Test block list results.
  $pages = [
    'system' => 'admin/config/block_list_override/system-list',
    'layout' => 'admin/config/block_list_override/layout-list',
  ];
  foreach ($pages as $type => $page) {
    $this
      ->drupalGet($page);

    //sleep(30);
    $this
      ->assertSession()
      ->statusCodeEquals(200);
    foreach (self::$replace as $field => $opt) {
      switch ($field) {
        case $type . '_match':
        case $type . '_prefix':
        case $type . '_regex':
          $this
            ->assertNoText($opt['hides'], $opt['label'] . ' block was not displayed .');
          break;
      }
    }
  }
  $this
    ->drupalLogout();
}