You are here

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

Tests the negated system config form.

We have to test system and layout separately since the system settings will affect the layout blocks.

File

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

Class

BlockListOverrideTest
Tests for the Block List Override module.

Namespace

Drupal\Tests\block_list_override\Functional

Code

public function testBlockListConfigFormNegatedSystem() {
  $type = 'system';

  // 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) {
    if (strpos($field, $type) !== NULL) {
      $edit[$field] = $opt['rule'];
    }
    else {
      $edit[$field] = '';
    }
  }
  $edit['system_negate'] = 1;
  $this
    ->drupalPostForm(NULL, $edit, t('Save configuration'));
  $this
    ->assertText('The configuration options have been saved.', 'The form was saved correctly.');

  // Test block list results.
  $page = 'admin/config/block_list_override/' . $type . '-list';
  $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
          ->assertText($opt['hides'], $opt['label'] . ' block was displayed .');
        break;
    }
  }
  $this
    ->drupalLogout();
}