diff options
Diffstat (limited to 'modules/taxonomy/taxonomy.test')
-rw-r--r-- | modules/taxonomy/taxonomy.test | 105 |
1 files changed, 55 insertions, 50 deletions
diff --git a/modules/taxonomy/taxonomy.test b/modules/taxonomy/taxonomy.test index a9b574c19..fd9df1f4f 100644 --- a/modules/taxonomy/taxonomy.test +++ b/modules/taxonomy/taxonomy.test @@ -916,12 +916,15 @@ class TaxonomyTokenReplaceTestCase extends TaxonomyWebTestCase { * Creates some terms and a node, then tests the tokens generated from them. */ function testTaxonomyTokenReplacement() { + global $language; + // Create two taxonomy terms. $term1 = $this->createTerm($this->vocabulary); $term2 = $this->createTerm($this->vocabulary); // Edit $term2, setting $term1 as parent. $edit = array(); + $edit['name'] = '<blink>Blinking Text</blink>'; $edit['parent[]'] = array($term1->tid); $this->drupalPost('taxonomy/term/' . $term2->tid . '/edit', $edit, t('Save')); @@ -931,57 +934,59 @@ class TaxonomyTokenReplaceTestCase extends TaxonomyWebTestCase { $edit[$this->instance['field_name'] . '[' . $this->langcode . '][]'] = $term2->tid; $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save')); - // Generate term token strings (before and after replacement) for term2. - $source = '[term:tid]'; - $source .= '[term:vid]'; - $source .= '[term:name]'; - $source .= '[term:description]'; - $source .= '[term:url]'; - $source .= '[term:node-count]'; - $source .= '[term:parent:name]'; - $source .= '[term:vocabulary:name]'; - - $target = $term2->tid; - $target .= $term2->vid; - $target .= check_plain($term2->name); - $target .= check_markup($term2->description, $term2->format); - $target .= url('taxonomy/term/' . $term2->tid, array('absolute' => TRUE)); - $target .= 1; - $target .= check_plain($term1->name); - $target .= check_plain($this->vocabulary->name); - - $result = token_replace($source, array('term' => $term2)); - $this->assertEqual(strcmp($target, $result), 0, t('Taxonomy term placeholder tokens replaced.')); - - // Generate vocabulary token strings (before and after replacement). - $source = '[vocabulary:vid]'; - $source .= '[vocabulary:name]'; - $source .= '[vocabulary:description]'; - $source .= '[vocabulary:node-count]'; - $source .= '[vocabulary:term-count]'; - - $target = $this->vocabulary->vid; - $target .= check_plain($this->vocabulary->name); - $target .= filter_xss($this->vocabulary->description); - $target .= 1; - $target .= 2; - - $result = token_replace($source, array('vocabulary' => $this->vocabulary)); - $this->assertEqual(strcmp($target, $result), 0, t('Taxonomy vocabulary placeholder tokens replaced.')); - - // Check that the results of token_generate are sanitized properly. This - // does NOT test the cleanliness of every token -- just that the $sanitize - // flag is being passed properly through the call stack and being handled - // correctly by a 'known' token, [term:name]. - $edit = array(); - $edit['name'] = '<blink>Blinking Text</blink>'; - $this->drupalPost('taxonomy/term/' . $term2->tid . '/edit', $edit, t('Save')); + // Generate and test sanitized tokens. + $tests = array(); + $tests['[term:tid]'] = $term2->tid; + $tests['[term:vid]'] = $term2->vid; + $tests['[term:name]'] = check_plain($term2->name); + $tests['[term:description]'] = check_markup($term2->description, $term2->format); + $tests['[term:url]'] = url('taxonomy/term/' . $term2->tid, array('absolute' => TRUE)); + $tests['[term:node-count]'] = 1; + $tests['[term:parent:name]'] = check_plain($term1->name); + $tests['[term:vocabulary:name]'] = check_plain($this->vocabulary->name); + + // Test to make sure that we generated something for each token. + $this->assertFalse(in_array(0, array_map('strlen', $tests)), t('No empty tokens generated.')); + + foreach ($tests as $input => $expected) { + $output = token_replace($input, array('term' => $term2), array('language' => $language)); + $this->assertFalse(strcmp($output, $expected), t('Sanitized taxonomy term token %token replaced.', array('%token' => $input))); + } + + // Generate and test unsanitized tokens. + $tests['[term:name]'] = $term2->name; + $tests['[term:description]'] = $term2->description; + $tests['[term:parent:name]'] = $term1->name; + $tests['[term:vocabulary:name]'] = $this->vocabulary->name; - $raw_tokens = array('name' => '[term:name]'); - $generated = token_generate('term', $raw_tokens, array('term' => $term2)); - $this->assertEqual(strcmp($generated['[term:name]'], check_plain($term2->name)), 0, t('Token sanitized.')); + foreach ($tests as $input => $expected) { + $output = token_replace($input, array('term' => $term2), array('language' => $language, 'sanitize' => FALSE)); + $this->assertFalse(strcmp($output, $expected), t('Unsanitized taxonomy term token %token replaced.', array('%token' => $input))); + } + + // Generate and test sanitized tokens. + $tests = array(); + $tests['[vocabulary:vid]'] = $this->vocabulary->vid; + $tests['[vocabulary:name]'] = check_plain($this->vocabulary->name); + $tests['[vocabulary:description]'] = filter_xss($this->vocabulary->description); + $tests['[vocabulary:node-count]'] = 1; + $tests['[vocabulary:term-count]'] = 2; - $generated = token_generate('term', $raw_tokens, array('term' => $term2), array('sanitize' => FALSE)); - $this->assertEqual(strcmp($generated['[term:name]'], $term2->name), 0, t('Unsanitized token generated properly.')); + // Test to make sure that we generated something for each token. + $this->assertFalse(in_array(0, array_map('strlen', $tests)), t('No empty tokens generated.')); + + foreach ($tests as $input => $expected) { + $output = token_replace($input, array('vocabulary' => $this->vocabulary), array('language' => $language)); + $this->assertFalse(strcmp($output, $expected), t('Sanitized taxonomy vocabulary token %token replaced.', array('%token' => $input))); + } + + // Generate and test unsanitized tokens. + $tests['[vocabulary:name]'] = $this->vocabulary->name; + $tests['[vocabulary:description]'] = $this->vocabulary->description; + + foreach ($tests as $input => $expected) { + $output = token_replace($input, array('vocabulary' => $this->vocabulary), array('language' => $language, 'sanitize' => FALSE)); + $this->assertFalse(strcmp($output, $expected), t('Unsanitized taxonomy vocabulary token %token replaced.', array('%token' => $input))); + } } } |