-
Notifications
You must be signed in to change notification settings - Fork 1
/
mathjax.test
117 lines (102 loc) · 3.97 KB
/
mathjax.test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
/**
* @file
* Web test file for MathJax module.
*/
/**
* Web test case for the module.
*/
class MathjaxWebTestCase extends BackdropWebTestCase {
/**
* 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->backdropCreateUser(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->backdropGet($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->backdropLogin($this->administrator);
$this->backdropGet('admin/config/content/mathjax');
$this->assertTitle('MathJax | Backdrop', '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({
extensions: ['tex2jax.js'],
jax: ['input/TeX','output/HTML-CSS'],
tex2jax: {
inlineMath: [ ['$','$'], ['\\\\(','\\\\)'] ],
processEscapes: true
}
});";
$path = 'admin/config/content/mathjax';
$edit = array(
'mathjax_config_type' => 1,
'mathjax_config_string' => $custom,
);
$this->backdropPost($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->backdropLogin($this->administrator);
$this->backdropGet('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->backdropGet('admin/config/content/mathjax');
$edit = array(
'mathjax_use_cdn' => FALSE,
);
$this->backdropPost(NULL, $edit, t('Save configuration'));
$this->backdropGet('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->backdropLogin($this->administrator);
// Activate the MathJax filter on the filtered_html text format.
$this->backdropGet('admin/config/content/formats/filtered_html');
$edit = array('filters[filter_mathjax][status]' => TRUE);
$this->backdropPost(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');
}
}