You are here

image_allow_insecure_derivatives.test in Image Allow Insecure Derivatives 7

Tests for the Image Allow Insecure Derivatives module.

File

image_allow_insecure_derivatives.test
View source
<?php

/**
 * @file
 * Tests for the Image Allow Insecure Derivatives module.
 */

/**
 * Provides tests for the Image Allow Insecure Derivatives module.
 */
class ImageAllowInsecureDerivativesTestCase extends DrupalWebTestCase {

  /**
   * Provides the information of the tests.
   */
  public static function getInfo() {
    return array(
      'name' => 'Image Allow Insecure Derivatives',
      'description' => 'Perform various tests with the Image Allow Insecure Derivatives module.',
      'group' => 'Image',
    );
  }

  /**
   * Provides the set up tasks for the tests.
   */
  function setUp() {
    parent::setUp('image_allow_insecure_derivatives');
  }

  /**
   * Makes sure the default setting is enabled.
   */
  function testDefaultSetting() {
    $setting = variable_get('image_allow_insecure_derivatives', FALSE);
    $this
      ->assertTrue($setting, 'The default setting is TRUE.');
  }

  /**
   * Tests uninstalling the module.
   */
  function testUinstallModule() {
    drupal_uninstall_modules(array(
      'image_allow_insecure_derivatives',
    ));
    $setting = variable_get('image_allow_insecure_derivatives', FALSE);
    $this
      ->assertFalse($setting, 'Uninstalling the module removes the setting.');
  }

  /**
   * Tests the settings page.
   */
  function testSettings() {
    $admin_user = $this
      ->drupalCreateUser(array(
      'administer site configuration',
    ));
    $this
      ->drupalLogin($admin_user);

    // Disable the setting.
    $this
      ->drupalPost('admin/config/media/image-toolkit', array(
      'image_allow_insecure_derivatives' => FALSE,
    ), t('Save configuration'));
    $this
      ->assertText(t('The configuration options have been saved.'));
    $this
      ->drupalGet('admin/config/media/image-toolkit');
    if ($this
      ->parse()) {
      $field = $this
        ->xpath('//input[@name=:name]', array(
        ':name' => 'image_allow_insecure_derivatives',
      ));
      $this
        ->assertFalse(isset($field[0]['checked']), 'Image Allow Insecure Derivatives can be disabled.');
    }

    // Enable the setting.
    $this
      ->drupalPost('admin/config/media/image-toolkit', array(
      'image_allow_insecure_derivatives' => TRUE,
    ), t('Save configuration'));
    $this
      ->assertText(t('The configuration options have been saved.'));
    $this
      ->drupalGet('admin/config/media/image-toolkit');
    if ($this
      ->parse()) {
      $field = $this
        ->xpath('//input[@name=:name]', array(
        ':name' => 'image_allow_insecure_derivatives',
      ));
      $this
        ->assertTrue(isset($field[0]['checked']), 'Image Allow Insecure Derivatives can be enabled.');
    }
  }

  /**
   * Tests the requirements page.
   */
  function testRequirements() {
    $admin_user = $this
      ->drupalCreateUser(array(
      'administer site configuration',
    ));
    $this
      ->drupalLogin($admin_user);

    // Retrieve the status report page when enabled.
    $this
      ->drupalGet('admin/reports/status');
    $this
      ->assertText(t('Image Allow Insecure Derivatives'), 'Image Allow Insecure Derivatives is displayed on the status report page when enabled.');
    $this
      ->assertText(t('Allowing insecure image derivates can cause security instabilities. Only use this if you are experiencing image display issues, and understand the security risks.'), 'The correct status is shown when enabled.');

    // Disable the setting and re-check the page.
    variable_set('image_allow_insecure_derivatives', FALSE);
    $this
      ->drupalGet('admin/reports/status');
    $this
      ->assertText(t('Image Allow Insecure Derivatives'), 'Image Allow Insecure Derivatives is displayed on the status report page when disabled.');
    $this
      ->assertNoText(t('Allowing insecure image derivates can cause security instabilities. Only use this if you are experiencing image display issues, and understand the security risks.'), 'The correct status is shown when disabled.');
  }

}

Classes

Namesort descending Description
ImageAllowInsecureDerivativesTestCase Provides tests for the Image Allow Insecure Derivatives module.