From 9ef28d449ed24a124556f4e756ad7d249a9bb875 Mon Sep 17 00:00:00 2001 Message-Id: <9ef28d449ed24a124556f4e756ad7d249a9bb875.1344844955.git.dmitriy.trt@gmail.com> From: "Dmitriy.trt" Date: Mon, 13 Aug 2012 15:02:29 +0700 Subject: [PATCH] Issue #1727804: Fix keywords parsing pattern and add test for it. --- includes/context.inc | 2 +- tests/context.test | 58 +++++++++++++++++++++++++++++++++++++++++ tests/ctools_plugin_test.info | 1 + 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/tests/context.test b/tests/context.test new file mode 100644 index 0000000..b5f6fb1 --- /dev/null +++ b/tests/context.test @@ -0,0 +1,58 @@ + '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: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/tests/ctools_plugin_test.info b/tests/ctools_plugin_test.info index 1d47997..11f4aab 100644 --- a/tests/ctools_plugin_test.info +++ b/tests/ctools_plugin_test.info @@ -6,4 +6,5 @@ dependencies[] = ctools files[] = ctools.plugins.test files[] = object_cache.test files[] = css.test +files[] = context.test hidden = TRUE -- 1.7.10.4