You are here

it_cookie_compliance.test in IT Cookie Compliance 7

IT Cookie Compliance module test file.

File

it_cookie_compliance.test
View source
<?php

/**
 * @file
 * IT Cookie Compliance module test file.
 */

/**
 * Tests the functionality of the Simpletest example content type.
 */
class ItCookieComplianceTestCase extends DrupalWebTestCase {

  /**
   * Override getInfo.
   */
  public static function getInfo() {
    return array(
      'name' => 'IT Cookie Compliance preemptive blocking',
      'description' => 'Ensure that blocks and javascripts are blocked as designed.',
      'group' => 'IT Cookie Compliance',
    );
  }

  /**
   * Override setUp.
   */
  public function setUp() {
    parent::setUp(array(
      'it_cookie_compliance',
    ));

    // Set block to /misc/jquery.once.js and misc/drupal.js
    variable_set('it_cookie_compliance_javascript', 'jquery');

    // Set block to block-system-main
    variable_set('it_cookie_compliance_blocks', 'main');
  }

  /**
   * Tests whether javascripts are been blocked correctly.
   */
  public function testJavascriptBlocking() {
    $this
      ->drupalGet('node');
    $this
      ->assertNoRaw('jquery.once.js', 'Checking if jquery javascript has been removed');
    $this
      ->assertRaw('drupal.js', 'Checking if drupal javascript has not been removed');

    // Set block to /misc/jquery.once.js and misc/drupal.js
    variable_set('it_cookie_compliance_javascript', 'jquery,drupal');
    $this
      ->drupalGet('');
    $this
      ->assertNoRaw('drupal.js', 'Checking if drupal javascript has been removed after adding it to options');
  }

  /**
   * Tests whether blocks are been blocked correctly.
   */
  public function testBlockBlocking() {
    $this
      ->drupalGet('');
    $this
      ->assertNoRaw('block-system-main', 'Checking if main block has been removed');
    variable_set('it_cookie_compliance_blocks', '');
    $this
      ->drupalGet('');
    $this
      ->assertRaw('block-system-main', 'Checking if main block has not been removed when option is not set');
  }

  /**
   * Tests that nothing is blocked after cookies have been accepted.
   */
  public function testAfterCookie() {
    $this
      ->drupalGet('', array(), array(
      "Cookie: cookie-agreed=2",
    ));
    $this
      ->assertRaw('block-system-main', 'Checking if main block has not been removed with cookies accepted');
    $this
      ->assertRaw('jquery.once.js', 'Checking if jquery javascript has not been removed with cookies accepted');
  }

}

Classes

Namesort descending Description
ItCookieComplianceTestCase Tests the functionality of the Simpletest example content type.