1 token.test | TokenNodeTestCase::testNodeTokens() |
File
- core/
modules/ simpletest/ tests/ token.test, line 458 - Test integration for the token module.
Class
Code
function testNodeTokens() {
$admin_user = $this->backdropCreateUser(array('create post content', 'create url aliases'));
$this->backdropLogin($admin_user);
$files = $this->backdropGetTestFiles('image');
$file = new File((array) $files[0]);
$file->uid = $admin_user->uid;
$file->save();
$node_title = $this->randomName();
$node_edit = array(
'title' => $node_title,
'path[auto]' => FALSE,
'path[alias]' => 'content/source-node',
'field_tags[und]' => 'foo, bar',
'field_image[und][0][fid]' => $file->fid,
);
$this->backdropPost('node/add/post', $node_edit, t('Save'));
$source_node = $this->backdropGetNodeByTitle($node_title);
$tokens = array(
'source' => NULL,
'source:nid' => NULL,
'log' => $source_node->log,
'url:path' => 'content/source-node',
'url:absolute' => url("node/{$source_node->nid}", array('absolute' => TRUE)),
'url:relative' => url("node/{$source_node->nid}", array('absolute' => FALSE)),
'url:unaliased:path' => "node/{$source_node->nid}",
'content-type' => 'Post',
'content-type:name' => 'Post',
'content-type:machine-name' => 'post',
'content-type:description' => "Add a blog post, news article, or press release.",
'content-type:node-count' => 2,
'content-type:edit-url' => url('admin/structure/types/manage/post', array('absolute' => TRUE)),
'field_image' => file_create_url($file->uri),
'field_tags' => 'foo, bar',
// Deprecated tokens.
//'tnid' => 0,
'type' => 'post',
'type-name' => 'Post',
'url:alias' => 'content/source-node',
);
$this->assertTokens('node', array('node' => $source_node), $tokens);
$translated_node = $this->backdropCreateNode(array(
'tnid' => $source_node->nid,
'type' => 'post',
));
$tokens = array(
'source' => $source_node->title,
'source:nid' => $source_node->nid,
'log' => '',
'url:path' => $translated_node->path['alias'],
'url:absolute' => url("node/{$translated_node->nid}", array('absolute' => TRUE)),
'url:relative' => url("node/{$translated_node->nid}", array('absolute' => FALSE)),
'url:unaliased:path' => "node/{$translated_node->nid}",
'content-type' => 'Post',
'content-type:name' => 'Post',
'content-type:machine-name' => 'post',
'content-type:description' => "Add a blog post, news article, or press release.",
'content-type:node-count' => 3,
'content-type:edit-url' => url('admin/structure/types/manage/post', array('absolute' => TRUE)),
// Deprecated tokens.
'type' => 'post',
'type-name' => 'Post',
'tnid' => $source_node->nid,
'url:alias' => $translated_node->path['alias'],
);
$this->assertTokens('node', array('node' => $translated_node), $tokens);
}