Révision 39a181a4
Ajouté par Assos Assos il y a environ 6 ans
drupal7/sites/all/modules/link/tests/link.entity_token.test | ||
---|---|---|
6 | 6 |
*/ |
7 | 7 |
|
8 | 8 |
/** |
9 |
* Testing that tokens can be used in link titles |
|
9 |
* Testing that tokens can be used in link titles.
|
|
10 | 10 |
*/ |
11 | 11 |
class LinkEntityTokenTest extends LinkBaseTestClass { |
12 | 12 |
|
13 |
/** |
|
14 |
* Get Info. |
|
15 |
*/ |
|
13 | 16 |
public static function getInfo() { |
14 | 17 |
return array( |
15 | 18 |
'name' => 'Link entity tokens test', |
... | ... | |
19 | 22 |
); |
20 | 23 |
} |
21 | 24 |
|
22 |
function setUp($modules = array()) { |
|
25 |
/** |
|
26 |
* Setup. |
|
27 |
*/ |
|
28 |
public function setUp($modules = array()) { |
|
23 | 29 |
parent::setUp(array('token', 'entity', 'entity_token')); |
24 | 30 |
} |
25 |
|
|
31 |
|
|
26 | 32 |
/** |
27 | 33 |
* Creates a link field, fills it, then uses a loaded node to test tokens. |
28 | 34 |
*/ |
29 |
function testFieldTokenNodeLoaded() { |
|
30 |
// create field
|
|
35 |
public function testFieldTokenNodeLoaded() {
|
|
36 |
// Create field.
|
|
31 | 37 |
$settings = array( |
32 | 38 |
'instance[settings][enable_tokens]' => 0, |
33 | 39 |
); |
34 | 40 |
$field_name = $this->createLinkField('page', |
35 |
$settings);
|
|
41 |
$settings); |
|
36 | 42 |
|
37 |
// create page form
|
|
43 |
// Create page form.
|
|
38 | 44 |
$this->drupalGet('node/add/page'); |
39 |
//$field_name = 'field_' . $name;
|
|
45 |
// $field_name = 'field_' . $name;.
|
|
40 | 46 |
$this->assertField($field_name . '[und][0][title]', 'Title found'); |
41 | 47 |
$this->assertField($field_name . '[und][0][url]', 'URL found'); |
42 | 48 |
|
... | ... | |
58 | 64 |
'label' => $this->randomName(), |
59 | 65 |
), |
60 | 66 |
); |
61 |
//$this->assert('pass', '<pre>' . print_r($token_url_tests, TRUE) . '<pre>');
|
|
62 |
|
|
67 |
// @codingStandardsIgnoreLine
|
|
68 |
// $this->assert('pass', '<pre>' . print_r($token_url_tests, TRUE) . '<pre>');. |
|
63 | 69 |
foreach ($token_url_tests as &$input) { |
64 | 70 |
$this->drupalGet('node/add/page'); |
65 |
|
|
71 |
|
|
66 | 72 |
$edit = array( |
67 | 73 |
'title' => $input['label'], |
68 | 74 |
$field_name . '[und][0][title]' => $input['label'], |
... | ... | |
73 | 79 |
$input['url'] = $url; |
74 | 80 |
} |
75 | 81 |
|
76 |
// change to anonymous user
|
|
82 |
// Change to anonymous user.
|
|
77 | 83 |
$this->drupalLogout(); |
78 |
|
|
84 |
|
|
79 | 85 |
foreach ($token_url_tests as $index => $input2) { |
80 | 86 |
$node = node_load($index); |
81 | 87 |
$this->assertNotEqual(NULL, $node, "Do we have a node?"); |
82 | 88 |
$this->assertEqual($node->nid, $index, "Test that we have a node."); |
83 | 89 |
$token_name = '[node:' . str_replace('_', '-', $field_name) . ':url]'; |
84 | 90 |
$assert_data = token_replace($token_name, |
85 |
array('node' => $node));
|
|
91 |
array('node' => $node)); |
|
86 | 92 |
$this->assertEqual($input2['href'], $assert_data, "Test that the url token has been set to " . $input2['href'] . ' - ' . $assert_data); |
87 | 93 |
} |
88 | 94 |
} |
89 |
|
|
95 |
|
|
90 | 96 |
/** |
91 |
* Creates a link field, fills it, then uses a loaded and node_view'd node to test tokens. |
|
97 |
* Field Token Node Viewed. |
|
98 |
* |
|
99 |
* Creates a link field, fills it, then uses a loaded and node_view'd node to |
|
100 |
* test tokens. |
|
92 | 101 |
*/ |
93 |
function testFieldTokenNodeViewed() { |
|
94 |
// create field
|
|
102 |
public function testFieldTokenNodeViewed() {
|
|
103 |
// Create field.
|
|
95 | 104 |
$settings = array( |
96 | 105 |
'instance[settings][enable_tokens]' => 0, |
97 | 106 |
); |
98 | 107 |
$field_name = $this->createLinkField('page', |
99 |
$settings);
|
|
108 |
$settings); |
|
100 | 109 |
|
101 |
// create page form
|
|
110 |
// Create page form.
|
|
102 | 111 |
$this->drupalGet('node/add/page'); |
103 |
//$field_name = 'field_' . $name;
|
|
112 |
// $field_name = 'field_' . $name;.
|
|
104 | 113 |
$this->assertField($field_name . '[und][0][title]', 'Title found'); |
105 | 114 |
$this->assertField($field_name . '[und][0][url]', 'URL found'); |
106 | 115 |
|
... | ... | |
122 | 131 |
'label' => $this->randomName(), |
123 | 132 |
), |
124 | 133 |
); |
125 |
//$this->assert('pass', '<pre>' . print_r($token_url_tests, TRUE) . '<pre>'); |
|
126 | 134 |
|
135 |
//@codingStandardsIgnoreLine |
|
136 |
// $this->assert('pass', '<pre>' . print_r($token_url_tests, TRUE) . '<pre>');. |
|
127 | 137 |
foreach ($token_url_tests as &$input) { |
128 | 138 |
$this->drupalGet('node/add/page'); |
129 |
|
|
139 |
|
|
130 | 140 |
$edit = array( |
131 | 141 |
'title' => $input['label'], |
132 | 142 |
$field_name . '[und][0][title]' => $input['label'], |
... | ... | |
137 | 147 |
$input['url'] = $url; |
138 | 148 |
} |
139 | 149 |
|
140 |
// change to anonymous user
|
|
150 |
// Change to anonymous user.
|
|
141 | 151 |
$this->drupalLogout(); |
142 |
|
|
152 |
|
|
143 | 153 |
foreach ($token_url_tests as $index => $input2) { |
144 | 154 |
$node = node_load($index); |
145 |
$node_array = node_view($node, 'full'); |
|
146 | 155 |
$this->assertNotEqual(NULL, $node, "Do we have a node?"); |
147 | 156 |
$this->assertEqual($node->nid, $index, "Test that we have a node."); |
148 | 157 |
$token_name = '[node:' . str_replace('_', '-', $field_name) . ':url]'; |
149 | 158 |
$assert_data = token_replace($token_name, |
150 |
array('node' => $node));
|
|
159 |
array('node' => $node)); |
|
151 | 160 |
$this->assertEqual($input2['href'], $assert_data, "Test that the url token has been set to " . $input2['href'] . ' - ' . $assert_data); |
152 | 161 |
} |
153 | 162 |
} |
154 |
|
|
155 |
} |
|
163 |
|
|
164 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules