summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn C Fiala2011-02-22 06:40:18 (GMT)
committer John C Fiala2011-02-22 06:40:18 (GMT)
commit87ae9c7540ec73dd740330bc05873e38e9ed63b7 (patch)
tree2cb434629a56b48fef960ac8458a6a44e2cb5510
parent8ca7ee52f033d1549a0f7997437da794a85414b2 (diff)
bug report #462538 by tim.plunkett,dboulet:Allow User Entered Tokens setting should not be required to use tokens on the field settings page.
-rw-r--r--link.inc6
-rw-r--r--tests/link.token.test69
2 files changed, 64 insertions, 11 deletions
diff --git a/link.inc b/link.inc
index a91f298..e4c0bd5 100644
--- a/link.inc
+++ b/link.inc
@@ -74,7 +74,7 @@ function _link_sanitize(&$item, $delta, &$field, &$node) {
}
// Replace URL tokens.
- if (module_exists('token') && $field['enable_tokens']) {
+ if ($field['enable_tokens'] && module_exists('token')) {
// Load the node if necessary for nodes in views.
$token_node = isset($node->nid) ? node_load($node->nid) : $node;
$item['url'] = token_replace($item['url'], 'node', $token_node);
@@ -122,7 +122,7 @@ function _link_sanitize(&$item, $delta, &$field, &$node) {
$title = $item['title'];
}
// Replace tokens. - originally we only did it for value titles.
- if ($field['enable_tokens'] && module_exists('token')) {
+ if (($field['title'] == 'value' || $field['enable_tokens']) && module_exists('token')) {
// Load the node if necessary for nodes in views.
$token_node = isset($node->nid) ? node_load($node->nid) : $node;
$title = filter_xss(token_replace($title, 'node', $token_node), array('b', 'br', 'code', 'em', 'i', 'img', 'span', 'strong', 'sub', 'sup', 'tt', 'u'));
@@ -173,7 +173,7 @@ function _link_sanitize(&$item, $delta, &$field, &$node) {
}
// Handle "title" link attribute
- if ($field['enable_tokens'] && !empty($item['attributes']['title']) && module_exists('token')) {
+ if (!empty($item['attributes']['title']) && module_exists('token')) {
// Load the node (necessary for nodes in views).
$token_node = isset($node->nid) ? node_load($node->nid) : $node;
$item['attributes']['title'] = token_replace($item['attributes']['title'], 'node', $token_node);
diff --git a/tests/link.token.test b/tests/link.token.test
index 4b9606e..36564a4 100644
--- a/tests/link.token.test
+++ b/tests/link.token.test
@@ -59,7 +59,7 @@ class LinkTokenTest extends ContentCrudTestCase {
$this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save'));
$this->drupalPost(NULL, array(
'title' => 'required',
- 'enable_tokens' => 1), t('Save field settings'));
+ 'enable_tokens' => TRUE), t('Save field settings'));
// Is field created?
$this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added');
@@ -114,7 +114,7 @@ class LinkTokenTest extends ContentCrudTestCase {
$this->drupalPost(NULL, array(
'title' => 'value',
'title_value' => $name . ' [type]',
- 'enable_tokens' => TRUE,
+ 'enable_tokens' => FALSE,
), t('Save field settings'));
// Is filed created?
@@ -171,7 +171,7 @@ class LinkTokenTest extends ContentCrudTestCase {
$this->drupalPost(NULL, array(
'title' => 'value',
'title_value' => $name . ' [title-raw]',
- 'enable_tokens' => TRUE,
+ 'enable_tokens' => FALSE,
), t('Save field settings'));
// Is field created?
@@ -226,7 +226,7 @@ class LinkTokenTest extends ContentCrudTestCase {
$url_type = str_replace('_', '-', $this->content_types[0]->type);
$edit = array('attributes[title]' => '['. $field_name .'-url]',
- 'enable_tokens' => TRUE);
+ 'enable_tokens' => FALSE);
$this->drupalPost('admin/content/node-type/'. $url_type .'/fields/'. $field['field_name'],
$edit, t('Save field settings'));
@@ -286,7 +286,7 @@ class LinkTokenTest extends ContentCrudTestCase {
$url_type = str_replace('_', '-', $this->content_types[0]->type);
$edit = array('attributes[title]' => '['. $field_name .'-title]',
- 'enable_tokens' => TRUE);
+ 'enable_tokens' => FALSE);
$this->drupalPost('admin/content/node-type/'. $url_type .'/fields/'. $field['field_name'],
$edit, t('Save field settings'));
@@ -337,7 +337,7 @@ class LinkTokenTest extends ContentCrudTestCase {
$this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save'));
$this->drupalPost(NULL, array(
'title' => 'required',
- 'enable_tokens' => 1), t('Save field settings'));
+ 'enable_tokens' => TRUE), t('Save field settings'));
// Is field created?
$this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added');
@@ -373,6 +373,59 @@ class LinkTokenTest extends ContentCrudTestCase {
}
/**
+ * If 'enable_tokens' is off, then the url shouldn't be filtered through the token module.
+ */
+ function testUserTokenLinkCreateInURLFail() {
+ $account = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
+ $this->drupalLogin($account);
+
+ // create field
+ $name = strtolower($this->randomName());
+ $edit = array(
+ '_add_new_field[label]' => $name,
+ '_add_new_field[field_name]' => $name,
+ '_add_new_field[type]' => 'link',
+ '_add_new_field[widget_type]' => 'link',
+ );
+ $this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save'));
+ $this->drupalPost(NULL, array(
+ 'title' => 'required',
+ 'enable_tokens' => FALSE), t('Save field settings'));
+
+ // Is field created?
+ $this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added');
+
+ // create page form
+ $this->drupalGet('node/add/page');
+ $field_name = 'field_' . $name;
+ $this->assertField($field_name . '[0][title]', 'Title found');
+ $this->assertField($field_name . '[0][url]', 'URL found');
+
+ $input = array(
+ 'href' => 'http://example.com/' . $this->randomName(),
+ 'label' => $this->randomName(),
+ );
+
+ $this->drupalLogin($account);
+ $this->drupalGet('node/add/page');
+
+ $edit = array(
+ 'title' => $input['label'],
+ $field_name . '[0][title]' => $input['label'],
+ $field_name . '[0][url]' => $input['href'] . "/[type]",
+ );
+ $this->drupalPost(NULL, $edit, t('Save'));
+ $url = $this->getUrl();
+
+ // change to anonymous user
+ $this->drupalLogout();
+ $this->drupalGet($url);
+
+ $this->assertRaw(l($input['label'], $input['href'] .'/[type]'));
+ //$this->fail($this->content);
+ }
+
+ /**
* Trying to set the url to contain a token.
*/
function testUserTokenLinkCreateInURL2() {
@@ -390,7 +443,7 @@ class LinkTokenTest extends ContentCrudTestCase {
$this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save'));
$this->drupalPost(NULL, array(
'title' => 'required',
- 'enable_tokens' => 1), t('Save field settings'));
+ 'enable_tokens' => TRUE), t('Save field settings'));
// Is field created?
$this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added');
@@ -443,7 +496,7 @@ class LinkTokenTest extends ContentCrudTestCase {
$this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save'));
$this->drupalPost(NULL, array(
'title' => 'required',
- 'enable_tokens' => 1), t('Save field settings'));
+ 'enable_tokens' => TRUE), t('Save field settings'));
// Is field created?
$this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added');