1 |
7fe061e8
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Contains simpletests making sure entity_token integration works.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Testing that tokens can be used in link titles
|
10 |
|
|
*/
|
11 |
|
|
class LinkEntityTokenTest extends LinkBaseTestClass {
|
12 |
|
|
|
13 |
|
|
public static function getInfo() {
|
14 |
|
|
return array(
|
15 |
|
|
'name' => 'Link entity tokens test',
|
16 |
|
|
'description' => 'Tests that a link field appears properly in entity tokens',
|
17 |
|
|
'group' => 'Link',
|
18 |
|
|
'dependencies' => array('token', 'entity', 'entity_token'),
|
19 |
|
|
);
|
20 |
|
|
}
|
21 |
|
|
|
22 |
|
|
function setUp($modules = array()) {
|
23 |
|
|
parent::setUp(array('token', 'entity', 'entity_token'));
|
24 |
|
|
}
|
25 |
|
|
|
26 |
|
|
/**
|
27 |
|
|
* Creates a link field, fills it, then uses a loaded node to test tokens.
|
28 |
|
|
*/
|
29 |
|
|
function testFieldTokenNodeLoaded() {
|
30 |
|
|
// create field
|
31 |
|
|
$settings = array(
|
32 |
|
|
'instance[settings][enable_tokens]' => 0,
|
33 |
|
|
);
|
34 |
|
|
$field_name = $this->createLinkField('page',
|
35 |
|
|
$settings);
|
36 |
|
|
|
37 |
|
|
// create page form
|
38 |
|
|
$this->drupalGet('node/add/page');
|
39 |
|
|
//$field_name = 'field_' . $name;
|
40 |
|
|
$this->assertField($field_name . '[und][0][title]', 'Title found');
|
41 |
|
|
$this->assertField($field_name . '[und][0][url]', 'URL found');
|
42 |
|
|
|
43 |
|
|
$token_url_tests = array(
|
44 |
|
|
1 => array(
|
45 |
|
|
'href' => 'http://example.com/' . $this->randomName(),
|
46 |
|
|
'label' => $this->randomName(),
|
47 |
|
|
),
|
48 |
|
|
2 => array(
|
49 |
|
|
'href' => 'http://example.com/' . $this->randomName() . '?property=value',
|
50 |
|
|
'label' => $this->randomName(),
|
51 |
|
|
),
|
52 |
|
|
3 => array(
|
53 |
|
|
'href' => 'http://example.com/' . $this->randomName() . '#position',
|
54 |
|
|
'label' => $this->randomName(),
|
55 |
|
|
),
|
56 |
|
|
4 => array(
|
57 |
|
|
'href' => 'http://example.com/' . $this->randomName() . '#lower?property=value2',
|
58 |
|
|
'label' => $this->randomName(),
|
59 |
|
|
),
|
60 |
|
|
);
|
61 |
|
|
//$this->assert('pass', '<pre>' . print_r($token_url_tests, TRUE) . '<pre>');
|
62 |
|
|
|
63 |
|
|
foreach ($token_url_tests as &$input) {
|
64 |
|
|
$this->drupalGet('node/add/page');
|
65 |
|
|
|
66 |
|
|
$edit = array(
|
67 |
|
|
'title' => $input['label'],
|
68 |
|
|
$field_name . '[und][0][title]' => $input['label'],
|
69 |
|
|
$field_name . '[und][0][url]' => $input['href'],
|
70 |
|
|
);
|
71 |
|
|
$this->drupalPost(NULL, $edit, t('Save'));
|
72 |
|
|
$url = $this->getUrl();
|
73 |
|
|
$input['url'] = $url;
|
74 |
|
|
}
|
75 |
|
|
|
76 |
|
|
// change to anonymous user
|
77 |
|
|
$this->drupalLogout();
|
78 |
|
|
|
79 |
|
|
foreach ($token_url_tests as $index => $input2) {
|
80 |
|
|
$node = node_load($index);
|
81 |
|
|
$this->assertNotEqual(NULL, $node, "Do we have a node?");
|
82 |
|
|
$this->assertEqual($node->nid, $index, "Test that we have a node.");
|
83 |
|
|
$token_name = '[node:' . str_replace('_', '-', $field_name) . ':url]';
|
84 |
|
|
$assert_data = token_replace($token_name,
|
85 |
|
|
array('node' => $node));
|
86 |
|
|
$this->assertEqual($input2['href'], $assert_data, "Test that the url token has been set to " . $input2['href'] . ' - ' . $assert_data);
|
87 |
|
|
}
|
88 |
|
|
}
|
89 |
|
|
|
90 |
|
|
/**
|
91 |
|
|
* Creates a link field, fills it, then uses a loaded and node_view'd node to test tokens.
|
92 |
|
|
*/
|
93 |
|
|
function testFieldTokenNodeViewed() {
|
94 |
|
|
// create field
|
95 |
|
|
$settings = array(
|
96 |
|
|
'instance[settings][enable_tokens]' => 0,
|
97 |
|
|
);
|
98 |
|
|
$field_name = $this->createLinkField('page',
|
99 |
|
|
$settings);
|
100 |
|
|
|
101 |
|
|
// create page form
|
102 |
|
|
$this->drupalGet('node/add/page');
|
103 |
|
|
//$field_name = 'field_' . $name;
|
104 |
|
|
$this->assertField($field_name . '[und][0][title]', 'Title found');
|
105 |
|
|
$this->assertField($field_name . '[und][0][url]', 'URL found');
|
106 |
|
|
|
107 |
|
|
$token_url_tests = array(
|
108 |
|
|
1 => array(
|
109 |
|
|
'href' => 'http://example.com/' . $this->randomName(),
|
110 |
|
|
'label' => $this->randomName(),
|
111 |
|
|
),
|
112 |
|
|
2 => array(
|
113 |
|
|
'href' => 'http://example.com/' . $this->randomName() . '?property=value',
|
114 |
|
|
'label' => $this->randomName(),
|
115 |
|
|
),
|
116 |
|
|
3 => array(
|
117 |
|
|
'href' => 'http://example.com/' . $this->randomName() . '#position',
|
118 |
|
|
'label' => $this->randomName(),
|
119 |
|
|
),
|
120 |
|
|
4 => array(
|
121 |
|
|
'href' => 'http://example.com/' . $this->randomName() . '#lower?property=value2',
|
122 |
|
|
'label' => $this->randomName(),
|
123 |
|
|
),
|
124 |
|
|
);
|
125 |
|
|
//$this->assert('pass', '<pre>' . print_r($token_url_tests, TRUE) . '<pre>');
|
126 |
|
|
|
127 |
|
|
foreach ($token_url_tests as &$input) {
|
128 |
|
|
$this->drupalGet('node/add/page');
|
129 |
|
|
|
130 |
|
|
$edit = array(
|
131 |
|
|
'title' => $input['label'],
|
132 |
|
|
$field_name . '[und][0][title]' => $input['label'],
|
133 |
|
|
$field_name . '[und][0][url]' => $input['href'],
|
134 |
|
|
);
|
135 |
|
|
$this->drupalPost(NULL, $edit, t('Save'));
|
136 |
|
|
$url = $this->getUrl();
|
137 |
|
|
$input['url'] = $url;
|
138 |
|
|
}
|
139 |
|
|
|
140 |
|
|
// change to anonymous user
|
141 |
|
|
$this->drupalLogout();
|
142 |
|
|
|
143 |
|
|
foreach ($token_url_tests as $index => $input2) {
|
144 |
|
|
$node = node_load($index);
|
145 |
|
|
$node_array = node_view($node, 'full');
|
146 |
|
|
$this->assertNotEqual(NULL, $node, "Do we have a node?");
|
147 |
|
|
$this->assertEqual($node->nid, $index, "Test that we have a node.");
|
148 |
|
|
$token_name = '[node:' . str_replace('_', '-', $field_name) . ':url]';
|
149 |
|
|
$assert_data = token_replace($token_name,
|
150 |
|
|
array('node' => $node));
|
151 |
|
|
$this->assertEqual($input2['href'], $assert_data, "Test that the url token has been set to " . $input2['href'] . ' - ' . $assert_data);
|
152 |
|
|
}
|
153 |
|
|
}
|
154 |
|
|
|
155 |
|
|
} |