You are here

mathjax.test in MathJax: LaTeX for Drupal 7.2

Web test file for MathJax module.

File

mathjax.test
View source
<?php

/**
 * @file
 * Web test file for MathJax module.
 */

/**
 * Web test case for the module.
 */
class MathjaxWebTestCase extends DrupalWebTestCase {

  /**
   * Provide info on these tests to the admin interface.
   */
  public static function getInfo() {
    return array(
      'name' => 'MathJax tests',
      'description' => 'Tests the default configuration and admin functions.',
      'group' => 'MathJax',
    );
  }

  /**
   * Set up the test evironment.
   */
  protected function setUp() {
    parent::setUp('mathjax');
    $this->administrator = $this
      ->drupalCreateUser(array(
      'administer mathjax',
      'access site reports',
      'access administration pages',
      'administer site configuration',
      'administer filters',
    ));
  }

  /**
   * Test the default configuration.
   */
  public function testDefaults() {
    $path = '<front>';

    // Initial text on form load.
    $this
      ->drupalGet($path);
    $this
      ->assertRaw(mathjax_default('cdn url'), 'Default CDN URL found.');
    $this
      ->assertRaw('<script type="text/x-mathjax-config">' . mathjax_default('config string') . '</script>', 'Default configuration string found.');
  }

  /**
   * Test the administration functions.
   */
  public function testAdmin() {
    $this
      ->drupalLogin($this->administrator);
    $this
      ->drupalGet('admin/config/content/mathjax');
    $this
      ->assertTitle('MathJax | Drupal', 'Page title set.');
    $this
      ->assertText('MathJax CDN URL');
    $this
      ->assertFieldByName('mathjax_cdn_url', mathjax_default('cdn url'), 'Default CDN config string found.');
    $this
      ->assertText('Enter the Mathjax CDN url here or leave it unchanged to use the one provided by www.mathjax.org.');
    $this
      ->assertText('Configuration Type');
    $this
      ->assertFieldByName('mathjax_config_type', 0);
    $custom = "MathJax.Hub.Config({\n      extensions: ['tex2jax.js'],\n      jax: ['input/TeX','output/HTML-CSS'],\n      tex2jax: {\n        inlineMath: [ ['\$','\$'], ['\\\\(','\\\\)'] ],\n        processEscapes: true\n      }\n    });";
    $path = 'admin/config/content/mathjax';
    $edit = array(
      'mathjax_config_type' => 1,
      'mathjax_config_string' => $custom,
    );
    $this
      ->drupalPost($path, $edit, t('Save configuration'));
    $this
      ->assertText('Enter a JavaScript configuration string as documented');
    $this
      ->assertRaw('<script type="text/x-mathjax-config">' . $custom . '</script>', 'Custom configuration string found.');
  }

  /**
   * Tests the detection of MathJax libraries.
   */
  public function testLibraryDetection() {
    $this
      ->drupalLogin($this->administrator);
    $this
      ->drupalGet('admin/reports/status');
    $this
      ->assertNoText('MathJax is configured to use local library files but the libraries module is not enabled. See the README.');
    $this
      ->assertNoText('MathJax is configured to use local library files but they could not be found. See the README.');
    $this
      ->drupalGet('admin/config/content/mathjax');
    $edit = array(
      'mathjax_use_cdn' => FALSE,
    );
    $this
      ->drupalPost(NULL, $edit, t('Save configuration'));
    $this
      ->drupalGet('admin/reports/status');
    $this
      ->assertText('MathJax is configured to use local library files but the libraries module is not enabled. See the README.');
    $this
      ->assertText('MathJax is configured to use local library files but they could not be found. See the README.');
  }

  /**
   * Ensure the MathJax filter is at the bottom of the processing order.
   */
  public function testFilterOrder() {
    $this
      ->drupalLogin($this->administrator);

    // Activate the MathJax filter on the filtered_html text format.
    $this
      ->drupalGet('admin/config/content/formats/filtered_html');
    $edit = array(
      'filters[filter_mathjax][status]' => TRUE,
    );
    $this
      ->drupalPost(NULL, $edit, t('Save configuration'));

    // Ensure that MathJax appears at the bottom of the filter list.
    $result = $this
      ->xpath("//table[@id='filter-order']/tbody/tr[last()]/td[1]");
    $this
      ->assertEqual($result[0]
      ->__toString(), 'MathJax');
  }

}

Classes

Namesort descending Description
MathjaxWebTestCase Web test case for the module.