| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: link.attribute.test,v 1.1.2.14 2010/06/14 18:14:11 jcfiala Exp $ 3 4 /** 5 * @file 6 * Basic simpletests to test options on link module. 7 */ 8 9 // Let's include the parent class. 10 module_load_include('test', 'content', 'tests/content.crud'); 11 12 class LinkAttributeCrudTest extends ContentCrudTestCase { 13 14 private $zebra; 15 16 public $permissions = array( 17 'access content', 18 'administer content types', 19 'administer nodes', 20 'administer filters', 21 'access comments', 22 'post comments', 23 'post comments without approval', 24 'access administration pages', 25 ); 26 27 function getInfo() { 28 return array( 29 'name' => t('Link Attribute Tests'), 30 'description' => t('Tests the field attributes, making sure they appear in various displayed situations.'), 31 'group' => t('Link'), 32 ); 33 } 34 35 function setUp() { 36 $this->zebra = 0; 37 parent::setUp('link'); 38 $this->loginWithPermissions($this->permissions); 39 } 40 41 function createLink($url, $title, $attributes = array()) { 42 return array( 43 'url' => $url, 44 'title' => $title, 45 'attributes' => $attributes, 46 ); 47 } 48 49 /** 50 * This usually isn't needed. $this->pass($this->content); will usually 51 * display the current page. 52 */ 53 private function outputScreenContents($description, $basename) { 54 // This is a hack to get a directory that won't be cleaned up by simpletest 55 $file_dir = file_directory_path() .'/../simpletest_output_pages'; 56 if (!is_dir($file_dir)) { 57 mkdir($file_dir, 0777, TRUE); 58 } 59 $output_path = "$file_dir/$basename." . $this->randomName(10) . '.html'; 60 $rv = file_put_contents($output_path, $this->drupalGetContent()); 61 $this->pass("$description: Contents of result page are ". l('here', $output_path)); 62 } 63 64 private function assertLinkOnNode($field_name, $link_value, $message = '', $group = 'Other') { 65 $this->zebra++; 66 $zebra_string = ($this->zebra % 2 == 0) ? 'even' : 'odd'; 67 $cssFieldLocator = 'field-'. str_replace('_', '-', $field_name); 68 $this->assertPattern('@<div class="field field-type-link '. $cssFieldLocator .'".*<div class="field-item '. $zebra_string .'">\s*'. $link_value .'\s*</div>@is', 69 $message, 70 $group); 71 } 72 73 /** 74 * A simple test that just creates a new node type, adds a link field to it, creates a new node of that type, and makes sure 75 * that the node is being displayed. 76 */ 77 function testBasic() { 78 $this->acquireContentTypes(1); 79 variable_set('node_options_'. $this->content_types[0]->name, array('status', 'promote')); 80 $field_settings = array( 81 'type' => 'link', 82 'widget_type' => 'link', 83 'type_name' => $this->content_types[0]->name, 84 'attributes' => array(), // <-- This is needed or we have an error. 85 ); 86 87 $field = $this->createField($field_settings, 0); 88 //$this->pass('<pre>'. print_r($field, TRUE) .'</pre>'); 89 $field_db_info = content_database_info($field); 90 91 $this->acquireNodes(2); 92 93 $node = node_load($this->nodes[0]->nid); 94 $node->promote = 1; // We want this to show on front page for the teaser test. 95 $node->{$field['field_name']}[0] = $this->createLink('http://www.example.com', 'Test Link'); 96 node_save($node); 97 98 // Does this display on the node page? 99 $this->drupalGet('node/'. $this->nodes[0]->nid); 100 $this->assertLinkOnNode($field['field_name'], l('Test Link', 'http://www.example.com')); 101 102 // Does this display on the front page? 103 $this->drupalGet('<front>'); 104 // reset the zebra! 105 $this->zebra = 0; 106 $this->assertLinkOnNode($field['field_name'], l('Test Link', 'http://www.example.com')); 107 } 108 109 /** 110 * This test sees that we can create a link field with a defined class, and make sure 111 * that class displays properly when the link is displayed. 112 */ 113 function testLinkWithClassOnField() { 114 $this->acquireContentTypes(1); 115 $field_settings = array( 116 'type' => 'link', 117 'widget_type' => 'link', 118 'type_name' => $this->content_types[0]->name, 119 'attributes' => array( 120 'class' => 'test-class', 121 'target' => 'default', 122 'rel' => FALSE, 123 ), 124 ); 125 126 $field = $this->createField($field_settings, 0); 127 //$this->pass('<pre>'. print_r($field, TRUE) .'</pre>'); 128 $field_db_info = content_database_info($field); 129 130 $this->acquireNodes(2); 131 132 $node = node_load($this->nodes[0]->nid); 133 $node->promote = 1; // We want this to show on front page for the teaser test. 134 $node->{$field['field_name']}[0] = $this->createLink('http://www.example.com', 'Test Link'); 135 node_save($node); 136 137 // Does this display on the node page? 138 $this->drupalGet('node/'. $this->nodes[0]->nid); 139 //$this->outputScreenContents('Link field with class', 'link_'); 140 $this->assertLinkOnNode($field['field_name'], l('Test Link', 'http://www.example.com', array('attributes' => array('class' => 'test-class')))); 141 142 // Does this display on the front page? 143 $this->drupalGet('<front>'); 144 // reset the zebra! 145 $this->zebra = 0; 146 $this->assertLinkOnNode($field['field_name'], l('Test Link', 'http://www.example.com', array('attributes' => array('class' => 'test-class')))); 147 } 148 149 function testLinkWithNoFollowOnField() { 150 $this->acquireContentTypes(1); 151 $field_settings = array( 152 'type' => 'link', 153 'widget_type' => 'link', 154 'type_name' => $this->content_types[0]->name, 155 'attributes' => array( 156 'class' => '', 157 'target' => 'default', 158 'rel' => 'nofollow', 159 ), 160 ); 161 162 $field = $this->createField($field_settings, 0); 163 //$this->pass('<pre>'. print_r($field, TRUE) .'</pre>'); 164 $field_db_info = content_database_info($field); 165 166 $this->acquireNodes(2); 167 168 $node = node_load($this->nodes[0]->nid); 169 $node->promote = 1; // We want this to show on front page for the teaser test. 170 $node->{$field['field_name']}[0] = $this->createLink('http://www.example.com', 'Test Link'); 171 node_save($node); 172 173 // Does this display on the node page? 174 $this->drupalGet('node/'. $this->nodes[0]->nid); 175 //$this->outputScreenContents('Link field with class', 'link_'); 176 $this->assertLinkOnNode($field['field_name'], l('Test Link', 'http://www.example.com', array('attributes' => array('rel' => 'nofollow')))); 177 178 // Does this display on the front page? 179 $this->drupalGet('<front>'); 180 // reset the zebra! 181 $this->zebra = 0; 182 $this->assertLinkOnNode($field['field_name'], l('Test Link', 'http://www.example.com', array('attributes' => array('rel' => 'nofollow')))); 183 } 184 185 function testLinkWithNoFollowOnFieldTargetNewWindow() { 186 $this->acquireContentTypes(1); 187 $field_settings = array( 188 'type' => 'link', 189 'widget_type' => 'link', 190 'type_name' => $this->content_types[0]->name, 191 'attributes' => array( 192 'class' => '', 193 'target' => LINK_TARGET_NEW_WINDOW, 194 'rel' => 'nofollow', 195 ), 196 ); 197 198 $field = $this->createField($field_settings, 0); 199 //$this->pass('<pre>'. print_r($field, TRUE) .'</pre>'); 200 $field_db_info = content_database_info($field); 201 202 $this->acquireNodes(2); 203 204 $node = node_load($this->nodes[0]->nid); 205 $node->promote = 1; // We want this to show on front page for the teaser test. 206 $node->{$field['field_name']}[0] = $this->createLink('http://www.example.com', 'Test Link'); 207 node_save($node); 208 209 // Does this display on the node page? 210 $this->drupalGet('node/'. $this->nodes[0]->nid); 211 //$this->outputScreenContents('Link field with class', 'link_'); 212 $this->assertLinkOnNode($field['field_name'], l('Test Link', 'http://www.example.com', array('attributes' => array('target' => '_blank', 'rel' => 'nofollow')))); 213 //$this->pass($this->content); 214 215 // Does this display on the front page? 216 $this->drupalGet('<front>'); 217 // reset the zebra! 218 $this->zebra = 0; 219 $this->assertLinkOnNode($field['field_name'], l('Test Link', 'http://www.example.com', array('attributes' => array('target' => '_blank', 'rel' => 'nofollow')))); 220 } 221 222 /** 223 * Trying to reproduce exactly what's in issue #664990 224 * 225 * http://drupal.org/node/664990 226 */ 227 function testLinkWithNoFollowOnFieldTargetNewWindowAndAClass() { 228 $this->acquireContentTypes(1); 229 $field_settings = array( 230 'type' => 'link', 231 'widget_type' => 'link', 232 'type_name' => $this->content_types[0]->name, 233 'attributes' => array( 234 'class' => 'testlink', 235 'target' => LINK_TARGET_NEW_WINDOW, 236 'rel' => 'nofollow', 237 ), 238 ); 239 240 $field = $this->createField($field_settings, 0); 241 //$this->pass('<pre>'. print_r($field, TRUE) .'</pre>'); 242 $field_db_info = content_database_info($field); 243 244 $this->acquireNodes(2); 245 246 $node = node_load($this->nodes[0]->nid); 247 $node->promote = 1; // We want this to show on front page for the teaser test. 248 $node->{$field['field_name']}[0] = $this->createLink('http://www.example.com', 'Test Link'); 249 node_save($node); 250 251 // Does this display on the node page? 252 $this->drupalGet('node/'. $this->nodes[0]->nid); 253 //$this->outputScreenContents('Link field with class', 'link_'); 254 $this->assertLinkOnNode($field['field_name'], l('Test Link', 'http://www.example.com', array('attributes' => array('class' => 'testlink', 'target' => '_blank', 'rel' => 'nofollow')))); 255 //$this->pass($this->content); 256 257 // Does this display on the front page? 258 $this->drupalGet('<front>'); 259 // reset the zebra! 260 $this->zebra = 0; 261 $this->assertLinkOnNode($field['field_name'], l('Test Link', 'http://www.example.com', array('attributes' => array('class' => 'testlink', 'target' => '_blank', 'rel' => 'nofollow')))); 262 } 263 264 /** 265 * Another test for http://drupal.org/node/664990 266 */ 267 function test_Link_With_Title_Attribute_WithNoFollowOnFieldTargetNewWindowAndAClass_Form() { 268 $this->acquireContentTypes(1); 269 $field_settings = array( 270 'type' => 'link', 271 'widget_type' => 'link', 272 'type_name' => $this->content_types[0]->name, 273 'attributes' => array( 274 'class' => '', 275 'target' => 'default', 276 'rel' => 'nofollow', 277 'title' => '', 278 ), 279 ); 280 281 $field = $this->createField($field_settings, 0); 282 $field_db_info = content_database_info($field); 283 $url_type = str_replace('_', '-', $this->content_types[0]->type); 284 285 $edit = array(); 286 $edit['attributes[class]'] = 'testdata'; 287 $edit['attributes[target]'] = LINK_TARGET_NEW_WINDOW; 288 $edit['attributes[rel]'] = 'nofollow'; 289 290 $this->drupalPost('admin/content/node-type/'. $url_type .'/fields/'. $field['field_name'], 291 $edit, t('Save field settings')); 292 $this->assertText(t('Saved field @field_name', array('@field_name' => $field['field_name']))); 293 294 // So, having saved this field_name, let's see if it works... 295 $this->acquireNodes(1); 296 297 $node = node_load($this->nodes[0]->nid); 298 299 $this->drupalGet('node/'. $this->nodes[0]->nid); 300 301 $edit = array(); 302 $edit[$field['field_name'] .'[0][url]'] = 'http://www.example.com/test'; 303 $title = 'title_'. $this->randomName(20); 304 $edit[$field['field_name'] .'[0][title]'] = $title; 305 306 $this->drupalPost('node/'. $this->nodes[0]->nid .'/edit', $edit, t('Save')); 307 308 // Make sure we get a new version! 309 $node = node_load($this->nodes[0]->nid, NULL, TRUE); 310 $this->assertText(t('@type @title has been updated.', 311 array('@title' => $node->title, 312 '@type' => $this->content_types[0]->name))); 313 314 $this->drupalGet('node/'. $node->nid); 315 $this->assertText($title, 'Make sure the link title/text shows'); 316 //$this->assertRaw(' title="test_data"', "Do we show the title?"); 317 $this->assertLinkOnNode($field['field_name'], 318 l($title, 319 'http://www.example.com/test', 320 array('attributes' => array('target' => '_blank', 321 'rel' => 'nofollow', 322 'class' => 'testdata')))); 323 //$this->pass($this->content); 324 } 325 326 function test_Link_With_Title_Attribute() { 327 $this->acquireContentTypes(1); 328 $field_settings = array( 329 'type' => 'link', 330 'widget_type' => 'link', 331 'type_name' => $this->content_types[0]->name, 332 'attributes' => array( 333 'class' => '', 334 'target' => 'default', 335 'rel' => 'nofollow', 336 'title' => 'test_title', 337 ), 338 ); 339 340 $field = $this->createField($field_settings, 0); 341 $field_db_info = content_database_info($field); 342 343 $this->acquireNodes(1); 344 345 $node = node_load($this->nodes[0]->nid); 346 347 $this->drupalGet('node/'. $this->nodes[0]->nid); 348 349 $edit = array(); 350 $edit[$field['field_name'] .'[0][url]'] = 'http://www.example.com/test'; 351 352 $this->drupalPost('node/'. $this->nodes[0]->nid .'/edit', $edit, t('Save')); 353 354 // Make sure we get a new version! 355 $node = node_load($this->nodes[0]->nid, NULL, TRUE); 356 $this->assertText(t('@type @title has been updated.', 357 array('@title' => $node->title, 358 '@type' => $this->content_types[0]->name))); 359 360 $this->drupalGet('node/'. $node->nid); 361 $this->assertRaw(' title="test_title"', "Do we show the title?"); 362 //$this->assertRaw(l('http://www.example.com/test', 'http://www.example.com/test', array('attributes' => array('title' => 'test_title')))); 363 } 364 365 function test_Link_With_Title_Attribute_form() { 366 $this->acquireContentTypes(1); 367 $field_settings = array( 368 'type' => 'link', 369 'widget_type' => 'link', 370 'type_name' => $this->content_types[0]->name, 371 'attributes' => array( 372 'class' => '', 373 'target' => 'default', 374 'rel' => 'nofollow', 375 'title' => '', 376 ), 377 ); 378 379 $field = $this->createField($field_settings, 0); 380 $field_db_info = content_database_info($field); 381 $url_type = str_replace('_', '-', $this->content_types[0]->type); 382 383 $edit = array('attributes[title]' => 'test_data'); 384 385 $this->drupalPost('admin/content/node-type/'. $url_type .'/fields/'. $field['field_name'], 386 $edit, t('Save field settings')); 387 $this->assertText(t('Saved field @field_name', array('@field_name' => $field['field_name']))); 388 389 // So, having saved this field_name, let's see if it works... 390 $this->acquireNodes(1); 391 392 $node = node_load($this->nodes[0]->nid); 393 394 $this->drupalGet('node/'. $this->nodes[0]->nid); 395 396 $edit = array(); 397 $edit[$field['field_name'] .'[0][url]'] = 'http://www.example.com/test'; 398 $title = 'title_'. $this->randomName(20); 399 $edit[$field['field_name'] .'[0][title]'] = $title; 400 401 $this->drupalPost('node/'. $this->nodes[0]->nid .'/edit', $edit, t('Save')); 402 403 // Make sure we get a new version! 404 $node = node_load($this->nodes[0]->nid, NULL, TRUE); 405 $this->assertText(t('@type @title has been updated.', 406 array('@title' => $node->title, 407 '@type' => $this->content_types[0]->name))); 408 409 $this->drupalGet('node/'. $node->nid); 410 $this->assertText($title, 'Make sure the link title/text shows'); 411 $this->assertRaw(' title="test_data"', "Do we show the title?"); 412 } 413 414 /** 415 * When the title attribute matches the link title, we need to suppress 416 * the title attribute. 417 */ 418 function test_Link_With_Title_Attribute_Not_Shown_form() { 419 $this->acquireContentTypes(1); 420 $field_settings = array( 421 'type' => 'link', 422 'widget_type' => 'link', 423 'type_name' => $this->content_types[0]->name, 424 'attributes' => array( 425 'class' => '', 426 'target' => 'default', 427 'rel' => 'nofollow', 428 'title' => '', 429 ), 430 ); 431 432 $common_title = 'title_'. $this->randomName(20); 433 434 $field = $this->createField($field_settings, 0); 435 $field_db_info = content_database_info($field); 436 $url_type = str_replace('_', '-', $this->content_types[0]->type); 437 438 $edit = array('attributes[title]' => $common_title); 439 440 $this->drupalPost('admin/content/node-type/'. $url_type .'/fields/'. $field['field_name'], 441 $edit, t('Save field settings')); 442 $this->assertText(t('Saved field @field_name', array('@field_name' => $field['field_name']))); 443 444 // So, having saved this field_name, let's see if it works... 445 $this->acquireNodes(1); 446 447 $node = node_load($this->nodes[0]->nid); 448 449 $this->drupalGet('node/'. $this->nodes[0]->nid); 450 451 $edit = array(); 452 $edit[$field['field_name'] .'[0][url]'] = 'http://www.example.com/test'; 453 $edit[$field['field_name'] .'[0][title]'] = $common_title; 454 455 $this->drupalPost('node/'. $this->nodes[0]->nid .'/edit', $edit, t('Save')); 456 457 // Make sure we get a new version! 458 $node = node_load($this->nodes[0]->nid, NULL, TRUE); 459 $this->assertText(t('@type @title has been updated.', 460 array('@title' => $node->title, 461 '@type' => $this->content_types[0]->name))); 462 463 $this->drupalGet('node/'. $node->nid); 464 $this->assertRaw('>'. $common_title .'<', 'Make sure the link title/text shows'); 465 $this->assertNoRaw(' title="'. $common_title .'"', 466 "Do we hide the title, since it matches the link title?"); 467 //$this->pass($this->content); 468 } 469 470 /** 471 * When the title attribute matches the link title, we need to suppress 472 * the title attribute. 473 */ 474 function test_Link_without_title_attribute() { 475 $this->acquireContentTypes(1); 476 $field_settings = array( 477 'type' => 'link', 478 'widget_type' => 'link', 479 'type_name' => $this->content_types[0]->name, 480 'attributes' => array( 481 'class' => '', 482 'target' => 'default', 483 'rel' => 'nofollow', 484 'title' => '', 485 ), 486 ); 487 488 $common_title = 'title_'. $this->randomName(20); 489 490 $field = $this->createField($field_settings, 0); 491 $field_db_info = content_database_info($field); 492 $url_type = str_replace('_', '-', $this->content_types[0]->type); 493 494 // So, having saved this field_name, let's see if it works... 495 $this->acquireNodes(1); 496 497 $node = node_load($this->nodes[0]->nid); 498 499 $this->drupalGet('node/'. $this->nodes[0]->nid); 500 501 $edit = array(); 502 $edit[$field['field_name'] .'[0][url]'] = 'http://www.example.com/test'; 503 $edit[$field['field_name'] .'[0][title]'] = $common_title; 504 505 $this->drupalPost('node/'. $this->nodes[0]->nid .'/edit', $edit, t('Save')); 506 507 // Make sure we get a new version! 508 $node = node_load($this->nodes[0]->nid, NULL, TRUE); 509 $this->assertText(t('@type @title has been updated.', 510 array('@title' => $node->title, 511 '@type' => $this->content_types[0]->name))); 512 513 $this->drupalGet('node/'. $node->nid); 514 $this->assertRaw('>'. $common_title .'<', 'Make sure the link title/text shows'); 515 $this->assertNoRaw(' title=""', 516 "Do we hide the title, since it is empty?"); 517 } 518 519 520 /** 521 * This test exercises the bugfix for http://drupal.org/node/628902. 522 * It's also making sure that if you set up a link field with 'rel="nofollow"' 523 * and point it internally, then the link does not show rel="nofollow". 524 */ 525 function test_rel_nofollow_bug() { 526 $account = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content')); 527 $this->drupalLogin($account); 528 529 // create field 530 $name = strtolower($this->randomName()); 531 $field_name = 'field_'. $name; 532 $edit = array( 533 '_add_new_field[label]' => $name, 534 '_add_new_field[field_name]' => $name, 535 '_add_new_field[type]' => 'link', 536 '_add_new_field[widget_type]' => 'link', 537 ); 538 $this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save')); 539 $this->drupalPost(NULL, array( 540 'title' => 'value', 541 'title_value' => $name, 542 'attributes[rel]' => 'nofollow'), t('Save field settings')); 543 544 // Is field created? 545 $this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added'); 546 547 // create page form 548 $this->drupalGet('node/add/page'); 549 $this->assertField($field_name . '[0][url]', 'URL found'); 550 551 $input = array( 552 'href' => 'test', // internal link! 553 ); 554 555 $edit = array( 556 'title' => $name, 557 $field_name . '[0][url]' => $input['href'], 558 ); 559 $this->drupalPost(NULL, $edit, t('Save')); 560 561 $url = $this->getUrl(); 562 563 // change to anonymous user 564 $this->drupalLogout(); 565 $this->drupalGet($url); 566 //$this->pass($this->content); 567 $this->assertRaw(l($name, 'test'));//, array('attributes' => array('rel' => '')))); 568 } 569 570 function test_rel_nofollow_on_external_link() { 571 $account = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content')); 572 $this->drupalLogin($account); 573 574 // create field 575 $name = strtolower($this->randomName()); 576 $field_name = 'field_'. $name; 577 $edit = array( 578 '_add_new_field[label]' => $name, 579 '_add_new_field[field_name]' => $name, 580 '_add_new_field[type]' => 'link', 581 '_add_new_field[widget_type]' => 'link', 582 ); 583 $this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save')); 584 $this->drupalPost(NULL, array( 585 'title' => 'value', 586 'title_value' => $name, 587 'attributes[rel]' => 'nofollow'), t('Save field settings')); 588 589 // Is field created? 590 $this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added'); 591 592 // create page form 593 $this->drupalGet('node/add/page'); 594 $this->assertField($field_name . '[0][url]', 'URL found'); 595 596 $input = array( 597 'href' => 'http://example.com/' . $this->randomName(), // internal link! 598 ); 599 600 $edit = array( 601 'title' => $name, 602 $field_name . '[0][url]' => $input['href'], 603 ); 604 $this->drupalPost(NULL, $edit, t('Save')); 605 606 $url = $this->getUrl(); 607 608 // change to anonymous user 609 $this->drupalLogout(); 610 $this->drupalGet($url); 611 //$this->pass($this->content); 612 $this->assertRaw(l($name, $input['href'], array('attributes' => array('rel' => 'nofollow')))); 613 } 614 615 /** 616 * Here we test the fix to #626932, where an empty or bad attributes value on the link at the field 617 * level would cause the site to die in _link_sanitize, when the non-array $field['attributes'] is added 618 * to another array. 619 */ 620 function test_bad_attributes_bugfix_null_global_settings() { 621 $account = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content')); 622 $this->drupalLogin($account); 623 624 // create field 625 $name = strtolower($this->randomName()); 626 $field_name = 'field_'. $name; 627 $edit = array( 628 '_add_new_field[label]' => $name, 629 '_add_new_field[field_name]' => $name, 630 '_add_new_field[type]' => 'link', 631 '_add_new_field[widget_type]' => 'link', 632 ); 633 $this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save')); 634 $this->drupalPost(NULL, array( 635 'title' => 'value', 636 'title_value' => $name), t('Save field settings')); 637 638 // Is field created? 639 $this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added'); 640 641 // ruin the stored data in content_node_field. 642 // Here we replace the entire $field with a blank. The structure of the table 643 // prevents it from being set to a null, sadly. 644 db_query("UPDATE {content_node_field} SET global_settings = '' WHERE field_name = '%s'", 645 $field_name); 646 647 // create page form 648 $this->drupalGet('node/add/page'); 649 $this->assertField($field_name . '[0][url]', 'URL found'); 650 651 $input = array( 652 'href' => 'test', // internal link! 653 ); 654 655 $edit = array( 656 'title' => $name, 657 $field_name . '[0][url]' => $input['href'], 658 ); 659 $this->drupalPost(NULL, $edit, t('Save')); 660 661 $url = $this->getUrl(); 662 663 // change to anonymous user 664 $this->drupalLogout(); 665 $this->drupalGet($url); 666 //$this->pass($this->content); 667 $this->assertRaw(l($name, 'test'));//, array('attributes' => array('rel' => '')))); 668 } 669 /** 670 * Here we test the fix to #626932, where an empty or bad attributes value on the link at the field 671 * level would cause the site to die in _link_sanitize, when the non-array $field['attributes'] is added 672 * to another array. 673 */ 674 function test_bad_attributes_bugfix_string_attributes() { 675 $account = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content')); 676 $this->drupalLogin($account); 677 678 // create field 679 $name = strtolower($this->randomName()); 680 $field_name = 'field_'. $name; 681 $edit = array( 682 '_add_new_field[label]' => $name, 683 '_add_new_field[field_name]' => $name, 684 '_add_new_field[type]' => 'link', 685 '_add_new_field[widget_type]' => 'link', 686 ); 687 $this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save')); 688 $this->drupalPost(NULL, array( 689 'title' => 'value', 690 'title_value' => $name), t('Save field settings')); 691 692 // Is field created? 693 $this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added'); 694 695 // ruin the stored data in content_node_field. 696 // Here we set $field['attributes'] equal to a string of length 0. 697 db_query("UPDATE {content_node_field} SET global_settings = '%s' WHERE field_name = '%s'", 698 'a:6:{s:10:"attributes";s:0:"";s:7:"display";a:1:{s:10:"url_cutoff";s:2:"80";}s:3:"url";i:0;s:5:"title";s:8:"optional";s:11:"title_value";s:0:"";s:13:"enable_tokens";i:1;}', $field_name); 699 700 // create page form 701 $this->drupalGet('node/add/page'); 702 $this->assertField($field_name . '[0][url]', 'URL found'); 703 704 $input = array( 705 'href' => 'test', // internal link! 706 ); 707 708 $edit = array( 709 'title' => $name, 710 $field_name . '[0][url]' => $input['href'], 711 ); 712 $this->drupalPost(NULL, $edit, t('Save')); 713 714 $url = $this->getUrl(); 715 716 // change to anonymous user 717 $this->drupalLogout(); 718 $this->drupalGet($url); 719 //$this->pass($this->content); 720 $this->assertRaw(l($name, 'test'));//, array('attributes' => array('rel' => '')))); 721 } 722 723 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |