You are here

function SecureSiteTest::testFilterCheck in Secure Site 6

Same name and namespace in other branches
  1. 5 tests/securesite.test \SecureSiteTest::testFilterCheck()

Tests for _securesite_filter_check()

TODO: Add result explanations TODO: Verify correctness of test #11

File

tests/securesite.test, line 575
Secure Site module unit tests

Class

SecureSiteTest
Unit tests for the Secure Site module

Code

function testFilterCheck() {
  $home = variable_get('site_frontpage', 'node');

  // Disable Secure Site, as the init() stuff can get in the way
  $this
    ->drupalVariableSet('securesite_enabled', SECURESITE_DISABLED);

  // Test #1: Basic Whitelist
  $this
    ->drupalVariableSet('securesite_filter_pages_type', SECURESITE_WHITELIST);
  $this
    ->drupalVariableSet('securesite_filter_pages', 'node');
  $this
    ->assertTrue(_securesite_filter_check('node'), t('Filter Check Test #1') . ': %s');

  // Test #2: Basic Blacklist
  $this
    ->drupalVariableSet('securesite_filter_pages_type', SECURESITE_BLACKLIST);
  $this
    ->assertFalse(_securesite_filter_check('node'), t('Filter Check Test #2') . ': %s');

  // Test #3: Empty Whitelist
  $this
    ->drupalVariableSet('securesite_filter_pages_type', SECURESITE_WHITELIST);
  $this
    ->drupalVariableSet('securesite_filter_pages', '');
  $this
    ->assertFalse(_securesite_filter_check($home), t('Filter Check Test #3') . ': %s');

  // Test #4: Empty Blacklist
  $this
    ->drupalVariableSet('securesite_filter_pages_type', SECURESITE_BLACKLIST);
  $this
    ->assertTrue(_securesite_filter_check($home), t('Filter Check Test #4') . ': %s');

  // Test #5: NULL Whitelist
  $this
    ->drupalVariableSet('securesite_filter_pages_type', SECURESITE_WHITELIST);
  $this
    ->drupalVariableSet('securesite_filter_pages', NULL);
  $this
    ->assertFalse(_securesite_filter_check($home), t('Filter Check Test #5') . ': %s');

  // Test #6: NULL Blacklist
  $this
    ->drupalVariableSet('securesite_filter_pages_type', SECURESITE_BLACKLIST);
  $this
    ->assertTrue(_securesite_filter_check($home), t('Filter Check Test #6') . ': %s');

  // Test #7: <front> Whitelist
  $this
    ->drupalVariableSet('securesite_filter_pages_type', SECURESITE_WHITELIST);
  $this
    ->drupalVariableSet('securesite_filter_pages', '<front>');
  $this
    ->assertTrue(_securesite_filter_check($home), t('Filter Check Test #7') . ': %s');

  // Test #8: <front> Blacklist
  $this
    ->drupalVariableSet('securesite_filter_pages_type', SECURESITE_BLACKLIST);
  $this
    ->assertFalse(_securesite_filter_check($home), t('Filter Check Test #8') . ': %s');

  // Test #9: Empty Path
  $this
    ->drupalVariableSet('securesite_filter_pages_type', SECURESITE_WHITELIST);
  $this
    ->drupalVariableSet('securesite_filter_pages', '');
  $this
    ->assertFalse(_securesite_filter_check(''), t('Filter Check Test #9') . ': %s');

  // Test #10: NULL Path
  $this
    ->drupalVariableSet('securesite_filter_pages_type', SECURESITE_BLACKLIST);
  $this
    ->drupalVariableSet('securesite_filter_pages', '');
  $this
    ->assertFalse(_securesite_filter_check(NULL), t('Filter Check Test #10') . ': %s');

  // Test #11: <front> is the same as no path
  $this
    ->drupalVariableSet('securesite_filter_pages_type', SECURESITE_BLACKLIST);
  $this
    ->drupalVariableSet('securesite_filter_pages', '<front>');
  $this
    ->assertFalse(_securesite_filter_check(''), t('Filter Check Test #11') . ': %s');
}