From 29a6913890a675ddf1a9239b4407f105e02dc95d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ctibor=20Bran=C4=8D=C3=ADk?= Date: Sun, 20 Mar 2016 19:27:01 +0100 Subject: Added drupal modules for site --- sites/all/modules/ctools/tests/context.test | 62 ++++++ sites/all/modules/ctools/tests/css.test | 81 ++++++++ sites/all/modules/ctools/tests/css_cache.test | 48 +++++ sites/all/modules/ctools/tests/ctools.drush.sh | 119 ++++++++++++ sites/all/modules/ctools/tests/ctools.plugins.test | 100 ++++++++++ .../tests/ctools_export_test/ctools_export.test | 215 +++++++++++++++++++++ ...ols_export_test.default_ctools_export_tests.inc | 31 +++ .../ctools_export_test/ctools_export_test.info | 16 ++ .../ctools_export_test/ctools_export_test.install | 86 +++++++++ .../ctools_export_test/ctools_export_test.module | 10 + .../modules/ctools/tests/ctools_plugin_test.info | 20 ++ .../modules/ctools/tests/ctools_plugin_test.module | 72 +++++++ .../all/modules/ctools/tests/math_expression.test | 129 +++++++++++++ .../ctools/tests/math_expression_stack.test | 63 ++++++ sites/all/modules/ctools/tests/object_cache.test | 46 +++++ .../cached/ctoolsCachedPluginArray.class.php | 7 + .../cached/ctoolsCachedPluginArray2.class.php | 7 + .../ctools/tests/plugins/cached/plugin_array.inc | 20 ++ .../ctools/tests/plugins/cached/plugin_array2.inc | 20 ++ .../tests/plugins/cached/plugin_array_dne.inc | 15 ++ .../ctoolsNotCachedPluginArray.class.php | 7 + .../ctoolsNotCachedPluginArray2.class.php | 7 + .../tests/plugins/not_cached/plugin_array.inc | 20 ++ .../tests/plugins/not_cached/plugin_array2.inc | 20 ++ .../tests/plugins/not_cached/plugin_array_dne.inc | 15 ++ 25 files changed, 1236 insertions(+) create mode 100644 sites/all/modules/ctools/tests/context.test create mode 100644 sites/all/modules/ctools/tests/css.test create mode 100644 sites/all/modules/ctools/tests/css_cache.test create mode 100755 sites/all/modules/ctools/tests/ctools.drush.sh create mode 100644 sites/all/modules/ctools/tests/ctools.plugins.test create mode 100644 sites/all/modules/ctools/tests/ctools_export_test/ctools_export.test create mode 100644 sites/all/modules/ctools/tests/ctools_export_test/ctools_export_test.default_ctools_export_tests.inc create mode 100644 sites/all/modules/ctools/tests/ctools_export_test/ctools_export_test.info create mode 100644 sites/all/modules/ctools/tests/ctools_export_test/ctools_export_test.install create mode 100644 sites/all/modules/ctools/tests/ctools_export_test/ctools_export_test.module create mode 100644 sites/all/modules/ctools/tests/ctools_plugin_test.info create mode 100644 sites/all/modules/ctools/tests/ctools_plugin_test.module create mode 100644 sites/all/modules/ctools/tests/math_expression.test create mode 100644 sites/all/modules/ctools/tests/math_expression_stack.test create mode 100644 sites/all/modules/ctools/tests/object_cache.test create mode 100644 sites/all/modules/ctools/tests/plugins/cached/ctoolsCachedPluginArray.class.php create mode 100644 sites/all/modules/ctools/tests/plugins/cached/ctoolsCachedPluginArray2.class.php create mode 100644 sites/all/modules/ctools/tests/plugins/cached/plugin_array.inc create mode 100644 sites/all/modules/ctools/tests/plugins/cached/plugin_array2.inc create mode 100644 sites/all/modules/ctools/tests/plugins/cached/plugin_array_dne.inc create mode 100644 sites/all/modules/ctools/tests/plugins/not_cached/ctoolsNotCachedPluginArray.class.php create mode 100644 sites/all/modules/ctools/tests/plugins/not_cached/ctoolsNotCachedPluginArray2.class.php create mode 100644 sites/all/modules/ctools/tests/plugins/not_cached/plugin_array.inc create mode 100644 sites/all/modules/ctools/tests/plugins/not_cached/plugin_array2.inc create mode 100644 sites/all/modules/ctools/tests/plugins/not_cached/plugin_array_dne.inc (limited to 'sites/all/modules/ctools/tests') diff --git a/sites/all/modules/ctools/tests/context.test b/sites/all/modules/ctools/tests/context.test new file mode 100644 index 000000000..bdf14e3f4 --- /dev/null +++ b/sites/all/modules/ctools/tests/context.test @@ -0,0 +1,62 @@ + 'Keywords substitution', + 'description' => 'Verify that keywords are properly replaced with data.', + 'group' => 'Chaos Tools Suite', + ); + } + + public function setUp() { + parent::setUp('ctools'); + + ctools_include('context'); + } + + public function testKeywordsSubstitution() { + // Create node context for substitution. + $node = $this->drupalCreateNode(); + $context = ctools_context_create('node', $node); + $contexts = array('argument_1' => $context); + + // Run tests on some edge cases. + $checks = array( + '%node:changed:raw:' => array( + "{$node->changed}:", + t('Multi-level token has been replaced. Colon left untouched.'), + ), + '%node:title' => array( + "{$node->title}", + t('Keyword and converter have been replaced.'), + ), + '%%node:title' => array( + "%node:title", + t('Keyword after escaped percent sign left untouched.'), + ), + '%node:title%node:nid' => array( + "{$node->title}{$node->nid}", + t('Multiple substitutions have been replaced.'), + ), + '%node:title:' => array( + "{$node->title}:", + t('Colon after keyword and converter left untouched.'), + ), + '%node:title%%' => array( + "{$node->title}%", + t('Escaped percent sign after keyword and converter left untouched.'), + ), + '%%%node:title' => array( + "%{$node->title}", + t('Keyword after escaped and unescaped percent sign has been replaced.'), + ), + ); + foreach ($checks as $string => $expectations) { + list($expected_result, $message) = $expectations; + $actual_result = ctools_context_keyword_substitute($string, array(), $contexts); + $this->assertEqual($actual_result, $expected_result, $message); + } + } + +} diff --git a/sites/all/modules/ctools/tests/css.test b/sites/all/modules/ctools/tests/css.test new file mode 100644 index 000000000..4a5200caa --- /dev/null +++ b/sites/all/modules/ctools/tests/css.test @@ -0,0 +1,81 @@ + 'CSS Tools tests', + 'description' => '...', + 'group' => 'Chaos Tools Suite', + ); + } + + function setUp() { + // Additionally enable contact module. + parent::setUp('ctools'); + } + + /** + * Test that cached plugins are loaded correctly. + */ + function testCssStuff() { + $css = "#some-id .some-class {\n color: black;\n illegal-key: foo;\n}"; + $filtered_css = '#some-id .some-class{color:black;}'; + + ctools_include('css'); + $filename1 = ctools_css_store('unfiltered-css-test', $css, FALSE); + $filename2 = ctools_css_store('filtered-css-test', $css, TRUE); + + $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 .= '
Unfiltered: ' . $filename1 . ' ' . $match . '
'; +// $output .= '
' . file_get_contents($filename1) . '
'; + + $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 .= '
Filtered: ' . $filename2 . ' ' . $match . '
'; +// $output .= '
' . file_get_contents($filename2) . '
'; +// +// drupal_add_css($filename2, array('type' => 'file')); +// return array('#markup' => $output); + + + // Test that in case that url can be used, the value surives when a colon is in it. + $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)); + $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. + $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); + $color = (strpos($filtered, 'color:blue') !== FALSE); + $this->assertTrue($font_size && $color, 'Multiple properties are merged.'); + + $css = '@import url("other.css");p {color: red;}'; + $filtered = ctools_css_filter($css); + $other_css = (strpos($filtered, 'other.css') === FALSE); + $color = (strpos($filtered, 'color:red') !== FALSE); + $this->assertTrue($other_css && $color, 'CSS is properly sanitized.'); + + $css = ';p {color: red; font-size: 12px;}'; + $filtered = ctools_css_filter($css); + $font_size = (strpos($filtered, 'font-size:12px;') !== FALSE); + $color = (strpos($filtered, 'color:red') !== FALSE); + $this->assertTrue($font_size && $color, 'Multiple properties are retained.'); + } +} diff --git a/sites/all/modules/ctools/tests/css_cache.test b/sites/all/modules/ctools/tests/css_cache.test new file mode 100644 index 000000000..e289b42c9 --- /dev/null +++ b/sites/all/modules/ctools/tests/css_cache.test @@ -0,0 +1,48 @@ + '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.'); + } + +} diff --git a/sites/all/modules/ctools/tests/ctools.drush.sh b/sites/all/modules/ctools/tests/ctools.drush.sh new file mode 100755 index 000000000..31bdee359 --- /dev/null +++ b/sites/all/modules/ctools/tests/ctools.drush.sh @@ -0,0 +1,119 @@ +#!/bin/bash + +# Run this from the terminal inside a drupal root folder +# i.e. DRUPAL_ROOT_DIR/sites/all/modules/contrib/ctools/tests/ctools.drush.sh + +function stamp { + echo ============== + echo timestamp : `date` + echo ============== +} + +DRUPAL_ROOT=`drush dd` +MODULE_DIR="$DRUPAL_ROOT/sites/all/modules" +MODULE_NAME="ctools_drush_test" + +stamp + +echo 'Enabling ctools, views, and bulk_export modules.' +drush en ctools views bulk_export --yes + +stamp +echo 'Reading all export info' +drush ctools-export-info + +stamp +echo 'Reading all export info with format' +drush ctools-export-info --format=json + +stamp +echo 'Reading tables only from export info' +drush ctools-export-info --tables-only + +stamp +echo 'Reading tables only from export info with format' +drush ctools-export-info --tables-only --format=json + +stamp +echo 'Reading all disabled exportables' +drush ctools-export-info --filter=disabled + +stamp +echo 'Enabling all default views' +drush ctools-export-enable views_view --yes + +stamp +echo 'Reading all enabled exportables' +drush ctools-export-info --filter=enabled + +stamp +echo 'Reading all overridden exportables' +drush ctools-export-info --filter=overridden + +stamp +echo 'Reading all database only exportables' +drush ctools-export-info --filter=database + +stamp +echo 'View all default views export data' +drush ctools-export-view views_view --yes + +stamp +echo 'View default "archive" view export data' +drush ctools-export-view views_view archive + +stamp +echo 'Disable default "archive" view' +drush ctools-export-disable views_view archive + +stamp +echo 'Enable default "archive" view' +drush ctools-export-enable views_view archive + +stamp +echo 'Reading all enabled exportables (archive disabled)' +drush ctools-export-info + +stamp +echo 'Disabling all default views' +drush ctools-export-disable views_view --yes + +stamp +echo 'Revert all default views' +drush ctools-export-revert views_view --yes + +stamp +echo 'Enable all node views' +drush ctools-export-enable views_view --module=node --yes + +stamp +echo 'Disable all node views' +drush ctools-export-disable views_view --module=node --yes + +stamp +echo 'Revert all node views' +drush ctools-export-revert views_view --module=node --yes + +stamp +echo 'Revert all exportables' +drush ctools-export-revert --all --yes + +stamp +echo 'Enable all exportables' +drush ctools-export-enable --all --yes + +stamp +echo 'Disable all exportables' +drush ctools-export-disable --all --yes + +stamp +echo 'Bulk export all objects' +drush ctools-export $MODULE_NAME --subdir='tests' --choice=1 + +stamp +echo 'Show all files in created folder' +ls -lAR "$MODULE_DIR/tests/$MODULE_NAME" + +stamp +echo 'Removing exported object files' +rm -Rf $MODULE_DIR/tests diff --git a/sites/all/modules/ctools/tests/ctools.plugins.test b/sites/all/modules/ctools/tests/ctools.plugins.test new file mode 100644 index 000000000..fe1829cfb --- /dev/null +++ b/sites/all/modules/ctools/tests/ctools.plugins.test @@ -0,0 +1,100 @@ + 'Get plugin info', + 'description' => 'Verify that plugin type definitions can properly set and overide values.', + 'group' => 'Chaos Tools Suite', + ); + } + + function setUp() { + // Additionally enable contact module. + parent::setUp('ctools', 'ctools_plugin_test'); + } + + 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( + '@plugin' => $id, + '@module' => $module, + '@type' => $type, + '@function' => $function, + '@retrieved' => $func, + ))); + } + + 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( + '@plugin' => $id, + '@module' => $module, + '@type' => $type, + '@function' => $func, + ))); + } + + 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( + '@plugin' => $id, + '@module' => $module, + '@type' => $type, + '@class' => $class, + '@retrieved' => $class_name, + ))); + } + + 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( + '@plugin' => $id, + '@module' => $module, + '@type' => $type, + '@class' => $class, + ))); + } + + /** + * Test that plugins are loaded correctly. + */ + function testPluginLoading() { + ctools_include('plugins'); + $module = 'ctools_plugin_test'; + $type = 'not_cached'; + + // Test function retrieval for plugins using different definition methods. + $this->assertPluginFunction($module, $type, 'plugin_array', 'function'); + $this->assertPluginFunction($module, $type, 'plugin_array2', 'function'); + $this->assertPluginMissingFunction($module, $type, 'plugin_array_dne', 'function'); + $this->assertPluginFunction($module, "big_hook_$type", 'test1', 'function'); + + // Test class retrieval for plugins using different definition methods. + $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. + + $type = 'cached'; + + // Test function retrieval for plugins using different definition methods. + $this->assertPluginFunction($module, $type, 'plugin_array', 'function'); + $this->assertPluginFunction($module, $type, 'plugin_array2', 'function'); + $this->assertPluginMissingFunction($module, $type, 'plugin_array_dne', 'function'); + $this->assertPluginFunction($module, "big_hook_$type", 'test1', 'function'); + + // Test class retrieval for plugins using different definition methods. + $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. + } +} diff --git a/sites/all/modules/ctools/tests/ctools_export_test/ctools_export.test b/sites/all/modules/ctools/tests/ctools_export_test/ctools_export.test new file mode 100644 index 000000000..1accfd740 --- /dev/null +++ b/sites/all/modules/ctools/tests/ctools_export_test/ctools_export.test @@ -0,0 +1,215 @@ + 'CTools export CRUD tests', + 'description' => 'Test the CRUD functionality for the ctools export system.', + 'group' => 'Chaos Tools Suite', + ); + } + + protected function setUp() { + parent::setUp('ctools_export_test'); + $this->resetAll(); + } + + /** + * Tests CRUD operation: Load. + */ + function testCrudExportLoad() { + $loaded_export = ctools_export_crud_load('ctools_export_test', 'database_test'); + + $expected_export = new stdClass(); + $expected_export->machine = 'database_test'; + $expected_export->title = 'Database test'; + $expected_export->number = 0; + $expected_export->data = array( + 'test_1' => 'Test 1', + 'test_2' => 'Test 2', + ); + $expected_export->table = 'ctools_export_test'; + $expected_export->export_type = EXPORT_IN_DATABASE; + $expected_export->type = 'Normal'; + + $this->assertEqual($expected_export, $loaded_export, 'An exportable object has been loaded correctly from the database.'); + } + + /** + * Tests CRUD operation: Load multiple. + */ + function testCrudExportLoadMultiple() { + $exportable_names = array('database_test', 'overridden_test', 'default_test'); + $loaded_exports = ctools_export_crud_load_multiple('ctools_export_test', $exportable_names); + + $this->assertEqual(count($loaded_exports), 3, 'All exportables have been loaded.'); + } + + /** + * Tests CRUD operation: Load all. + */ + function testCrudExportLoadAll() { + $loaded_exports = ctools_export_crud_load_all('ctools_export_test'); + + $this->assertEqual(count($loaded_exports), 3, 'All exportables have been loaded.'); + } + + /** + * Tests CRUD operation: Save. + */ + 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.'); + + ctools_export_crud_save('ctools_export_test', $default_export); + + // Clear the static cache. + ctools_export_load_object_reset('ctools_export_test'); + + $overridden_export = ctools_export_crud_load('ctools_export_test', 'default_test'); + + $this->assertTrue($overridden_export->export_type === 3, 'The loaded exportable is overridden in the database.'); + } + + /** + * Tests CRUD operation: New. + */ + function testCrudExportNew() { + // Default exportable with defualt values. + $new_export = ctools_export_crud_new('ctools_export_test'); + + $expected_export = new stdClass(); + $expected_export->machine = ''; + $expected_export->title = ''; + $expected_export->number = 0; + $expected_export->data = NULL; + $expected_export->export_type = NULL; + $expected_export->type = 'Local'; + + $this->assertEqual($expected_export, $new_export, 'An exportable with default values is created.'); + + // Default exportable without default values. + $new_export = ctools_export_crud_new('ctools_export_test', FALSE); + + $expected_export = new stdClass(); + $expected_export->machine = ''; + $expected_export->title = ''; + $expected_export->number = NULL; + $expected_export->data = NULL; + + $this->assertEqual($expected_export, $new_export, 'An exportable without default values has been created.'); + } + + /** + * Tests CRUD operation: Revert. + */ + function testCrudExportRevert() { + // Load exportable, will come from database. + $original_export = ctools_export_crud_load('ctools_export_test', 'overridden_test'); + + $this->assertTrue($original_export->export_type === 3, 'Loaded export is overridden.'); + + $machine = $original_export->machine; + ctools_export_crud_delete('ctools_export_test', $original_export); + + $result = db_query("SELECT machine FROM {ctools_export_test} WHERE machine = :machine", array(':machine' => $machine))->fetchField(); + + $this->assertFalse($result, 'The exportable object has been removed from the database.'); + + // Clear the static cache. + ctools_export_load_object_reset('ctools_export_test'); + + // Reload the same object. + $default_export = ctools_export_crud_load('ctools_export_test', 'overridden_test'); + + // 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. + $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() { + // 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); + + $machine = $new_export->machine; + ctools_export_crud_delete('ctools_export_test', $new_export); + $result = ctools_export_crud_load('ctools_export_test', $machine); + + $this->assertFalse($result, 'The new exportable has been removed from the database.'); + + // Load the database only exportable. + $database_export = ctools_export_crud_load('ctools_export_test', 'database_test'); + + $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); + + $this->assertFalse($result, 'The database exportable has been removed from the database.'); + } + + /** + * Tests CRUD operation: Set status. + */ + 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); + ctools_export_load_object_reset('ctools_export_test'); + $disabled_export = ctools_export_crud_load('ctools_export_test', 'database_test'); + + $this->assertTrue($disabled_export->disabled, 'The database only exportable has been disabled.'); + + ctools_export_crud_enable('ctools_export_test', $disabled_export); + ctools_export_load_object_reset('ctools_export_test'); + $enabled_export = ctools_export_crud_load('ctools_export_test', 'database_test'); + + $this->assertTrue(empty($enabled_export->disabled), 'The database only exportable has been enabled.'); + + // Overridden object. + $overridden_export = ctools_export_crud_load('ctools_export_test', 'overridden_test'); + ctools_export_crud_disable('ctools_export_test', $overridden_export); + ctools_export_load_object_reset('ctools_export_test'); + $disabled_export = ctools_export_crud_load('ctools_export_test', 'overridden_test'); + + $this->assertTrue($disabled_export->disabled, 'The overridden exportable has been disabled.'); + + ctools_export_crud_enable('ctools_export_test', $disabled_export); + ctools_export_load_object_reset('ctools_export_test'); + $enabled_export = ctools_export_crud_load('ctools_export_test', 'overridden_test'); + + $this->assertTrue(empty($enabled_export->disabled), 'The overridden exportable has been enabled.'); + + // Default object. + $default_export = ctools_export_crud_load('ctools_export_test', 'default_test'); + ctools_export_crud_disable('ctools_export_test', $default_export); + ctools_export_load_object_reset('ctools_export_test'); + $disabled_export = ctools_export_crud_load('ctools_export_test', 'default_test'); + + $this->assertTrue($disabled_export->disabled, 'The default exportable has been disabled.'); + + ctools_export_crud_enable('ctools_export_test', $disabled_export); + ctools_export_load_object_reset('ctools_export_test'); + $enabled_export = ctools_export_crud_load('ctools_export_test', 'default_test'); + + $this->assertTrue(empty($enabled_export->disabled), 'The default exportable has been enabled.'); + } + +} diff --git a/sites/all/modules/ctools/tests/ctools_export_test/ctools_export_test.default_ctools_export_tests.inc b/sites/all/modules/ctools/tests/ctools_export_test/ctools_export_test.default_ctools_export_tests.inc new file mode 100644 index 000000000..9f2dd6c6b --- /dev/null +++ b/sites/all/modules/ctools/tests/ctools_export_test/ctools_export_test.default_ctools_export_tests.inc @@ -0,0 +1,31 @@ +disabled = FALSE; /* Edit this to true to make a default export_test disabled initially */ + $ctools_export_test->api_version = 1; + $ctools_export_test->machine = 'overridden_test'; + $ctools_export_test->title = 'Overridden test'; + $ctools_export_test->number = 1; + $ctools_export_test->data = array( + 'test_1' => 'Test 1', + 'test_2' => 'Test 2', + ); + $ctools_export_tests['overridden_test'] = $ctools_export_test; + + $ctools_export_test = new stdClass(); + $ctools_export_test->disabled = FALSE; /* Edit this to true to make a default export_test disabled initially */ + $ctools_export_test->api_version = 1; + $ctools_export_test->machine = 'default_test'; + $ctools_export_test->title = 'Default test'; + $ctools_export_test->number = 2; + $ctools_export_test->data = ''; + $ctools_export_tests['default_test'] = $ctools_export_test; + + return $ctools_export_tests; +} diff --git a/sites/all/modules/ctools/tests/ctools_export_test/ctools_export_test.info b/sites/all/modules/ctools/tests/ctools_export_test/ctools_export_test.info new file mode 100644 index 000000000..e016aeb5d --- /dev/null +++ b/sites/all/modules/ctools/tests/ctools_export_test/ctools_export_test.info @@ -0,0 +1,16 @@ +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 2015-08-19 +version = "7.x-1.9" +core = "7.x" +project = "ctools" +datestamp = "1440020680" + diff --git a/sites/all/modules/ctools/tests/ctools_export_test/ctools_export_test.install b/sites/all/modules/ctools/tests/ctools_export_test/ctools_export_test.install new file mode 100644 index 000000000..2eb54ca39 --- /dev/null +++ b/sites/all/modules/ctools/tests/ctools_export_test/ctools_export_test.install @@ -0,0 +1,86 @@ + 'CTools export test data table', + 'export' => array( + 'key' => 'machine', + 'identifier' => 'ctools_export_test', + 'default hook' => 'default_ctools_export_tests', + 'bulk export' => TRUE, + 'api' => array( + 'owner' => 'ctools_export_test', + 'api' => 'default_ctools_export_tests', + 'minimum_version' => 1, + 'current_version' => 1, + ), + ), + 'fields' => array( + 'machine' => array( + 'description' => "The unique machine name (required by ctools).", + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + 'default' => '', + ), + 'title' => array( + 'description' => "The human readable title.", + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + 'default' => '', + ), + 'number' => array( + 'description' => "A number.", + 'type' => 'int', + 'not null' => TRUE, + 'default' => 0, + ), + 'data' => array( + 'type' => 'blob', + 'description' => "A serialized array of data.", + 'serialize' => TRUE, + 'serialized default' => 'a:0:{}', + ), + ), + 'primary key' => array('machine'), + ); + + return $schema; +} + +/** + * Implments hook_install(); + */ +function ctools_export_test_install() { + $ctools_export_tests = array(); + // Put this default in the database only (no default). + $ctools_export_test = new stdClass(); + $ctools_export_test->machine = 'database_test'; + $ctools_export_test->title = 'Database test'; + $ctools_export_test->number = 0; + $ctools_export_test->data = array( + 'test_1' => 'Test 1', + 'test_2' => 'Test 2', + ); + $ctools_export_tests['database_test'] = $ctools_export_test; + + // Put this default in the database, so we have this in code and in the database. + $ctools_export_test = new stdClass(); + $ctools_export_test->machine = 'overridden_test'; + $ctools_export_test->title = 'Overridden test'; + $ctools_export_test->number = 1; + $ctools_export_test->data = array( + 'test_1' => 'Test 1', + 'test_2' => 'Test 2', + ); + $ctools_export_tests['overridden_test'] = $ctools_export_test; + + foreach ($ctools_export_tests as $ctools_export_test) { + // Save the record to the database. + drupal_write_record('ctools_export_test', $ctools_export_test); + } +} diff --git a/sites/all/modules/ctools/tests/ctools_export_test/ctools_export_test.module b/sites/all/modules/ctools/tests/ctools_export_test/ctools_export_test.module new file mode 100644 index 000000000..80f1adbb3 --- /dev/null +++ b/sites/all/modules/ctools/tests/ctools_export_test/ctools_export_test.module @@ -0,0 +1,10 @@ + 1); + } +} diff --git a/sites/all/modules/ctools/tests/ctools_plugin_test.info b/sites/all/modules/ctools/tests/ctools_plugin_test.info new file mode 100644 index 000000000..15a510b62 --- /dev/null +++ b/sites/all/modules/ctools/tests/ctools_plugin_test.info @@ -0,0 +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 2015-08-19 +version = "7.x-1.9" +core = "7.x" +project = "ctools" +datestamp = "1440020680" + diff --git a/sites/all/modules/ctools/tests/ctools_plugin_test.module b/sites/all/modules/ctools/tests/ctools_plugin_test.module new file mode 100644 index 000000000..567f6e73d --- /dev/null +++ b/sites/all/modules/ctools/tests/ctools_plugin_test.module @@ -0,0 +1,72 @@ + array( + 'defaults' => array( + 'bool' => true, + 'string' => 'string', + 'array' => array('some value'), + ), + ), + 'cached' => array( + 'cache' => TRUE, + 'classes' => array( + 'handler', + ), + ), + 'not_cached' => array( + 'cache' => FALSE, + 'classes' => array( + 'handler', + ), + ), + 'big_hook_cached' => array( + 'cache' => TRUE, + 'use hooks' => TRUE, + 'classes' => array( + 'handler', + ), + ), + 'big_hook_not_cached' => array( + 'cache' => FALSE, + 'use hooks' => TRUE, + 'classes' => array( + 'handler', + ), + ), + ); +} + +function ctools_plugin_test_ctools_plugin_test_big_hook_cached() { + return array( + 'test1' => array( + 'function' => 'ctools_plugin_test_hook_cached_test', + 'handler' => 'class1', + ), + ); +} + +function ctools_plugin_test_ctools_plugin_test_big_hook_not_cached() { + return array( + 'test1' => array( + 'function' => 'ctools_plugin_test_hook_not_cached_test', + 'class' => 'class1', + ), + ); +} + +function ctools_plugin_test_hook_cached_test() {} +function ctools_plugin_test_hook_not_cached_test() {} diff --git a/sites/all/modules/ctools/tests/math_expression.test b/sites/all/modules/ctools/tests/math_expression.test new file mode 100644 index 000000000..730e079a5 --- /dev/null +++ b/sites/all/modules/ctools/tests/math_expression.test @@ -0,0 +1,129 @@ + '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))")); + } +} diff --git a/sites/all/modules/ctools/tests/math_expression_stack.test b/sites/all/modules/ctools/tests/math_expression_stack.test new file mode 100644 index 000000000..8143a55b8 --- /dev/null +++ b/sites/all/modules/ctools/tests/math_expression_stack.test @@ -0,0 +1,63 @@ + '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()); + + } +} diff --git a/sites/all/modules/ctools/tests/object_cache.test b/sites/all/modules/ctools/tests/object_cache.test new file mode 100644 index 000000000..8791d7e70 --- /dev/null +++ b/sites/all/modules/ctools/tests/object_cache.test @@ -0,0 +1,46 @@ + 'Ctools object cache storage', + 'description' => 'Verify that objects are written, readable and lockable.', + 'group' => 'Chaos Tools Suite', + ); + } + + public function setUp() { + // Additionally enable ctools module. + parent::setUp('ctools'); + } + + public function testObjectStorage() { + $account1 = $this->drupalCreateUser(array()); + $this->drupalLogin($account1); + + $data = array( + 'test1' => 'foobar', + ); + + ctools_include('object-cache'); + ctools_object_cache_set('testdata', 'one', $data); + $this->assertEqual($data, ctools_object_cache_get('testdata', 'one'), 'Object cache data successfully stored'); + + // 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. + } +} diff --git a/sites/all/modules/ctools/tests/plugins/cached/ctoolsCachedPluginArray.class.php b/sites/all/modules/ctools/tests/plugins/cached/ctoolsCachedPluginArray.class.php new file mode 100644 index 000000000..ea087fa63 --- /dev/null +++ b/sites/all/modules/ctools/tests/plugins/cached/ctoolsCachedPluginArray.class.php @@ -0,0 +1,7 @@ + 'ctools_plugin_test_plugin_array_cached_test', + 'handler' => array( + 'class' => 'ctoolsCachedPluginArray', + ), +); + +/** + * Plugin array function plugin. + */ +function ctools_plugin_test_plugin_array_cached_test() {} diff --git a/sites/all/modules/ctools/tests/plugins/cached/plugin_array2.inc b/sites/all/modules/ctools/tests/plugins/cached/plugin_array2.inc new file mode 100644 index 000000000..e6676154d --- /dev/null +++ b/sites/all/modules/ctools/tests/plugins/cached/plugin_array2.inc @@ -0,0 +1,20 @@ + 'ctools_plugin_test_plugin_array2_cached_test', + 'handler' => array( + 'class' => 'ctoolsCachedPluginArray2', + ), +); + +/** + * Plugin array function plugin. + */ +function ctools_plugin_test_plugin_array2_cached_test() {} diff --git a/sites/all/modules/ctools/tests/plugins/cached/plugin_array_dne.inc b/sites/all/modules/ctools/tests/plugins/cached/plugin_array_dne.inc new file mode 100644 index 000000000..e3d3bfb90 --- /dev/null +++ b/sites/all/modules/ctools/tests/plugins/cached/plugin_array_dne.inc @@ -0,0 +1,15 @@ + 'ctools_plugin_test_plugin_array_dne_cached_test', + 'handler' => array( + 'class' => 'ctoolsCachedPluginArrayDNE', + ), +); diff --git a/sites/all/modules/ctools/tests/plugins/not_cached/ctoolsNotCachedPluginArray.class.php b/sites/all/modules/ctools/tests/plugins/not_cached/ctoolsNotCachedPluginArray.class.php new file mode 100644 index 000000000..422a7b34c --- /dev/null +++ b/sites/all/modules/ctools/tests/plugins/not_cached/ctoolsNotCachedPluginArray.class.php @@ -0,0 +1,7 @@ + 'ctools_plugin_test_plugin_array_not_cached_test', + 'handler' => array( + 'class' => 'ctoolsNotCachedPluginArray', + ), +); + +/** + * Plugin array function plugin. + */ +function ctools_plugin_test_plugin_array_not_cached_test() {} diff --git a/sites/all/modules/ctools/tests/plugins/not_cached/plugin_array2.inc b/sites/all/modules/ctools/tests/plugins/not_cached/plugin_array2.inc new file mode 100644 index 000000000..06b817571 --- /dev/null +++ b/sites/all/modules/ctools/tests/plugins/not_cached/plugin_array2.inc @@ -0,0 +1,20 @@ + 'ctools_plugin_test_plugin_array2_not_cached_test', + 'handler' => array( + 'class' => 'ctoolsNotCachedPluginArray2', + ), +); + +/** + * Plugin array function plugin. + */ +function ctools_plugin_test_plugin_array2_not_cached_test() {} diff --git a/sites/all/modules/ctools/tests/plugins/not_cached/plugin_array_dne.inc b/sites/all/modules/ctools/tests/plugins/not_cached/plugin_array_dne.inc new file mode 100644 index 000000000..1f19d2a44 --- /dev/null +++ b/sites/all/modules/ctools/tests/plugins/not_cached/plugin_array_dne.inc @@ -0,0 +1,15 @@ + 'ctools_plugin_test_plugin_array_dne_not_cached_test', + 'handler' => array( + 'class' => 'ctoolsNotCachedPluginArrayDNE', + ), +); -- cgit v1.2.3