security update core+modules
This commit is contained in:
48
sites/all/modules/ctools/tests/css_cache.test
Normal file
48
sites/all/modules/ctools/tests/css_cache.test
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Tests the custom CSS cache handler.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests the custom CSS cache handler.
|
||||
*/
|
||||
class CtoolsObjectCache extends DrupalWebTestCase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Ctools CSS cache',
|
||||
'description' => 'Tests the custom CSS cache handler.',
|
||||
'group' => 'Chaos Tools Suite',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp('ctools');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the custom CSS cache handler.
|
||||
*
|
||||
* @see https://drupal.org/node/1313368
|
||||
*/
|
||||
public function testCssCache() {
|
||||
// Create a CSS cache entry.
|
||||
$filename = ctools_css_cache('body { color: red; }');
|
||||
|
||||
// Perform a cron run. The CSS cache entry should not be removed.
|
||||
$this->cronRun();
|
||||
$this->assertTrue(file_exists($filename), 'The CSS cache is not cleared after performing a cron run.');
|
||||
|
||||
// Manually clear the caches. The CSS cache entry should be removed.
|
||||
drupal_flush_all_caches();
|
||||
$this->assertFalse(file_exists($filename), 'The CSS cache is cleared after clearing all caches.');
|
||||
}
|
||||
|
||||
}
|
@@ -2,14 +2,15 @@ name = CTools export test
|
||||
description = CTools export test module
|
||||
core = 7.x
|
||||
package = Chaos tool suite
|
||||
version = CTOOLS_MODULE_VERSION
|
||||
dependencies[] = ctools
|
||||
hidden = TRUE
|
||||
|
||||
files[] = ctools_export.test
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-02-02
|
||||
version = "7.x-1.2+31-dev"
|
||||
; Information added by Drupal.org packaging script on 2015-03-18
|
||||
version = "7.x-1.7"
|
||||
core = "7.x"
|
||||
project = "ctools"
|
||||
datestamp = "1359766341"
|
||||
datestamp = "1426696183"
|
||||
|
||||
|
@@ -1,17 +1,20 @@
|
||||
name = Chaos tools plugins test
|
||||
description = Provides hooks for testing ctools plugins.
|
||||
package = Chaos tool suite
|
||||
version = CTOOLS_MODULE_VERSION
|
||||
core = 7.x
|
||||
dependencies[] = ctools
|
||||
files[] = ctools.plugins.test
|
||||
files[] = object_cache.test
|
||||
files[] = css.test
|
||||
files[] = context.test
|
||||
files[] = math_expression.test
|
||||
files[] = math_expression_stack.test
|
||||
hidden = TRUE
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-02-02
|
||||
version = "7.x-1.2+31-dev"
|
||||
; Information added by Drupal.org packaging script on 2015-03-18
|
||||
version = "7.x-1.7"
|
||||
core = "7.x"
|
||||
project = "ctools"
|
||||
datestamp = "1359766341"
|
||||
datestamp = "1426696183"
|
||||
|
||||
|
129
sites/all/modules/ctools/tests/math_expression.test
Normal file
129
sites/all/modules/ctools/tests/math_expression.test
Normal file
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \CtoolsMathExpressionTestCase.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests the MathExpression library of ctools.
|
||||
*/
|
||||
class CtoolsMathExpressionTestCase extends DrupalWebTestCase {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'CTools math expression tests',
|
||||
'description' => 'Test the math expression library of ctools.',
|
||||
'group' => 'Chaos Tools Suite',
|
||||
);
|
||||
}
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp('ctools', 'ctools_plugin_test');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a random double between 0 and 1.
|
||||
*/
|
||||
protected function rand01() {
|
||||
return rand(0, PHP_INT_MAX) / PHP_INT_MAX;
|
||||
}
|
||||
|
||||
/**
|
||||
* A custom assertion with checks the values in a certain range.
|
||||
*/
|
||||
protected function assertFloat($first, $second, $delta = 0.0000001, $message = '', $group = 'Other') {
|
||||
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);
|
||||
}
|
||||
|
||||
public function testArithmetic() {
|
||||
$math_expression = new ctools_math_expr();
|
||||
|
||||
// Test constant expressions.
|
||||
$this->assertEqual($math_expression->e('2'), 2);
|
||||
$random_number = rand(0, 10);
|
||||
$this->assertEqual($random_number, $math_expression->e((string) $random_number));
|
||||
|
||||
// Test simple arithmetic.
|
||||
$random_number_a = rand(5, 10);
|
||||
$random_number_b = rand(5, 10);
|
||||
$this->assertEqual($random_number_a + $random_number_b, $math_expression->e("$random_number_a + $random_number_b"));
|
||||
$this->assertEqual($random_number_a - $random_number_b, $math_expression->e("$random_number_a - $random_number_b"));
|
||||
$this->assertEqual($random_number_a * $random_number_b, $math_expression->e("$random_number_a * $random_number_b"));
|
||||
$this->assertEqual($random_number_a / $random_number_b, $math_expression->e("$random_number_a / $random_number_b"));
|
||||
|
||||
// Test Associative property.
|
||||
$random_number_c = rand(5, 10);
|
||||
$this->assertEqual($math_expression->e("$random_number_a + ($random_number_b + $random_number_c)"), $math_expression->e("($random_number_a + $random_number_b) + $random_number_c"));
|
||||
$this->assertEqual($math_expression->e("$random_number_a * ($random_number_b * $random_number_c)"), $math_expression->e("($random_number_a * $random_number_b) * $random_number_c"));
|
||||
|
||||
// Test Commutative property.
|
||||
$this->assertEqual($math_expression->e("$random_number_a + $random_number_b"), $math_expression->e("$random_number_b + $random_number_a"));
|
||||
$this->assertEqual($math_expression->e("$random_number_a * $random_number_b"), $math_expression->e("$random_number_b * $random_number_a"));
|
||||
|
||||
// Test Distributive property.
|
||||
$this->assertEqual($math_expression->e("($random_number_a + $random_number_b) * $random_number_c"), $math_expression->e("($random_number_a * $random_number_c + $random_number_b * $random_number_c)"));
|
||||
|
||||
$this->assertEqual(pow($random_number_a, $random_number_b), $math_expression->e("$random_number_a ^ $random_number_b"));
|
||||
}
|
||||
|
||||
public function testBuildInFunctions() {
|
||||
$math_expression = new ctools_math_expr();
|
||||
|
||||
// @todo: maybe run this code multiple times to test different values.
|
||||
$random_double = $this->rand01();
|
||||
$random_int = rand(5, 10);
|
||||
$this->assertFloat(sin($random_double), $math_expression->e("sin($random_double)"));
|
||||
$this->assertFloat(cos($random_double), $math_expression->e("cos($random_double)"));
|
||||
$this->assertFloat(tan($random_double), $math_expression->e("tan($random_double)"));
|
||||
$this->assertFloat(exp($random_double), $math_expression->e("exp($random_double)"));
|
||||
$this->assertFloat(sqrt($random_double), $math_expression->e("sqrt($random_double)"));
|
||||
$this->assertFloat(log($random_double), $math_expression->e("ln($random_double)"));
|
||||
$this->assertFloat(round($random_double), $math_expression->e("round($random_double)"));
|
||||
$this->assertFloat(abs($random_double + $random_int), $math_expression->e('abs(' . ($random_double + $random_int) . ')'));
|
||||
$this->assertEqual(round($random_double + $random_int), $math_expression->e('round(' . ($random_double + $random_int) . ')'));
|
||||
$this->assertEqual(ceil($random_double + $random_int), $math_expression->e('ceil(' . ($random_double + $random_int) . ')'));
|
||||
$this->assertEqual(floor($random_double + $random_int), $math_expression->e('floor(' . ($random_double + $random_int) . ')'));
|
||||
|
||||
// @fixme: you can't run time without an argument.
|
||||
$this->assertFloat(time(), $math_expression->e('time(1)'));
|
||||
|
||||
$random_double_a = $this->rand01();
|
||||
$random_double_b = $this->rand01();
|
||||
// @fixme: max/min don't work at the moment.
|
||||
// $this->assertFloat(max($random_double_a, $random_double_b), $math_expression->e("max($random_double_a, $random_double_b)"));
|
||||
// $this->assertFloat(min($random_double_a, $random_double_b), $math_expression->e("min($random_double_a, $random_double_b)"));
|
||||
}
|
||||
|
||||
public function testVariables() {
|
||||
$math_expression = new ctools_math_expr();
|
||||
|
||||
$random_number_a = rand(5, 10);
|
||||
$random_number_b = rand(5, 10);
|
||||
|
||||
// Store the first random number and use it on calculations.
|
||||
$math_expression->e("var = $random_number_a");
|
||||
$this->assertEqual($random_number_a + $random_number_b, $math_expression->e("var + $random_number_b"));
|
||||
$this->assertEqual($random_number_a * $random_number_b, $math_expression->e("var * $random_number_b"));
|
||||
$this->assertEqual($random_number_a - $random_number_b, $math_expression->e("var - $random_number_b"));
|
||||
$this->assertEqual($random_number_a / $random_number_b, $math_expression->e("var / $random_number_b"));
|
||||
}
|
||||
|
||||
public function testCustomFunctions() {
|
||||
$math_expression = new ctools_math_expr();
|
||||
|
||||
$random_number_a = rand(5, 10);
|
||||
$random_number_b = rand(5, 10);
|
||||
|
||||
// Create a one-argument function.
|
||||
$math_expression->e("f(x) = 2 * x");
|
||||
$this->assertEqual($random_number_a * 2, $math_expression->e("f($random_number_a)"));
|
||||
$this->assertEqual($random_number_b * 2, $math_expression->e("f($random_number_b)"));
|
||||
|
||||
// Create a two-argument function.
|
||||
$math_expression->e("g(x, y) = 2 * x + y");
|
||||
$this->assertEqual($random_number_a * 2 + $random_number_b, $math_expression->e("g($random_number_a, $random_number_b)"));
|
||||
|
||||
// Use a custom function in another function.
|
||||
$this->assertEqual(($random_number_a * 2 + $random_number_b) * 2, $math_expression->e("f(g($random_number_a, $random_number_b))"));
|
||||
}
|
||||
}
|
63
sites/all/modules/ctools/tests/math_expression_stack.test
Normal file
63
sites/all/modules/ctools/tests/math_expression_stack.test
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \CtoolsMathExpressionStackTestCase
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests the simple MathExpressionStack class.
|
||||
*/
|
||||
class CtoolsMathExpressionStackTestCase extends DrupalWebTestCase {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'CTools math expression stack tests',
|
||||
'description' => 'Test the stack class of the math expression library.',
|
||||
'group' => 'Chaos Tools Suite',
|
||||
);
|
||||
}
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp('ctools', 'ctools_plugin_test');
|
||||
}
|
||||
|
||||
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());
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user