updated etxlink, ctools, colorbox, computed_field

This commit is contained in:
2019-05-13 17:51:14 +02:00
parent 33210e10f2
commit 2ffad14939
309 changed files with 4930 additions and 2655 deletions

View File

@@ -1,20 +1,206 @@
<?php
/**
* @file
* Test the keyword substitution functionality.
*/
class CtoolsContextIDTestCase extends DrupalWebTestCase {
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'Context IDs',
'description' => 'Verify that Context IDs work properly.',
'group' => 'ctools',
'dependencies' => array('ctools'),
);
}
/**
* {@inheritdoc}
*/
protected function setUp(array $modules = array()) {
$modules[] = 'ctools';
parent::setUp($modules);
ctools_include('context');
}
private function getTestContexts() {
$test_objects = array(
array(),
array(
'name' => 'foo_bar',
),
array(
'id' => 25,
),
array(
'id' => 5,
'name' => NULL,
),
array(
'id' => 'a',
'name' => 'foo_bar',
),
array(
'id' => 'z',
'name' => 'baz',
),
array(
'id' => 15,
'name' => 'baz',
),
array(
'id' => 'z',
'name' => 'foo',
),
array(
'id' => 1,
'name' => 'foo',
),
array(
'id' => 47,
'name' => 'bar',
),
array(
'id' => 99,
'name' => 'bar',
),
);
return $test_objects;
}
/**
* Test ctools_context_id where the context only has an id.
*/
public function testContextId() {
$context = array();
$expected = 'context__1';
$actual = ctools_context_id($context);
$this->assertEqual($actual, $expected, 'Empty context has id ' . $expected);
$context = array('id' => 4);
$expected = 'context__4';
$actual = ctools_context_id($context);
$this->assertEqual($actual, $expected, 'Context 4 has id ' . $expected);
$context = array('id' => 'a');
$expected = 'context__a';
$actual = ctools_context_id($context);
$this->assertEqual($actual, $expected, 'Context "a" has id ' . $expected);
}
/**
* Test ctools_context_id where the context has an id and a name.
*/
public function testContextIdName() {
$context = array('id' => '512', 'name' => 'foo');
$expected = 'context_foo_512';
$this->assertEqual(ctools_context_id($context), $expected, 'Context "512"/"foo" has id ' . $expected);
$context = array('id' => '512', 'name' => 'foo_bar');
$expected = 'context_foo_bar_512';
$this->assertEqual(ctools_context_id($context), $expected, 'Context "512"/"foo_bar" has id ' . $expected);
}
/**
* Test ctools_context_id where the context has an id & name, and a type is specified.
*/
public function testContextIdNameType() {
$type = 'sort';
$context = array('id' => '512', 'name' => 'foo');
$expected = 'sort_foo_512';
$this->assertEqual(ctools_context_id($context, $type), $expected, 'Context "512" has id ' . $expected);
$type = NULL;
$context = array('id' => '512', 'name' => 'foo');
$expected = '_foo_512';
$this->assertEqual(ctools_context_id($context, $type), $expected, 'Context "512" has id ' . $expected);
}
/**
* Test ctools_context_next_id in various scenarios.
*/
public function testNextContextId() {
$test_objects = $this->getTestContexts();
// If no object list or name is given?
$value = ctools_context_next_id(NULL, NULL);
$expected = 1;
$this->assertEqual($value, $expected, 'NULL objects have next id ' . $expected);
// If no object list is given?
$value = ctools_context_next_id(NULL, 'bar');
$expected = 1;
$this->assertEqual($value, $expected, 'NULL objects have next id ' . $expected);
// If no object list is given (another way)?
$value = ctools_context_next_id(array(), 'bar');
$expected = 1;
$this->assertEqual($value, $expected, 'Empty objects have next id ' . $expected);
// The name is empty... which is just another name.
$value = ctools_context_next_id($test_objects, '');
$expected = 1;
$this->assertEqual($value, $expected, 'Unnamed objects have next id ' . $expected . ' (got ' . $value . ')');
// The value of the id key is not a number.
$value = ctools_context_next_id($test_objects, 'foo_bar');
$expected = 1;
$this->assertEqual($value, $expected, 'Objects with non-integer ids are ignored ' . $expected);
// One object's id is not a number (ignore) but another is valid.
$value = ctools_context_next_id($test_objects, 'baz');
$expected = 16;
$this->assertEqual($value, $expected, 'Baz\'s objects have next id ' . $expected);
// An expected case: there is one match and the id is numeric.
$value = ctools_context_next_id($test_objects, 'foo');
$expected = 2;
$this->assertEqual($value, $expected, 'Foo\'s objects have next id ' . $expected);
// Another expected case: there are multiple numeric IDs.
$value = ctools_context_next_id($test_objects, 'bar');
$expected = 100;
$this->assertEqual($value, $expected, 'Bar\'s objects have next id ' . $expected);
}
}
/**
* Test the keyword substitution functionality.
*/
class CtoolsContextKeywordsSubstitutionTestCase extends DrupalWebTestCase {
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'Keywords substitution',
'description' => 'Verify that keywords are properly replaced with data.',
'group' => 'ctools',
'dependencies' => array('ctools'),
);
}
public function setUp() {
parent::setUp('ctools');
/**
* {@inheritdoc}
*/
protected function setUp(array $modules = array()) {
$modules[] = 'ctools';
parent::setUp($modules);
ctools_include('context');
}
/**
* Test the keyword substitution.
*/
public function testKeywordsSubstitution() {
// Create node context for substitution.
$node = $this->drupalCreateNode();
@@ -23,64 +209,164 @@ class CtoolsContextKeywordsSubstitutionTestCase extends DrupalWebTestCase {
// Run tests on some edge cases.
$checks = array(
'%node:changed:raw:' => array(
array(
'%node:changed:raw:',
array('%title' => ''),
"{$node->changed}:",
t('Multi-level token has been replaced. Colon left untouched.'),
),
'%node:title' => array(
array(
'%node:title',
array('%title' => ''),
"{$node->title}",
t('Keyword and converter have been replaced.'),
),
'%%node:title' => array(
array(
'%%node:title',
array('%title' => ''),
"%node:title",
t('Keyword after escaped percent sign left untouched.'),
),
'%node:title%node:nid' => array(
array(
'%node:title%node:nid',
array('%title' => ''),
"{$node->title}{$node->nid}",
t('Multiple substitutions have been replaced.'),
),
'%node:title:' => array(
array(
'%node:title:',
array('%title' => ''),
"{$node->title}:",
t('Colon after keyword and converter left untouched.'),
),
'%node:title%%' => array(
array(
'%node:title%%',
array('%title' => ''),
"{$node->title}%",
t('Escaped percent sign after keyword and converter left untouched.'),
),
'%%%node:title' => array(
array(
'%%%node:title',
array('%title' => ''),
"%{$node->title}",
t('Keyword after escaped and unescaped percent sign has been replaced.'),
),
'%%foo:bar' => array(
array(
'%%foo:bar',
array('%title' => ''),
"%foo:bar",
t('Non-existant context ignored.'),
),
'There was about 20%-30% difference in price.' => array(
array(
'There was about 20%-30% difference in price.',
array('%title' => ''),
'There was about 20%-30% difference in price.',
t('Non-keyword percent sign left untouched.'),
),
'href="my%20file%2dname.pdf"' => array(
array(
'href="my%20file%2dname.pdf"',
array('%title' => ''),
'href="my%20file%2dname.pdf"',
t('HTTP URL escape left untouched.'),
),
'href="my%a0file%fdname.pdf"' => array(
array(
'href="my%a0file%fdname.pdf"',
array('%title' => ''),
'href="my%a0file%fdname.pdf"',
t('HTTP URL escape (high-chars) left untouched.'),
),
'<a href="http://www.example.com/here%20is%20a%20pdf.pdf">Click here!</a>' => array(
array(
'<a href="http://www.example.com/here%20is%20a%20pdf.pdf">Click here!</a>',
array('%title' => ''),
'<a href="http://www.example.com/here%20is%20a%20pdf.pdf">Click here!</a>',
t('HTTP URL escape percent sign left untouched in HTML.'),
),
'SELECT * FROM {table} WHERE field = "%s"' => array(
array(
'SELECT * FROM {table} WHERE field = "%s"',
array('%title' => ''),
'SELECT * FROM {table} WHERE field = "%s"',
t('SQL percent sign left untouched.'),
),
array(
'%title',
array('%title' => 'foobar'),
'foobar',
t('String value in $keywords array is returned.'),
),
array(
'%title',
array('%title' => ''),
'',
t('Empty string value in $keywords array returns empty string.'),
),
array(
'%title',
array('%title' => NULL),
'',
t('NULL value in $keywords array returns empty string.'),
),
array(
'%title',
array('%title' => FALSE),
'',
t('FALSE value in $keywords array returns empty string.'),
),
array(
'%title',
array('%title' => 11),
'11',
t('Integer value in $keywords array returns string representation of the integer.'),
),
array(
'%title',
array('%title' => 'substring %title'),
'substring %title',
t('Input value as substring in $keywords array left untouched.'),
),
);
foreach ($checks as $string => $expectations) {
list($expected_result, $message) = $expectations;
$actual_result = ctools_context_keyword_substitute($string, array(), $contexts);
foreach ($checks as $check) {
list($string, $keywords, $expected_result, $message) = $check;
$actual_result = ctools_context_keyword_substitute($string, $keywords, $contexts);
$this->assertEqual($actual_result, $expected_result, $message);
}
}
}
/**
* Test the context classes.
*/
class CtoolsContextUnitTestCase extends DrupalUnitTestCase {
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'Context unit tests',
'description' => 'Verifies that context classes behave correctly',
'group' => 'ctools',
'dependencies' => array('ctools'),
);
}
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
require_once __DIR__ . '/../includes/context.inc';
}
/**
* Tests that contexts have the correct required property value.
*/
public function testOptionalRequiredContext() {
$required_context = new ctools_context_required('test1');
$this->assertTrue($required_context->required);
$optional_context = new ctools_context_optional('test2');
$this->assertFalse($optional_context->required);
}
}

View File

@@ -1,65 +1,98 @@
<?php
/**
* @file
* Tests for different parts of the ctools plugin system.
*/
/**
* Test menu links depending on user permissions.
*/
class CtoolsCssTestCase extends DrupalWebTestCase {
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'CSS Tools tests',
'description' => '...',
'description' => 'Confirm the custom CSS handling works.',
'group' => 'ctools',
'dependencies' => array('ctools'),
);
}
function setUp() {
// Additionally enable contact module.
parent::setUp('ctools');
/**
* {@inheritdoc}
*/
public function setUp(array $modules = array()) {
$modules[] = 'ctools';
parent::setUp($modules);
ctools_include('css');
}
/**
* Test that cached plugins are loaded correctly.
* Test that Stored CSS snippets can be retrieved, filtered or otherwise.
*/
function testCssStuff() {
public function testCssStoreFilterRetrieve() {
$css = "#some-id .some-class {\n color: black;\n illegal-key: foo;\n}";
$filtered_css = '#some-id .some-class{color:black;}';
ctools_include('css');
$this->assertNull(ctools_css_retrieve('missing-css-test'), 'Missing css snippet is not found');
$filename1 = ctools_css_store('unfiltered-css-test', $css, FALSE);
$filename2 = ctools_css_store('filtered-css-test', $css, TRUE);
$file_contents = file_get_contents($filename1);
$this->assertEqual($css, $file_contents, 'Unfiltered css file contents are correct');
$this->assertEqual($filename1, ctools_css_retrieve('unfiltered-css-test'), 'Unfiltered css file successfully fetched');
$file_contents = file_get_contents($filename1);
$this->assertEqual($css, $file_contents, 'Unfiltered css file contents are correct');
// $match = $filename1 == ctools_css_retrieve('unfiltered-css-test') ? 'Match' : 'No match';
// $output .= '<pre>Unfiltered: ' . $filename1 . ' ' . $match . '</pre>';
// $output .= '<pre>' . file_get_contents($filename1) . '</pre>';
$this->assertEqual($filename2, ctools_css_retrieve('filtered-css-test'), 'Filtered css file succcesfully fetched');
$file_contents = file_get_contents($filename2);
$this->assertEqual($filtered_css, $file_contents, 'Filtered css file contents are correct');
// $match = $filename2 == ctools_css_retrieve('filtered-css-test') ? 'Match' : 'No match';
// $output .= '<pre>Filtered: ' . $filename2 . ' ' . $match . '</pre>';
// $output .= '<pre>' . file_get_contents($filename2) . '</pre>';
//
// drupal_add_css($filename2, array('type' => 'file'));
// return array('#markup' => $output);
}
/**
* Test that Stored CSS snippets can be correctly overwritten.
*/
public function testCssStoreOverwrite() {
$css1 = "#some-id .some-class {\n color: black;\n illegal-key: foo;\n}";
// Test that in case that url can be used, the value surives when a colon is in it.
$css2 = "#other-id .other-class {\n color: blue;\n illegal-key: foo;\n}";
$filtered_css2 = '#other-id .other-class{color:blue;}';
ctools_css_store('unfiltered-css-test', $css1, FALSE);
ctools_css_store('filtered-css-test', $css1, TRUE);
// Now overwrite the first css with the second version.
$filename3 = ctools_css_store('unfiltered-css-test', $css2, FALSE);
$filename4 = ctools_css_store('filtered-css-test', $css2, TRUE);
$file_contents3 = file_get_contents($filename3);
$file_contents4 = file_get_contents($filename4);
$this->assertEqual($css2, $file_contents3, 'Unfiltered CSS has overwritten earlier contents.');
$this->assertEqual($filtered_css2, $file_contents4, 'Filtered CSS has overwritten earlier contents.');
}
/**
* Test that in case that url is used, the colons survives filtering.
*/
public function testCssFilterURLHandling() {
$css = "#some-id {\n background-image: url(http://example.com/example.gif);\n}";
$css_data = ctools_css_disassemble($css);
$empty_array = array();
$disallowed_values_regex = '/(expression)/';
$filtered = ctools_css_assemble(ctools_css_filter_css_data($css_data, $empty_array, $empty_array, '', $disallowed_values_regex));
$intermediate = ctools_css_filter_css_data($css_data, $empty_array, $empty_array, '', $disallowed_values_regex);
$filtered = ctools_css_assemble($intermediate);
$url = (strpos($filtered, 'http://example.com/example.gif') !== FALSE);
$this->assertTrue($url, 'CSS with multiple colons can survive.');
}
// Test that in case the CSS has two properties defined are merged.
/**
* Test that when the CSS has two properties defined they are merged.
*/
public function testCssFilterMergeProperties() {
$css = "#some-id {\n font-size: 12px;\n}\n#some-id {\n color: blue;\n}";
$filtered = ctools_css_filter($css);
$font_size = (strpos($filtered, 'font-size:12px;') !== FALSE);
@@ -78,4 +111,5 @@ class CtoolsCssTestCase extends DrupalWebTestCase {
$color = (strpos($filtered, 'color:red') !== FALSE);
$this->assertTrue($font_size && $color, 'Multiple properties are retained.');
}
}

View File

@@ -1,30 +1,28 @@
<?php
/**
* @file
* Tests the custom CSS cache handler.
*/
/**
* Tests the custom CSS cache handler.
*/
class CtoolsObjectCache extends DrupalWebTestCase {
class CtoolsCSSObjectCache extends DrupalWebTestCase {
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'Ctools CSS cache',
'name' => 'CSS cache',
'description' => 'Tests the custom CSS cache handler.',
'group' => 'ctools',
'dependencies' => array('ctools'),
);
}
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp('ctools');
public function setUp(array $modules = array()) {
$modules[] = 'ctools';
parent::setUp($modules);
}
/**

View File

View File

@@ -1,26 +1,43 @@
<?php
/**
* @file
* Tests for different parts of the ctools plugin system.
*/
/**
* Test menu links depending on user permissions.
*/
class CtoolsPluginsGetInfoTestCase extends DrupalWebTestCase {
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'Get plugin info',
'description' => 'Verify that plugin type definitions can properly set and overide values.',
'group' => 'ctools',
'dependencies' => array('ctools'),
);
}
function setUp() {
// Additionally enable contact module.
parent::setUp('ctools', 'ctools_plugin_test');
/**
* {@inheritdoc}
*/
public function setUp(array $modules = array()) {
$modules[] = 'ctools';
$modules[] = 'ctools_plugin_test';
parent::setUp($modules);
}
/**
* Assert helper to check that a specific plugin function exists.
*
* @param $module
* The module that owns the plugin.
* @param $type
* The type of plugin.
* @param $id
* The id of the specific plugin to load.
* @param $function
* The identifier of the function. For example, 'settings form'.
*/
protected function assertPluginFunction($module, $type, $id, $function = 'function') {
$func = ctools_plugin_load_function($module, $type, $id, $function);
$this->assertTrue(function_exists($func), t('Plugin @plugin of plugin type @module:@type successfully retrieved @retrieved for @function.', array(
@@ -32,6 +49,18 @@ class CtoolsPluginsGetInfoTestCase extends DrupalWebTestCase {
)));
}
/**
* Assert helper to check that a specific plugin function does NOT exist.
*
* @param $module
* The module that owns the plugin.
* @param $type
* The type of plugin.
* @param $id
* The id of the specific plugin to load.
* @param $function
* The identifier of the function. For example, 'settings form'.
*/
protected function assertPluginMissingFunction($module, $type, $id, $function = 'function') {
$func = ctools_plugin_load_function($module, $type, $id, $function);
$this->assertEqual($func, NULL, t('Plugin @plugin of plugin type @module:@type for @function with missing function successfully failed.', array(
@@ -42,6 +71,18 @@ class CtoolsPluginsGetInfoTestCase extends DrupalWebTestCase {
)));
}
/**
* Assert helper to check that a plugin can be loaded using a named class.
*
* @param $module
* The module that owns the plugin.
* @param $type
* The type of plugin.
* @param $id
* The id of the specific plugin to load.
* @param string $class
* The name of the PHP class to load.
*/
protected function assertPluginClass($module, $type, $id, $class = 'handler') {
$class_name = ctools_plugin_load_class($module, $type, $id, $class);
$this->assertTrue(class_exists($class_name), t('Plugin @plugin of plugin type @module:@type successfully retrieved @retrieved for @class.', array(
@@ -53,6 +94,18 @@ class CtoolsPluginsGetInfoTestCase extends DrupalWebTestCase {
)));
}
/**
* Assert helper to check that a plugin DOES NOT contain the named class.
*
* @param $module
* The module that owns the plugin.
* @param $type
* The type of plugin.
* @param $id
* The id of the specific plugin to load.
* @param string $class
* The name of the PHP class to load.
*/
protected function assertPluginMissingClass($module, $type, $id, $class = 'handler') {
$class_name = ctools_plugin_load_class($module, $type, $id, $class);
$this->assertEqual($class_name, NULL, t('Plugin @plugin of plugin type @module:@type for @class with missing class successfully failed.', array(
@@ -66,7 +119,7 @@ class CtoolsPluginsGetInfoTestCase extends DrupalWebTestCase {
/**
* Test that plugins are loaded correctly.
*/
function testPluginLoading() {
public function testPluginLoading() {
ctools_include('plugins');
$module = 'ctools_plugin_test';
$type = 'not_cached';
@@ -81,7 +134,7 @@ class CtoolsPluginsGetInfoTestCase extends DrupalWebTestCase {
$this->assertPluginClass($module, $type, 'plugin_array', 'handler');
$this->assertPluginClass($module, $type, 'plugin_array2', 'handler');
$this->assertPluginMissingClass($module, $type, 'plugin_array_dne', 'handler');
// TODO Test big hook plugins.
// @todo Test big hook plugins.
$type = 'cached';
@@ -95,6 +148,7 @@ class CtoolsPluginsGetInfoTestCase extends DrupalWebTestCase {
$this->assertPluginClass($module, $type, 'plugin_array', 'handler');
$this->assertPluginClass($module, $type, 'plugin_array2', 'handler');
$this->assertPluginMissingClass($module, $type, 'plugin_array_dne', 'handler');
// TODO Test big hook plugins.
// @todo Test big hook plugins.
}
}

View File

@@ -0,0 +1,239 @@
<?php
/**
* @file Test classes for code in the CTools module file.
*/
/**
* Test menu links depending on user permissions.
*/
class CtoolsModuleTestCase extends DrupalWebTestCase {
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'Ctools module functions tests',
'description' => 'Check functions in the ctools.module not otherwise tested.',
'group' => 'ctools',
'dependencies' => array('ctools'),
);
}
/**
* {@inheritdoc}
*/
public function setUp(array $modules = array()) {
$modules[] = 'ctools';
parent::setUp($modules);
}
/**
* Test that the break phrase function behaves as expected.
*/
public function testBreakPhrase() {
$tests = array(
NULL => array('value' => array()),
'' => array('value' => array()),
'1' => array('operator' => 'and', 'value' => array(1)),
'99' => array('operator' => 'and', 'value' => array(99)),
'+1' => array('invalid_input' => TRUE, 'value' => array(-1)),
' 1' => array('invalid_input' => TRUE, 'value' => array(-1)),
'1 ' => array('invalid_input' => TRUE, 'value' => array(-1)),
'-1' => array('invalid_input' => TRUE, 'value' => array(-1)),
'-99' => array('invalid_input' => TRUE, 'value' => array(-1)),
'1,2' => array('operator' => 'and', 'value' => array(1, 2)),
'1 2' => array('operator' => 'or', 'value' => array(1, 2)),
'1+2' => array('operator' => 'or', 'value' => array(1, 2)),
'1,2,3' => array('operator' => 'and', 'value' => array(1, 2, 3)),
'1 2 3' => array('operator' => 'or', 'value' => array(1, 2, 3)),
'1+2+3' => array('operator' => 'or', 'value' => array(1, 2, 3)),
'1 , 2 , 3' => array('invalid_input' => TRUE, 'value' => array(-1)),
'1 + 2 + 3' => array('invalid_input' => TRUE, 'value' => array(-1)),
'1,2,3,4,5,6,7,8,9' => array(
'operator' => 'and',
'value' => array(1, 2, 3, 4, 5, 6, 7, 8, 9),
),
'1 2,3,4 5 6 7 8 9' => array('invalid_input' => TRUE, 'value' => array(-1)),
);
foreach ($tests as $string => $expected) {
$result = ctools_break_phrase($string);
$expected = (object) $expected;
$this->assertEqual($result, $expected, 'Break Phrase test patterns: ' . $string);
}
}
/**
* Test that the (deprecated) getuserroles returns expected array.
*/
public function testGetUserRoles() {
$result = ctools_get_roles();
$this->assertTrue(is_array($result), 'get_roles returns an array');
// A key-value array of integers.
foreach ($result as $k => $v) {
$this->assertTrue(is_numeric($k), 'Role key is numeric; ' . $k);
$this->assertTrue(is_string($v), 'Role id is string; ' . $v);
}
}
/**
* Test the ctools_attach_js function returns the expected paths.
*/
public function testAttachJs() {
$taxonomy_path = drupal_get_path('module', 'taxonomy');
$ctools_path = drupal_get_path('module', 'ctools');
// Func should probably do a different thing but this is current behaviour.
$path = ctools_attach_js('');
$this->assertEqual($path, $ctools_path . '/js/.js', 'Attach an empty string');
$path = ctools_attach_js('foo');
$this->assertEqual($path, $ctools_path . '/js/foo.js', 'Attach simple string');
$path = ctools_attach_js('foo', 'ctools', '');
$this->assertEqual($path, $ctools_path . '//foo.js', 'Attach string with empty subdir');
$path = ctools_attach_js('foo', 'ctools', 'javascript');
$this->assertEqual($path, $ctools_path . '/javascript/foo.js', 'Attach string with alternate subdir');
$path = ctools_attach_js('foo', 'taxonomy', 'javascript');
$this->assertEqual($path, $taxonomy_path . '/javascript/foo.js', 'Attach string from different module');
}
/**
* Test the ctools_attach_css function returns the expected paths.
*/
public function testAttachCss() {
$taxonomy_path = drupal_get_path('module', 'taxonomy');
$ctools_path = drupal_get_path('module', 'ctools');
// Func should probably do a different thing but this is current behaviour.
$path = ctools_attach_css('');
$this->assertEqual($path, $ctools_path . '/css/.css', 'Attach empty string');
$path = ctools_attach_css('foo');
$this->assertEqual($path, $ctools_path . '/css/foo.css', 'Attach simple string');
$path = ctools_attach_css('foo', 'ctools', '');
$this->assertEqual($path, $ctools_path . '//foo.css', 'Attach string with empty subdir');
$path = ctools_attach_css('foo', 'ctools', 'theme');
$this->assertEqual($path, $ctools_path . '/theme/foo.css', 'Attach string with alternate subdir');
$path = ctools_attach_css('foo', 'taxonomy', 'theme');
$this->assertEqual($path, $taxonomy_path . '/theme/foo.css', 'Attach string from different module');
}
/**
* Test the ctools version compare function.
*/
public function testApiVersionCompare() {
// We're beyond version 1.
$ok = ctools_api_version('1.0');
$this->assertTrue($ok, 'Check API version 1.0 is ok');
// We're beyond version 1.0.1 too.
$ok = ctools_api_version('1.0.1');
$this->assertTrue($ok, 'Check API version 1.0.1 is ok');
// Not (yet) on api version 10.
$ok = ctools_api_version('10.0');
$this->assertFalse($ok, 'Check API version 10.0 is not ok');
// We are (currently) between version 1.1 and version 4.0.
$ok = ctools_api_version('1.1', '4.0');
$this->assertTrue($ok, 'Check API is between 1 and 4');
}
/**
* Test that the ctools_classs_add works.
*/
public function testClassesAdd() {
ctools_class_reset();
ctools_class_add('testclass');
$classes = ctools_get_classes();
$this->assertEqual(is_array($classes), 1, 'Classes should be an array');
$this->assertEqual(count($classes), 1, 'Classes array has one element');
$this->assertEqual(count($classes['html']), 1, 'Classes array has element: html');
$this->assertTrue(isset($classes['html']['add']), 'Classes array has element: html/add');
$this->assertEqual($classes['html']['add'], array('testclass'), 'Classes array has expected value');
ctools_class_add('class2 class3');
$classes = ctools_get_classes();
$this->assertEqual(is_array($classes), 1, 'Classes should be an array');
$this->assertEqual(count($classes['html']), 1, 'Classes array has element: html');
// TODO: An undesirable result: array('testclass', 'class2', 'class3') is better.
$this->assertEqual($classes['html']['add'], array(
'testclass',
'class2 class3',
), 'Classes array has expected value');
}
/**
* Test that the ctools_classs_remove works.
*/
public function testClassesRemove() {
ctools_class_reset();
ctools_class_remove('testclass');
$classes = ctools_get_classes();
$this->assertEqual(is_array($classes), 1, 'Classes should be an array');
$this->assertEqual(count($classes), 1, 'Classes array has one element');
$this->assertEqual(count($classes['html']), 1, 'Classes array has element: html');
$this->assertTrue(isset($classes['html']['remove']), 'Classes array has element: html/remove');
$this->assertEqual($classes['html']['remove'], array('testclass'), 'Classes array has expected value');
ctools_class_remove('class2 class3');
$classes = ctools_get_classes();
$this->assertEqual(count($classes), 1, 'Classes array has one element');
$this->assertEqual(count($classes['html']), 1, 'Classes array has element: html');
// This is an undesirable result, is array('testclass', 'class2', 'class3') better.
$this->assertEqual($classes['html']['remove'], array(
'testclass',
'class2 class3',
), 'Classes array has expected value');
}
/**
* Test that the ctools_classs_add and ctools_classs_remove interact well.
*/
public function testClassesAddRemove() {
ctools_class_reset();
ctools_class_add('testclass');
ctools_class_remove('testclass');
$classes = ctools_get_classes();
$this->assertTrue(isset($classes['html']['add']), 'Classes array has an add set');
$this->assertEqual($classes['html']['add'], array('testclass'), 'testclass is in the add set');
$this->assertTrue(isset($classes['html']['remove']), 'Classes array has a remove set');
// TODO: Is it really good to let this happen?
$this->assertEqual($classes['html']['remove'], array('testclass'), 'testclass is in the remove set');
}
/**
* Test that the ctools_classs_add and ctools_classs_remove interact well .. 2.
*/
public function testClassesAddRemove2() {
ctools_class_reset();
ctools_class_add('class2 class3');
ctools_class_remove('class3');
$classes = ctools_get_classes();
$this->assertTrue(isset($classes['html']['add']), 'Classes array has an add set');
$this->assertEqual($classes['html']['add'], array('class2 class3'), 'Added class2 class3 is in add set');
$this->assertTrue(isset($classes['html']['remove']), 'Classes array has a remove set');
// TODO: Is it really good to let this happen?
$this->assertEqual($classes['html']['remove'], array('class3'), 'class3 in remove set');
}
}

View File

@@ -1,32 +1,34 @@
<?php
/**
* @file
* Tests for the CTools export system.
*/
/**
* Tests export CRUD.
*/
class CtoolsExportCrudTestCase extends DrupalWebTestCase {
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'CTools export CRUD tests',
'name' => 'Export CRUD',
'description' => 'Test the CRUD functionality for the ctools export system.',
'group' => 'ctools',
);
}
protected function setUp() {
parent::setUp('ctools_export_test');
$this->resetAll();
/**
* {@inheritdoc}
*/
public function setUp(array $modules = array()) {
$modules[] = 'ctools';
$modules[] = 'ctools_export_test';
parent::setUp($modules);
}
/**
* Tests CRUD operation: Load.
*/
function testCrudExportLoad() {
public function testCrudExportLoad() {
$loaded_export = ctools_export_crud_load('ctools_export_test', 'database_test');
$expected_export = new stdClass();
@@ -47,7 +49,7 @@ class CtoolsExportCrudTestCase extends DrupalWebTestCase {
/**
* Tests CRUD operation: Load multiple.
*/
function testCrudExportLoadMultiple() {
public function testCrudExportLoadMultiple() {
$exportable_names = array('database_test', 'overridden_test', 'default_test');
$loaded_exports = ctools_export_crud_load_multiple('ctools_export_test', $exportable_names);
@@ -57,7 +59,7 @@ class CtoolsExportCrudTestCase extends DrupalWebTestCase {
/**
* Tests CRUD operation: Load all.
*/
function testCrudExportLoadAll() {
public function testCrudExportLoadAll() {
$loaded_exports = ctools_export_crud_load_all('ctools_export_test');
$this->assertEqual(count($loaded_exports), 3, 'All exportables have been loaded.');
@@ -66,10 +68,10 @@ class CtoolsExportCrudTestCase extends DrupalWebTestCase {
/**
* Tests CRUD operation: Save.
*/
function testCrudExportSave() {
public function testCrudExportSave() {
$default_export = ctools_export_crud_load('ctools_export_test', 'default_test');
$this->assertTrue($default_export->in_code_only,'The loaded exportable is in code only.');
$this->assertTrue($default_export->in_code_only, 'The loaded exportable is in code only.');
ctools_export_crud_save('ctools_export_test', $default_export);
@@ -84,7 +86,7 @@ class CtoolsExportCrudTestCase extends DrupalWebTestCase {
/**
* Tests CRUD operation: New.
*/
function testCrudExportNew() {
public function testCrudExportNew() {
// Default exportable with defualt values.
$new_export = ctools_export_crud_new('ctools_export_test');
@@ -113,7 +115,7 @@ class CtoolsExportCrudTestCase extends DrupalWebTestCase {
/**
* Tests CRUD operation: Revert.
*/
function testCrudExportRevert() {
public function testCrudExportRevert() {
// Load exportable, will come from database.
$original_export = ctools_export_crud_load('ctools_export_test', 'overridden_test');
@@ -135,14 +137,15 @@ class CtoolsExportCrudTestCase extends DrupalWebTestCase {
// Check the exportable is now in_code_only.
$this->assertTrue($default_export->in_code_only, 'The loaded exportable is in the database only.');
// Make sure the default object loaded matches the same overridden one in the database.
// Make sure the default object loaded matches the same overridden one in
// the database.
$this->assertEqual($original_export->machine, $default_export->machine, 'The default exportable has been loaded and matches the overridden exportable.');
}
/**
* Tests CRUD operation: Delete.
*/
function testCrudExportDelete() {
public function testCrudExportDelete() {
// Create a stub entry save it and delete it from the database.
$new_export = ctools_export_crud_new('ctools_export_test');
ctools_export_crud_save('ctools_export_test', $new_export);
@@ -158,6 +161,7 @@ class CtoolsExportCrudTestCase extends DrupalWebTestCase {
$machine = $database_export->machine;
ctools_export_crud_delete('ctools_export_test', $database_export);
// Clear the exportable caches as it's been loaded above.
ctools_export_load_object_reset('ctools_export_test');
$result = ctools_export_crud_load('ctools_export_test', $machine);
@@ -168,7 +172,7 @@ class CtoolsExportCrudTestCase extends DrupalWebTestCase {
/**
* Tests CRUD operation: Set status.
*/
function testCrudExportSetStatus() {
public function testCrudExportSetStatus() {
// Database only object.
$database_export = ctools_export_crud_load('ctools_export_test', 'database_test');
ctools_export_crud_disable('ctools_export_test', $database_export);

View File

@@ -1,5 +1,9 @@
<?php
/**
* @file
*/
/**
* Implements hook_default_export_tests().
*/

View File

@@ -2,15 +2,13 @@ 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 2016-11-22
version = "7.x-1.12"
; Information added by Drupal.org packaging script on 2019-02-08
version = "7.x-1.15"
core = "7.x"
project = "ctools"
datestamp = "1479787162"
datestamp = "1549603691"

View File

@@ -1,12 +1,16 @@
<?php
/**
* Implements hook_schema();
* @file
*/
/**
* Implements hook_schema().
*/
function ctools_export_test_schema() {
$schema['ctools_export_test'] = array(
'description' => 'CTools export test data table',
'export' => array(
'description' => 'CTools export test data table',
'export' => array(
'key' => 'machine',
'identifier' => 'ctools_export_test',
'default hook' => 'default_ctools_export_tests',
@@ -53,7 +57,7 @@ function ctools_export_test_schema() {
}
/**
* Implments hook_install();
* Implements hook_install().
*/
function ctools_export_test_install() {
$ctools_export_tests = array();

View File

@@ -1,5 +1,9 @@
<?php
/**
* @file
*/
/**
* Implements hook_ctools_plugin_api().
*/

View File

@@ -1,20 +1,12 @@
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 2016-11-22
version = "7.x-1.12"
; Information added by Drupal.org packaging script on 2019-02-08
version = "7.x-1.15"
core = "7.x"
project = "ctools"
datestamp = "1479787162"
datestamp = "1549603691"

View File

@@ -1,10 +1,12 @@
<?php
/**
* Define some plugin systems to test ctools plugin includes.
* @file
* Define some plugin systems to test CTools plugin includes.
*/
/**
* Implementation of hook_ctools_plugin_dierctory()
* Implementation of hook_ctools_plugin_directory().
*/
function ctools_plugin_test_ctools_plugin_directory($module, $plugin) {
if ($module == 'ctools_plugin_test') {
@@ -12,11 +14,14 @@ function ctools_plugin_test_ctools_plugin_directory($module, $plugin) {
}
}
/**
* Implements hook_ctools_plugin_type().
*/
function ctools_plugin_test_ctools_plugin_type() {
return array(
'extra_defaults' => array(
'defaults' => array(
'bool' => true,
'bool' => TRUE,
'string' => 'string',
'array' => array('some value'),
),
@@ -50,6 +55,11 @@ function ctools_plugin_test_ctools_plugin_type() {
);
}
/**
* Plugin callback.
*
* @see ctools_plugin_test_ctools_plugin_type()
*/
function ctools_plugin_test_ctools_plugin_test_big_hook_cached() {
return array(
'test1' => array(
@@ -59,6 +69,11 @@ function ctools_plugin_test_ctools_plugin_test_big_hook_cached() {
);
}
/**
* Plugin callback.
*
* @see ctools_plugin_test_ctools_plugin_type()
*/
function ctools_plugin_test_ctools_plugin_test_big_hook_not_cached() {
return array(
'test1' => array(
@@ -68,5 +83,18 @@ function ctools_plugin_test_ctools_plugin_test_big_hook_not_cached() {
);
}
function ctools_plugin_test_hook_cached_test() {}
function ctools_plugin_test_hook_not_cached_test() {}
/**
* Callback for the big_hook_cached plugin.
*
* @see ctools_plugin_test_ctools_plugin_test_big_hook_cached
*/
function ctools_plugin_test_hook_cached_test() {
}
/**
* Callback for the big_hook_not_cached plugin.
*
* @see ctools_plugin_test_ctools_plugin_test_big_hook_not_cached()
*/
function ctools_plugin_test_hook_not_cached_test() {
}

View File

@@ -1,24 +1,29 @@
<?php
/**
* @file
* Contains \CtoolsMathExpressionTestCase.
*/
/**
* Tests the MathExpression library of ctools.
*/
class CtoolsMathExpressionTestCase extends DrupalWebTestCase {
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'CTools math expression tests',
'name' => 'Math expressions',
'description' => 'Test the math expression library of ctools.',
'group' => 'ctools',
'dependencies' => array('ctools'),
);
}
public function setUp() {
parent::setUp('ctools', 'ctools_plugin_test');
/**
* {@inheritdoc}
*/
public function setUp(array $modules = array()) {
$modules[] = 'ctools';
$modules[] = 'ctools_plugin_test';
parent::setUp($modules);
}
/**
@@ -35,6 +40,9 @@ class CtoolsMathExpressionTestCase extends DrupalWebTestCase {
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);
}
/**
* Test some arithmetic handling.
*/
public function testArithmetic() {
$math_expression = new ctools_math_expr();
@@ -66,10 +74,13 @@ class CtoolsMathExpressionTestCase extends DrupalWebTestCase {
$this->assertEqual(pow($random_number_a, $random_number_b), $math_expression->e("$random_number_a ^ $random_number_b"));
}
/**
* Test the basic built-in functions in the math expression library.
*/
public function testBuildInFunctions() {
$math_expression = new ctools_math_expr();
// @todo: maybe run this code multiple times to test different values.
// @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)"));
@@ -94,6 +105,9 @@ class CtoolsMathExpressionTestCase extends DrupalWebTestCase {
// $this->assertFloat(min($random_double_a, $random_double_b), $math_expression->e("min($random_double_a, $random_double_b)"));
}
/**
* Test variable handling.
*/
public function testVariables() {
$math_expression = new ctools_math_expr();
@@ -108,6 +122,9 @@ class CtoolsMathExpressionTestCase extends DrupalWebTestCase {
$this->assertEqual($random_number_a / $random_number_b, $math_expression->e("var / $random_number_b"));
}
/**
* Test custom function handling.
*/
public function testCustomFunctions() {
$math_expression = new ctools_math_expr();
@@ -126,4 +143,5 @@ class CtoolsMathExpressionTestCase extends DrupalWebTestCase {
// 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))"));
}
}

View File

@@ -1,26 +1,34 @@
<?php
/**
* @file
* Contains \CtoolsMathExpressionStackTestCase
*/
/**
* Tests the simple MathExpressionStack class.
*/
class CtoolsMathExpressionStackTestCase extends DrupalWebTestCase {
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'CTools math expression stack tests',
'name' => 'Math expressions stack',
'description' => 'Test the stack class of the math expression library.',
'group' => 'ctools',
'dependencies' => array('ctools'),
);
}
public function setUp() {
parent::setUp('ctools', 'ctools_plugin_test');
/**
* {@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();
@@ -35,13 +43,15 @@ class CtoolsMathExpressionStackTestCase extends DrupalWebTestCase {
$this->assertIdentical($value, $stack->pop());
$this->assertNull($stack->pop());
// Add multiple elements and see whether they are returned in the right order.
// 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.
// 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));
@@ -58,6 +68,6 @@ class CtoolsMathExpressionStackTestCase extends DrupalWebTestCase {
$this->assertEqual($stack->pop(), $value);
}
$this->assertNull($stack->pop());
}
}

View File

@@ -1,27 +1,34 @@
<?php
/**
* @file
* Tests for different parts of the ctools object caching system.
*/
/**
* Test object cache storage.
*/
class CtoolsObjectCache extends DrupalWebTestCase {
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'Ctools object cache storage',
'name' => 'Object cache storage (UI tests)',
'description' => 'Verify that objects are written, readable and lockable.',
'group' => 'ctools',
'dependencies' => array('ctools'),
);
}
public function setUp() {
// Additionally enable ctools module.
parent::setUp('ctools');
/**
* {@inheritdoc}
*/
public function setUp(array $modules = array()) {
$modules[] = 'ctools';
parent::setUp($modules);
}
public function testObjectStorage() {
ctools_include('cache');
$account1 = $this->drupalCreateUser(array());
$this->drupalLogin($account1);
@@ -36,11 +43,11 @@ class CtoolsObjectCache extends DrupalWebTestCase {
// TODO Test object locking somehow.
// Object locking/testing works on session_id but simpletest uses
// $this->session_id so can't be tested ATM.
ctools_object_cache_clear('testdata', 'one');
$this->assertFalse(ctools_object_cache_get('testdata', 'one'), 'Object cache data successfully cleared');
// TODO Test ctools_object_cache_clear_all somehow...
// ctools_object_cache_clear_all requires session_id funtionality as well.
}
}

View File

@@ -0,0 +1,141 @@
<?php
/**
* Test ctools_cache_find_plugin and the structure of the default cache plugins.
*/
class CtoolsUnitObjectCachePlugins extends DrupalWebTestCase {
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'Object cache storage (unit tests)',
'description' => 'Verify that objects are written, readable and lockable.',
'group' => 'ctools',
'dependencies' => array('ctools'),
);
}
/**
* {@inheritdoc}
*/
public function setUp(array $modules = array()) {
$modules[] = 'ctools';
parent::setUp($modules);
}
/**
* Check that the supplied array looks like a ctools cache plugin.
*
* @param mixed $p
* The value to check.
* @param string $msg
* Prefix of the assertion message.
*/
public function assertValidCachePlugin($p, $msg) {
$this->assertTrue(is_array($p), $msg . ': plugin is an array');
$this->assertEqual($p['plugin type'], 'cache', $msg . ': type is cache');
$this->assertTrue(array_key_exists('title', $p), $msg . ': title element exists');
$this->assertTrue(!empty($p['title']) && is_string($p['title']), $msg . ': title is a string');
$this->assertTrue(array_key_exists('cache get', $p), $msg . ': has a get function');
$this->assertTrue(!empty($p['cache get']) && is_callable($p['cache get']), $msg . ': get is executable');
$this->assertTrue(array_key_exists('cache set', $p), $msg . ': has a set function');
$this->assertTrue(!empty($p['cache set']) && is_callable($p['cache set']), $msg . ': set is executable');
// @todo Clear is required by the spec (cache.inc:40..48): but export_ui
// cache doesn't implement it. Enable the assertions when that problem is
// solved.
// $this->assertTrue(array_key_exists('cache clear', $p), $msg . ': has a clear function');
// $this->assertTrue(is_callable($p['cache clear']), $msg . ': clear is executable');
// @todo Break is optional acc'd to spec but does anything implement it?
$this->assertTrue(!array_key_exists('cache break', $p) || is_callable($p['cache break']), $msg . ': break is executable');
// @todo Finalize is optional so don't fail if not there??
$this->assertTrue(!array_key_exists('cache finalize', $p) || is_callable($p['cache finalize']), $msg . ': finalize is executable');
}
/**
* Check the return value of the ctools_cache_find_plugin function.
*
* @param mixed $p
* The value to check.
* @param string $msg
* Prefix of the assertion message.
*/
public function assertPluginNotFound($p, $msg) {
$this->assertTrue(is_array($p), $msg . ': is an array');
$plugin = array_shift($p);
$this->assertNull($plugin, $msg . ': no plugin info');
$data = array_shift($p);
$this->assertTrue(empty($data) || is_string($data), $msg . ': data string-like');
$this->assertTrue(empty($p), $msg . ': just two elements');
}
/**
* Check the return value of the ctools_cache_find_plugin function.
*
* @param mixed $p
* The value to check.
* @param string $msg
* Prefix of the assertion message.
*/
public function assertPluginFound($p, $msg) {
$this->assertTrue(is_array($p), $msg . ': is an array');
$plugin = array_shift($p);
$this->assertTrue(is_array($plugin), $msg . ': has plugin data');
$data = array_shift($p);
$this->assertTrue(empty($data) || is_string($data), $msg . ': data is string-like');
$this->assertTrue(empty($p), $msg . ': just two elements');
}
/**
* Test to see that we can find the standard simple plugin.
*/
public function testFindSimpleCachePlugin() {
ctools_include('cache');
// The simple plugin.
$plugin = ctools_cache_find_plugin('simple');
$this->assertPluginFound($plugin, 'The Simple Cache plugin is present');
$this->assertValidCachePlugin($plugin[0], 'The Simple Cache plugin');
// The simple plugin, with ::.
$plugin = ctools_cache_find_plugin('simple::data');
$this->assertPluginFound($plugin, 'The Simple Cache plugin is present, with data');
}
/**
* Test to see that we can find the standard export_ui plugin.
*/
public function testFindExportUICachePlugin() {
ctools_include('cache');
// The export plugin.
$plugin = ctools_cache_find_plugin('export_ui');
$this->assertPluginFound($plugin, 'The Export UI Cache plugin is present');
$this->assertValidCachePlugin($plugin[0], 'The Export Cache plugin');
// The export plugin, with ::.
$plugin = ctools_cache_find_plugin('export_ui::data');
$this->assertTrue(is_array($plugin), 'The Export UI Cache plugin is present, with data');
}
/**
* Test to see that we don't find plugins that aren't there.
*/
public function testFindFoobarbazCachePlugin() {
ctools_include('cache');
// An imaginary foobarbaz plugin.
$plugin = ctools_cache_find_plugin('foobarbaz');
$this->assertPluginNotFound($plugin, 'The Foobarbaz Cache plugin is absent');
$plugin = ctools_cache_find_plugin('foobarbaz::data');
$this->assertPluginNotFound($plugin, 'The Foobarbaz Cache plugin is absent, with data');
}
}

View File

@@ -0,0 +1,136 @@
<?php
/**
* @file
* Tests for different parts of the ctools object caching system.
*
* Needs to be a WebTest because need access to database tables.
*/
class CtoolsPageTokens extends DrupalWebTestCase {
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'Page token processing',
'description' => 'Verify that page tokens can be set and read.',
'group' => 'ctools',
'dependencies' => array('ctools'),
);
}
/**
* {@inheritdoc}
*/
public function setUp(array $modules = array()) {
$modules[] = 'ctools';
parent::setUp($modules);
// Start each test anew.
ctools_reset_page_tokens();
}
/**
* Test that we can set page tokens.
*/
public function testSetPageToken() {
ctools_set_page_token('id', 'variable', 'test');
$tokens = ctools_set_page_token();
$this->assertTrue(is_array($tokens) && count($tokens) === 1, 'Page tokens no longer empty.');
$this->assertEqual($tokens['id'], array('variable', 'test'), 'Page token has correct value.');
}
/**
* Test that we can set page tokens.
*/
public function testSetVariableToken() {
$string = ctools_set_variable_token('title');
$tokens = ctools_set_page_token();
$this->assertTrue(is_array($tokens) && count($tokens) === 1, 'Page tokens no longer empty');
$this->assertEqual($tokens[$string], array('variable', 'title'), 'Page tokens no longer empty');
}
/**
* Test that we can set page tokens.
*/
public function testReplaceVariableToken() {
$string = ctools_set_variable_token('title');
$this->assertEqual($string, '<!-- ctools-page-title -->', 'Expected form of token was found');
$elements = array(
'#type' => 'container',
'#attributes' => array('class' => array('test')),
'title' => '<h2>Title</h2>',
'content' => array(
'#type' => 'markup',
'#markup' => t('This is my test markup'),
'#prefix' => $string,
),
'link' => array(
'#type' => 'link',
'#title' => t('My link'),
'#href' => 'node/1',
),
);
$markup = '<div class="test"><!-- ctools-page-title -->This is my test markup<a href="node/1">My link</a></div>';
$new_markup = ctools_page_token_processing($markup, $elements);
$this->assertTrue(is_string($new_markup) && strlen($new_markup) > 1, 'Should return string');
$this->assertTrue(strstr($new_markup, '<h2>'), 'Variable Token Markup should contain h2 element');
$this->assertFalse(strstr($new_markup, 'ctools-page-title'), 'Variable Token Markup should not contain comment element');
}
/**
* Test that we can set page tokens.
*/
public function testReplaceCallbackToken() {
$string = ctools_set_callback_token('title', 'test_ctools_page_callback_token');
$this->assertEqual($string, '<!-- ctools-page-title -->', 'Expected form of token was found');
$elements = array(
'#type' => 'container',
'#attributes' => array('class' => array('test')),
'content' => array(
'#type' => 'markup',
'#markup' => t('This is my test markup'),
'#prefix' => $string,
),
'link' => array(
'#type' => 'link',
'#title' => t('My link'),
'#href' => 'node/1',
),
);
$markup = '<div class="test"><!-- ctools-page-title -->This is my test markup<a href="node/1">My link</a></div>';
$new_markup = ctools_page_token_processing($markup, $elements);
$this->assertTrue(is_string($new_markup) && strlen($new_markup) > 1, 'Should return a non-empty string');
$this->assertTrue(strstr($new_markup, '<h2>'), 'Callback Token Markup should contain h2 element');
$this->assertFalse(strstr($new_markup, 'ctools-page-title'), 'Callback Token Markup should not contain comment element');
}
}
/**
*
* @param $elements
*
* @return string
*/
function test_ctools_page_callback_token($elements) {
// Check that 'elements' array looks good.
if (isset($elements['content'])) {
return '<h2>Title</h2>';
}
else {
return '<!--bad-->';
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* @file
* A cached plugin object that tests inheritance including.

View File

@@ -1,4 +1,5 @@
<?php
/**
* @file
* A cached plugin object that tests inheritance including.

View File

@@ -1,4 +1,5 @@
<?php
/**
* @file
* Chaos Tools plugin include using a plugin array to declare a plugin.
@@ -17,4 +18,5 @@ $plugin = array(
/**
* Plugin array function plugin.
*/
function ctools_plugin_test_plugin_array_cached_test() {}
function ctools_plugin_test_plugin_array_cached_test() {
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* @file
* Chaos Tools plugin include using a plugin array to declare a plugin.
@@ -17,4 +18,5 @@ $plugin = array(
/**
* Plugin array function plugin.
*/
function ctools_plugin_test_plugin_array2_cached_test() {}
function ctools_plugin_test_plugin_array2_cached_test() {
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* @file
* Chaos Tools plugin include using a plugin array to declare a plugin.

View File

@@ -1,4 +1,5 @@
<?php
/**
* @file
* A cached plugin object that tests inheritance including.

View File

@@ -1,4 +1,5 @@
<?php
/**
* @file
* A cached plugin object that tests including.

View File

@@ -1,4 +1,5 @@
<?php
/**
* @file
* Chaos Tools plugin include using a plugin array to declare a plugin.
@@ -17,4 +18,5 @@ $plugin = array(
/**
* Plugin array function plugin.
*/
function ctools_plugin_test_plugin_array_not_cached_test() {}
function ctools_plugin_test_plugin_array_not_cached_test() {
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* @file
* Chaos Tools plugin include using a plugin array to declare a plugin.
@@ -17,4 +18,5 @@ $plugin = array(
/**
* Plugin array function plugin.
*/
function ctools_plugin_test_plugin_array2_not_cached_test() {}
function ctools_plugin_test_plugin_array2_not_cached_test() {
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* @file
* Chaos Tools plugin include using a plugin array to declare a plugin.