Verified Commit c63d29bd authored by Juraj Nemec's avatar Juraj Nemec
Browse files

Issue #2218647 by poker10, swim, Patil_kunal27: [D7] Undefined property:...

Issue #2218647 by poker10, swim, Patil_kunal27: [D7] Undefined property: stdClass::$nid in node_tokens()
parent 11082e25
Loading
Loading
Loading
Loading
+20 −0
Changes for modules/node/node.test: 20 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -2554,6 +2554,26 @@ class NodeTokenReplaceTestCase extends DrupalWebTestCase {
      $this->assertEqual($output, $expected, format_string('Sanitized node token %token replaced.', array('%token' => $input)));
    }

    // Test if the node without nid gets correct tokens (e.g. unsaved node).
    $new_node_without_nid = clone $node;
    unset($new_node_without_nid->nid);

    // Update tokens values which should be empty
    $tests['[node:nid]'] = '';
    $tests['[node:url]'] = '';
    $tests['[node:edit-url]'] = '';

    // Generate and test sanitized tokens.
    foreach ($tests as $input => $expected) {
      $output = token_replace($input, array('node' => $new_node_without_nid), array('language' => $language));
      $this->assertEqual($output, $expected, format_string('Sanitized node token %token replaced.', array('%token' => $input)));
    }

    // Revert tokens values
    $tests['[node:nid]'] = $node->nid;
    $tests['[node:url]'] = url('node/' . $node->nid, $url_options);
    $tests['[node:edit-url]'] = url('node/' . $node->nid . '/edit', $url_options);

    // Generate and test unsanitized tokens.
    $tests['[node:title]'] = $node->title;
    $tests['[node:body]'] = $node->body[$langcode][0]['value'];
+3 −3
Changes for modules/node/node.tokens.inc: 3 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -109,7 +109,7 @@ function node_tokens($type, $tokens, array $data = array(), array $options = arr
      switch ($name) {
        // Simple key values on the node.
        case 'nid':
          $replacements[$original] = $node->nid;
          $replacements[$original] = isset($node->nid) ? $node->nid : '';
          break;

        case 'vid':
@@ -168,11 +168,11 @@ function node_tokens($type, $tokens, array $data = array(), array $options = arr
          break;

        case 'url':
          $replacements[$original] = url('node/' . $node->nid, $url_options);
          $replacements[$original] = isset($node->nid) ? url('node/' . $node->nid, $url_options) : '';
          break;

        case 'edit-url':
          $replacements[$original] = url('node/' . $node->nid . '/edit', $url_options);
          $replacements[$original] = isset($node->nid) ? url('node/' . $node->nid . '/edit', $url_options) : '';
          break;

        // Default values for the chained tokens handled below.