| Commit | Line | Data |
|---|---|---|
| 811c2a65 | 1 | <?php |
| bba5c8a5 JF |
2 | // $Id$ |
| 3 | ||
| 4 | /** | |
| 5 | * @file | |
| 6 | * Contains simpletests making sure token integration works. | |
| 7 | */ | |
| 811c2a65 JF |
8 | |
| 9 | /** | |
| 10 | * Testing that tokens can be used in link titles | |
| 11 | */ | |
| 318da51e | 12 | class LinkTokenTest extends ContentCrudTestCase { |
| 811c2a65 | 13 | |
| 318da51e JF |
14 | public $permissions = array( |
| 15 | 'access content', | |
| 16 | 'administer content types', | |
| 17 | 'administer nodes', | |
| 18 | 'administer filters', | |
| 19 | 'access comments', | |
| 20 | 'post comments', | |
| 21 | 'post comments without approval', | |
| 22 | 'access administration pages', | |
| 23 | ); | |
| 24 | ||
| 811c2a65 JF |
25 | /** |
| 26 | * Implementation of getInfo(). | |
| 27 | */ | |
| 28 | function getInfo() { | |
| 29 | return array( | |
| 30 | 'name' => t('Link tokens - browser test'), | |
| 31 | 'description' => t('Tests including tokens in link titles, making sure they appear in node views. <strong>Requires <a href="@token_link">Token module</a>.</strong>'), | |
| 32 | 'group' => t('Link'), | |
| 33 | ); | |
| 34 | } | |
| 35 | ||
| 36 | /** | |
| 37 | * Implementation of setUp(). | |
| 38 | */ | |
| 39 | function setUp() { | |
| 40 | parent::setUp('content', 'link', 'token'); | |
| 41 | } | |
| 42 | ||
| 43 | /** | |
| 44 | * Creates a link field with a required title enabled for user-entered tokens. | |
| 45 | * Creates a node with a token in the link title and checks the value. | |
| 46 | */ | |
| 47 | function testUserTokenLinkCreate() { | |
| 48 | $account = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content')); | |
| 49 | $this->drupalLogin($account); | |
| 50 | ||
| 51 | // create field | |
| 52 | $name = strtolower($this->randomName()); | |
| 53 | $edit = array( | |
| 54 | '_add_new_field[label]' => $name, | |
| 55 | '_add_new_field[field_name]' => $name, | |
| 56 | '_add_new_field[type]' => 'link', | |
| 57 | '_add_new_field[widget_type]' => 'link', | |
| 58 | ); | |
| 59 | $this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save')); | |
| 60 | $this->drupalPost(NULL, array( | |
| 61 | 'title' => 'required', | |
| 62 | 'enable_tokens' => 1), t('Save field settings')); | |
| 63 | ||
| 64 | // Is field created? | |
| 65 | $this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added'); | |
| 66 | ||
| 67 | // create page form | |
| 68 | $this->drupalGet('node/add/page'); | |
| 69 | $field_name = 'field_' . $name; | |
| 70 | $this->assertField($field_name . '[0][title]', 'Title found'); | |
| 71 | $this->assertField($field_name . '[0][url]', 'URL found'); | |
| 72 | ||
| 73 | $input = array( | |
| 74 | 'href' => 'http://example.com/' . $this->randomName(), | |
| 75 | 'label' => $this->randomName(), | |
| 76 | ); | |
| 77 | ||
| 78 | $this->drupalLogin($account); | |
| 79 | $this->drupalGet('node/add/page'); | |
| 80 | ||
| 81 | $edit = array( | |
| 82 | 'title' => $input['label'], | |
| 83 | $field_name . '[0][title]' => $input['label'] . " [type]", | |
| 84 | $field_name . '[0][url]' => $input['href'], | |
| 85 | ); | |
| 86 | $this->drupalPost(NULL, $edit, t('Save')); | |
| 87 | $url = $this->getUrl(); | |
| 88 | ||
| 89 | // change to anonymous user | |
| 90 | $this->drupalLogout(); | |
| 91 | $this->drupalGet($url); | |
| 92 | ||
| 93 | $this->assertRaw(l($input['label'] . ' page', $input['href'])); | |
| 94 | } | |
| 95 | ||
| 96 | ||
| 97 | /** | |
| 98 | * Creates a link field with a static title and an admin-entered token. | |
| 99 | * Creates a node with a link and checks the title value. | |
| 100 | */ | |
| 101 | function testStaticTokenLinkCreate() { | |
| 102 | $account = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content')); | |
| 103 | $this->drupalLogin($account); | |
| 104 | ||
| 105 | // create field | |
| 106 | $name = strtolower($this->randomName()); | |
| 107 | $edit = array( | |
| 108 | '_add_new_field[label]' => $name, | |
| 109 | '_add_new_field[field_name]' => $name, | |
| 110 | '_add_new_field[type]' => 'link', | |
| 111 | '_add_new_field[widget_type]' => 'link', | |
| 112 | ); | |
| 113 | $this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save')); | |
| 114 | $this->drupalPost(NULL, array( | |
| 115 | 'title' => 'value', | |
| d1d9e371 JF |
116 | 'title_value' => $name . ' [type]', |
| 117 | 'enable_tokens' => TRUE, | |
| 118 | ), t('Save field settings')); | |
| 811c2a65 JF |
119 | |
| 120 | // Is filed created? | |
| 121 | $this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added'); | |
| 122 | ||
| 123 | // create page form | |
| 124 | $this->drupalGet('node/add/page'); | |
| 125 | $field_name = 'field_' . $name; | |
| 126 | $this->assertField($field_name . '[0][url]', 'URL found'); | |
| 127 | ||
| 128 | $input = array( | |
| 129 | 'href' => 'http://example.com/' . $this->randomName() | |
| 130 | ); | |
| 131 | ||
| 132 | $this->drupalLogin($account); | |
| 133 | $this->drupalGet('node/add/page'); | |
| 134 | ||
| 135 | $edit = array( | |
| 136 | 'title' => $name, | |
| 137 | $field_name . '[0][url]' => $input['href'], | |
| 138 | ); | |
| 139 | $this->drupalPost(NULL, $edit, t('Save')); | |
| 140 | ||
| 141 | $url = $this->getUrl(); | |
| 142 | ||
| 143 | // change to anonymous user | |
| 144 | $this->drupalLogout(); | |
| 145 | $this->drupalGet($url); | |
| 146 | ||
| 147 | $this->assertRaw(l($name . ' page', $input['href'])); | |
| 148 | } | |
| 149 | ||
| 150 | /** | |
| 151 | * Creates a link field with a static title and an admin-entered token. | |
| 152 | * Creates a node with a link and checks the title value. | |
| 153 | * | |
| 154 | * Basically, I want to make sure the [title-raw] token works, because it's a | |
| 155 | * token that changes from node to node, where [type]'s always going to be the | |
| 156 | * same. | |
| 157 | */ | |
| 158 | function testStaticTokenLinkCreate2() { | |
| 159 | $account = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content')); | |
| 160 | $this->drupalLogin($account); | |
| 161 | ||
| 162 | // create field | |
| 163 | $name = strtolower($this->randomName()); | |
| 164 | $edit = array( | |
| 165 | '_add_new_field[label]' => $name, | |
| 166 | '_add_new_field[field_name]' => $name, | |
| 167 | '_add_new_field[type]' => 'link', | |
| 168 | '_add_new_field[widget_type]' => 'link', | |
| 169 | ); | |
| 170 | $this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save')); | |
| 171 | $this->drupalPost(NULL, array( | |
| 172 | 'title' => 'value', | |
| d1d9e371 JF |
173 | 'title_value' => $name . ' [title-raw]', |
| 174 | 'enable_tokens' => TRUE, | |
| 175 | ), t('Save field settings')); | |
| 811c2a65 | 176 | |
| 5dd5b709 | 177 | // Is field created? |
| 811c2a65 JF |
178 | $this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added'); |
| 179 | ||
| 180 | // create page form | |
| 181 | $this->drupalGet('node/add/page'); | |
| 182 | $field_name = 'field_' . $name; | |
| 183 | $this->assertField($field_name . '[0][url]', 'URL found'); | |
| 184 | ||
| 185 | $input = array( | |
| 186 | 'href' => 'http://example.com/' . $this->randomName() | |
| 187 | ); | |
| 188 | ||
| 189 | $this->drupalLogin($account); | |
| 190 | $this->drupalGet('node/add/page'); | |
| 191 | ||
| 192 | $edit = array( | |
| 193 | 'title' => $name, | |
| 194 | $field_name . '[0][url]' => $input['href'], | |
| 195 | ); | |
| 196 | $this->drupalPost(NULL, $edit, t('Save')); | |
| 197 | ||
| 198 | $url = $this->getUrl(); | |
| 199 | ||
| 200 | // change to anonymous user | |
| 201 | $this->drupalLogout(); | |
| 202 | $this->drupalGet($url); | |
| 203 | ||
| 204 | $this->assertRaw(l($name .' '. $name, $input['href'])); | |
| 205 | } | |
| 318da51e | 206 | |
| de6b3902 | 207 | function test_Link_With_Title_Attribute_token_url_form() { |
| 318da51e JF |
208 | $this->loginWithPermissions($this->permissions); |
| 209 | $this->acquireContentTypes(1); | |
| 210 | $field_settings = array( | |
| 211 | 'type' => 'link', | |
| 212 | 'widget_type' => 'link', | |
| 213 | 'type_name' => $this->content_types[0]->name, | |
| 214 | 'attributes' => array( | |
| 215 | 'class' => '', | |
| 216 | 'target' => 'default', | |
| 217 | 'rel' => 'nofollow', | |
| 218 | 'title' => '', | |
| 219 | ), | |
| 220 | ); | |
| 221 | ||
| 222 | $field = $this->createField($field_settings, 0); | |
| 223 | //$this->fail('<pre>'. print_r($field, TRUE) .'</pre>'); | |
| 224 | $field_name = $field['field_name']; | |
| 225 | $field_db_info = content_database_info($field); | |
| 226 | $url_type = str_replace('_', '-', $this->content_types[0]->type); | |
| 227 | ||
| d1d9e371 JF |
228 | $edit = array('attributes[title]' => '['. $field_name .'-url]', |
| 229 | 'enable_tokens' => TRUE); | |
| 318da51e JF |
230 | |
| 231 | $this->drupalPost('admin/content/node-type/'. $url_type .'/fields/'. $field['field_name'], | |
| 232 | $edit, t('Save field settings')); | |
| 233 | $this->assertText(t('Saved field @field_name', array('@field_name' => $field['field_name']))); | |
| 234 | ||
| 235 | // So, having saved this field_name, let's see if it works... | |
| 236 | $this->acquireNodes(1); | |
| 237 | ||
| 238 | $node = node_load($this->nodes[0]->nid); | |
| 239 | ||
| 240 | $this->drupalGet('node/'. $this->nodes[0]->nid); | |
| 241 | ||
| 242 | $edit = array(); | |
| 243 | $test_link_url = 'http://www.example.com/test'; | |
| 244 | $edit[$field['field_name'] .'[0][url]'] = $test_link_url; | |
| 245 | $title = 'title_'. $this->randomName(20); | |
| 246 | $edit[$field['field_name'] .'[0][title]'] = $title; | |
| 247 | ||
| 248 | $this->drupalPost('node/'. $this->nodes[0]->nid .'/edit', $edit, t('Save')); | |
| 249 | ||
| 250 | // Make sure we get a new version! | |
| 251 | $node = node_load($this->nodes[0]->nid, NULL, TRUE); | |
| 252 | $this->assertText(t('@type @title has been updated.', | |
| 253 | array('@title' => $node->title, | |
| 254 | '@type' => $this->content_types[0]->name))); | |
| 255 | ||
| 256 | $this->drupalGet('node/'. $node->nid); | |
| 257 | $this->assertText($title, 'Make sure the link title/text shows'); | |
| 258 | $this->assertRaw(' title="'. $test_link_url .'"', "Do we show the link url as the title attribute?"); | |
| 259 | $this->assertNoRaw(' title="['. $field_name .'-url]"'); | |
| 260 | $this->assertTrue(module_exists('token'), t('Assure that Token Module is enabled.')); | |
| d1d9e371 | 261 | //$this->fail($this->content); |
| 318da51e JF |
262 | } |
| 263 | ||
| 264 | /** | |
| 265 | * If the title of the link is set to the title attribute, then the title | |
| 266 | * attribute isn't supposed to show. | |
| 267 | */ | |
| 268 | function test_Link_With_Title_Attribute_token_title_form() { | |
| 269 | $this->loginWithPermissions($this->permissions); | |
| 270 | $this->acquireContentTypes(1); | |
| 271 | $field_settings = array( | |
| 272 | 'type' => 'link', | |
| 273 | 'widget_type' => 'link', | |
| 274 | 'type_name' => $this->content_types[0]->name, | |
| 275 | 'attributes' => array( | |
| 276 | 'class' => '', | |
| 277 | 'target' => 'default', | |
| 278 | 'rel' => 'nofollow', | |
| 279 | 'title' => '', | |
| 280 | ), | |
| 281 | ); | |
| 282 | ||
| 283 | $field = $this->createField($field_settings, 0); | |
| 284 | $field_name = $field['field_name']; | |
| 285 | $field_db_info = content_database_info($field); | |
| 286 | $url_type = str_replace('_', '-', $this->content_types[0]->type); | |
| 287 | ||
| d1d9e371 JF |
288 | $edit = array('attributes[title]' => '['. $field_name .'-title]', |
| 289 | 'enable_tokens' => TRUE); | |
| 318da51e JF |
290 | |
| 291 | $this->drupalPost('admin/content/node-type/'. $url_type .'/fields/'. $field['field_name'], | |
| 292 | $edit, t('Save field settings')); | |
| 293 | $this->assertText(t('Saved field @field_name', array('@field_name' => $field['field_name']))); | |
| 294 | ||
| 295 | // So, having saved this field_name, let's see if it works... | |
| 296 | $this->acquireNodes(1); | |
| 297 | ||
| 298 | $node = node_load($this->nodes[0]->nid); | |
| 299 | ||
| 300 | $this->drupalGet('node/'. $this->nodes[0]->nid); | |
| 301 | ||
| 302 | $edit = array(); | |
| 303 | $edit[$field['field_name'] .'[0][url]'] = 'http://www.example.com/test'; | |
| 304 | $title = 'title_'. $this->randomName(20); | |
| 305 | $edit[$field['field_name'] .'[0][title]'] = $title; | |
| 306 | ||
| 307 | $this->drupalPost('node/'. $this->nodes[0]->nid .'/edit', $edit, t('Save')); | |
| 308 | ||
| 309 | // Make sure we get a new version! | |
| 310 | $node = node_load($this->nodes[0]->nid, NULL, TRUE); | |
| 311 | $this->assertText(t('@type @title has been updated.', | |
| 312 | array('@title' => $node->title, | |
| 313 | '@type' => $this->content_types[0]->name))); | |
| 314 | ||
| 315 | $this->drupalGet('node/'. $node->nid); | |
| 316 | $this->assertText($title, 'Make sure the link title/text shows'); | |
| 317 | $this->assertNoRaw(' title="'. $title .'"', "We should not show the link title as the title attribute?"); | |
| 318 | $this->assertNoRaw(' title="['. $field_name .'-title]"'); | |
| d1d9e371 | 319 | //$this->fail($this->content); |
| 318da51e | 320 | } |
| de6b3902 JF |
321 | |
| 322 | /** | |
| 323 | * Trying to set the url to contain a token. | |
| 324 | */ | |
| 325 | function testUserTokenLinkCreateInURL() { | |
| 326 | $account = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content')); | |
| 327 | $this->drupalLogin($account); | |
| 328 | ||
| 329 | // create field | |
| 330 | $name = strtolower($this->randomName()); | |
| 331 | $edit = array( | |
| 332 | '_add_new_field[label]' => $name, | |
| 333 | '_add_new_field[field_name]' => $name, | |
| 334 | '_add_new_field[type]' => 'link', | |
| 335 | '_add_new_field[widget_type]' => 'link', | |
| 336 | ); | |
| 337 | $this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save')); | |
| 338 | $this->drupalPost(NULL, array( | |
| 339 | 'title' => 'required', | |
| 340 | 'enable_tokens' => 1), t('Save field settings')); | |
| 341 | ||
| 342 | // Is field created? | |
| 343 | $this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added'); | |
| 344 | ||
| 345 | // create page form | |
| 346 | $this->drupalGet('node/add/page'); | |
| 347 | $field_name = 'field_' . $name; | |
| 348 | $this->assertField($field_name . '[0][title]', 'Title found'); | |
| 349 | $this->assertField($field_name . '[0][url]', 'URL found'); | |
| 350 | ||
| 351 | $input = array( | |
| 352 | 'href' => 'http://example.com/' . $this->randomName(), | |
| 353 | 'label' => $this->randomName(), | |
| 354 | ); | |
| 355 | ||
| 356 | $this->drupalLogin($account); | |
| 357 | $this->drupalGet('node/add/page'); | |
| 358 | ||
| 359 | $edit = array( | |
| 360 | 'title' => $input['label'], | |
| 361 | $field_name . '[0][title]' => $input['label'], | |
| 362 | $field_name . '[0][url]' => $input['href'] . "/[type]", | |
| 363 | ); | |
| 364 | $this->drupalPost(NULL, $edit, t('Save')); | |
| 365 | $url = $this->getUrl(); | |
| 366 | ||
| 367 | // change to anonymous user | |
| 368 | $this->drupalLogout(); | |
| 369 | $this->drupalGet($url); | |
| 370 | ||
| 371 | $this->assertRaw(l($input['label'], $input['href'] .'/page')); | |
| 372 | //$this->fail($this->content); | |
| 373 | } | |
| 374 | ||
| 375 | /** | |
| 376 | * Trying to set the url to contain a token. | |
| 377 | */ | |
| 378 | function testUserTokenLinkCreateInURL2() { | |
| 379 | $account = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content')); | |
| 380 | $this->drupalLogin($account); | |
| 381 | ||
| 382 | // create field | |
| 383 | $name = strtolower($this->randomName()); | |
| 384 | $edit = array( | |
| 385 | '_add_new_field[label]' => $name, | |
| 386 | '_add_new_field[field_name]' => $name, | |
| 387 | '_add_new_field[type]' => 'link', | |
| 388 | '_add_new_field[widget_type]' => 'link', | |
| 389 | ); | |
| 390 | $this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save')); | |
| 391 | $this->drupalPost(NULL, array( | |
| 392 | 'title' => 'required', | |
| 393 | 'enable_tokens' => 1), t('Save field settings')); | |
| 394 | ||
| 395 | // Is field created? | |
| 396 | $this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added'); | |
| 397 | ||
| 398 | // create page form | |
| 399 | $this->drupalGet('node/add/page'); | |
| 400 | $field_name = 'field_' . $name; | |
| 401 | $this->assertField($field_name . '[0][title]', 'Title found'); | |
| 402 | $this->assertField($field_name . '[0][url]', 'URL found'); | |
| 403 | ||
| 404 | $input = array( | |
| 405 | 'href' => 'http://example.com/' . $this->randomName(), | |
| 406 | 'label' => $this->randomName(), | |
| 407 | ); | |
| 408 | ||
| 409 | $this->drupalLogin($account); | |
| 410 | $this->drupalGet('node/add/page'); | |
| 411 | ||
| 412 | $edit = array( | |
| 413 | 'title' => $input['label'], | |
| 414 | $field_name . '[0][title]' => $input['label'], | |
| 415 | $field_name . '[0][url]' => $input['href'] . "/[author-uid]", | |
| 416 | ); | |
| 417 | $this->drupalPost(NULL, $edit, t('Save')); | |
| 418 | $url = $this->getUrl(); | |
| 419 | ||
| 420 | // change to anonymous user | |
| 421 | $this->drupalLogout(); | |
| 422 | $this->drupalGet($url); | |
| 423 | ||
| 424 | $this->assertRaw(l($input['label'], $input['href'] .'/'. $account->uid)); | |
| 425 | } | |
| 811c2a65 | 426 | } |