| Server IP : 195.130.67.5 / Your IP : 216.73.217.154 Web Server : Microsoft-IIS/10.0 System : Windows NT WEBSERVER1 10.0 build 17763 (Windows Server 2016) i586 User : IUSR ( 0) PHP Version : 7.4.19 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/inetpub/wwwroot/business/sites/all/modules/ctools/tests/ |
Upload File : |
<?php
/**
* Tests the simple MathExpressionStack class.
*/
class CtoolsMathExpressionStackTestCase extends DrupalWebTestCase {
/**
* {@inheritdoc}
*/
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'),
);
}
/**
* {@inheritdoc}
*/
public function setUp(array $modules = array()) {
$modules[] = 'ctools';
$modules[] = 'ctools_plugin_test';
parent::setUp($modules);
}
/**
* Test the math expression stack system.
*/
public function testStack() {
$stack = new ctools_math_expr_stack();
// Test the empty stack.
$this->assertNull($stack->last());
$this->assertNull($stack->pop());
// Add an element and see whether it's the right element.
$value = $this->randomName();
$stack->push($value);
$this->assertIdentical($value, $stack->last());
$this->assertIdentical($value, $stack->pop());
$this->assertNull($stack->pop());
// Add multiple elements and see whether they are returned in the right
// order.
$values = array($this->randomName(), $this->randomName(), $this->randomName());
foreach ($values as $value) {
$stack->push($value);
}
// Test the different elements at different positions with the last()
// method.
$count = count($values);
foreach ($values as $key => $value) {
$this->assertEqual($value, $stack->last($count - $key));
}
// Pass in a non-valid number to last.
$non_valid_number = rand(10, 20);
$this->assertNull($stack->last($non_valid_number));
// Test the order of the poping.
$values = array_reverse($values);
foreach ($values as $key => $value) {
$this->assertEqual($stack->last(), $value);
$this->assertEqual($stack->pop(), $value);
}
$this->assertNull($stack->pop());
}
}