math_expression_stack.test in Chaos Tool Suite (ctools) 7
File
tests/math_expression_stack.test
View source
<?php
class CtoolsMathExpressionStackTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Math expressions stack',
'description' => 'Test the stack class of the math expression library.',
'group' => 'ctools',
'dependencies' => array(
'ctools',
),
);
}
public function setUp(array $modules = array()) {
$modules[] = 'ctools';
$modules[] = 'ctools_plugin_test';
parent::setUp($modules);
}
public function testStack() {
$stack = new ctools_math_expr_stack();
$this
->assertNull($stack
->last());
$this
->assertNull($stack
->pop());
$value = $this
->randomName();
$stack
->push($value);
$this
->assertIdentical($value, $stack
->last());
$this
->assertIdentical($value, $stack
->pop());
$this
->assertNull($stack
->pop());
$values = array(
$this
->randomName(),
$this
->randomName(),
$this
->randomName(),
);
foreach ($values as $value) {
$stack
->push($value);
}
$count = count($values);
foreach ($values as $key => $value) {
$this
->assertEqual($value, $stack
->last($count - $key));
}
$non_valid_number = rand(10, 20);
$this
->assertNull($stack
->last($non_valid_number));
$values = array_reverse($values);
foreach ($values as $key => $value) {
$this
->assertEqual($stack
->last(), $value);
$this
->assertEqual($stack
->pop(), $value);
}
$this
->assertNull($stack
->pop());
}
}