Révision 7e72b748
Ajouté par Assos Assos il y a plus de 6 ans
drupal7/sites/all/modules/ctools/tests/math_expression.test | ||
---|---|---|
1 | 1 |
<?php |
2 | 2 |
|
3 |
/** |
|
4 |
* @file |
|
5 |
* Contains \CtoolsMathExpressionTestCase. |
|
6 |
*/ |
|
7 |
|
|
8 | 3 |
/** |
9 | 4 |
* Tests the MathExpression library of ctools. |
10 | 5 |
*/ |
11 | 6 |
class CtoolsMathExpressionTestCase extends DrupalWebTestCase { |
7 |
|
|
8 |
/** |
|
9 |
* {@inheritDoc} |
|
10 |
*/ |
|
12 | 11 |
public static function getInfo() { |
13 | 12 |
return array( |
14 |
'name' => 'CTools math expression tests',
|
|
13 |
'name' => 'Math expressions',
|
|
15 | 14 |
'description' => 'Test the math expression library of ctools.', |
16 | 15 |
'group' => 'ctools', |
16 |
'dependencies' => array('ctools'), |
|
17 | 17 |
); |
18 | 18 |
} |
19 | 19 |
|
20 |
public function setUp() { |
|
21 |
parent::setUp('ctools', 'ctools_plugin_test'); |
|
20 |
/** |
|
21 |
* {@inheritDoc} |
|
22 |
*/ |
|
23 |
function setUp(array $modules = array()) { |
|
24 |
$modules[] = 'ctools'; |
|
25 |
$modules[] = 'ctools_plugin_test'; |
|
26 |
parent::setUp($modules); |
|
22 | 27 |
} |
23 | 28 |
|
24 | 29 |
/** |
... | ... | |
35 | 40 |
return $this->assert(abs($first - $second) <= $delta, $message ? $message : t('Value @first is equal to value @second.', array('@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE))), $group); |
36 | 41 |
} |
37 | 42 |
|
43 |
/** |
|
44 |
* Test some arithmetic handling. |
|
45 |
*/ |
|
38 | 46 |
public function testArithmetic() { |
39 | 47 |
$math_expression = new ctools_math_expr(); |
40 | 48 |
|
... | ... | |
66 | 74 |
$this->assertEqual(pow($random_number_a, $random_number_b), $math_expression->e("$random_number_a ^ $random_number_b")); |
67 | 75 |
} |
68 | 76 |
|
77 |
/** |
|
78 |
* Test the basic built-in functions in the math expression library. |
|
79 |
*/ |
|
69 | 80 |
public function testBuildInFunctions() { |
70 | 81 |
$math_expression = new ctools_math_expr(); |
71 | 82 |
|
72 |
// @todo: maybe run this code multiple times to test different values.
|
|
83 |
// @todo Maybe run this code multiple times to test different values.
|
|
73 | 84 |
$random_double = $this->rand01(); |
74 | 85 |
$random_int = rand(5, 10); |
75 | 86 |
$this->assertFloat(sin($random_double), $math_expression->e("sin($random_double)")); |
... | ... | |
94 | 105 |
// $this->assertFloat(min($random_double_a, $random_double_b), $math_expression->e("min($random_double_a, $random_double_b)")); |
95 | 106 |
} |
96 | 107 |
|
108 |
/** |
|
109 |
* Test variable handling. |
|
110 |
*/ |
|
97 | 111 |
public function testVariables() { |
98 | 112 |
$math_expression = new ctools_math_expr(); |
99 | 113 |
|
... | ... | |
108 | 122 |
$this->assertEqual($random_number_a / $random_number_b, $math_expression->e("var / $random_number_b")); |
109 | 123 |
} |
110 | 124 |
|
125 |
/** |
|
126 |
* Test custom function handling. |
|
127 |
*/ |
|
111 | 128 |
public function testCustomFunctions() { |
112 | 129 |
$math_expression = new ctools_math_expr(); |
113 | 130 |
|
... | ... | |
126 | 143 |
// Use a custom function in another function. |
127 | 144 |
$this->assertEqual(($random_number_a * 2 + $random_number_b) * 2, $math_expression->e("f(g($random_number_a, $random_number_b))")); |
128 | 145 |
} |
146 |
|
|
129 | 147 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules