1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Contains \CtoolsMathExpressionStackTestCase
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Tests the simple MathExpressionStack class.
|
10 |
|
|
*/
|
11 |
|
|
class CtoolsMathExpressionStackTestCase extends DrupalWebTestCase {
|
12 |
|
|
public static function getInfo() {
|
13 |
|
|
return array(
|
14 |
|
|
'name' => 'CTools math expression stack tests',
|
15 |
|
|
'description' => 'Test the stack class of the math expression library.',
|
16 |
|
|
'group' => 'Chaos Tools Suite',
|
17 |
|
|
);
|
18 |
|
|
}
|
19 |
|
|
|
20 |
|
|
public function setUp() {
|
21 |
|
|
parent::setUp('ctools', 'ctools_plugin_test');
|
22 |
|
|
}
|
23 |
|
|
|
24 |
|
|
public function testStack() {
|
25 |
|
|
$stack = new ctools_math_expr_stack();
|
26 |
|
|
|
27 |
|
|
// Test the empty stack.
|
28 |
|
|
$this->assertNull($stack->last());
|
29 |
|
|
$this->assertNull($stack->pop());
|
30 |
|
|
|
31 |
|
|
// Add an element and see whether it's the right element.
|
32 |
|
|
$value = $this->randomName();
|
33 |
|
|
$stack->push($value);
|
34 |
|
|
$this->assertIdentical($value, $stack->last());
|
35 |
|
|
$this->assertIdentical($value, $stack->pop());
|
36 |
|
|
$this->assertNull($stack->pop());
|
37 |
|
|
|
38 |
|
|
// Add multiple elements and see whether they are returned in the right order.
|
39 |
|
|
$values = array($this->randomName(), $this->randomName(), $this->randomName());
|
40 |
|
|
foreach ($values as $value) {
|
41 |
|
|
$stack->push($value);
|
42 |
|
|
}
|
43 |
|
|
|
44 |
|
|
// Test the different elements at different positions with the last() method.
|
45 |
|
|
$count = count($values);
|
46 |
|
|
foreach ($values as $key => $value) {
|
47 |
|
|
$this->assertEqual($value, $stack->last($count - $key));
|
48 |
|
|
}
|
49 |
|
|
|
50 |
|
|
// Pass in a non-valid number to last.
|
51 |
|
|
$non_valid_number = rand(10, 20);
|
52 |
|
|
$this->assertNull($stack->last($non_valid_number));
|
53 |
|
|
|
54 |
|
|
// Test the order of the poping.
|
55 |
|
|
$values = array_reverse($values);
|
56 |
|
|
foreach ($values as $key => $value) {
|
57 |
|
|
$this->assertEqual($stack->last(), $value);
|
58 |
|
|
$this->assertEqual($stack->pop(), $value);
|
59 |
|
|
}
|
60 |
|
|
$this->assertNull($stack->pop());
|
61 |
|
|
|
62 |
|
|
}
|
63 |
|
|
} |