Projet

Général

Profil

Révision 7fe061e8

Ajouté par Assos Assos il y a plus de 8 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/link/tests/link.validate.test
22 22

  
23 23
    $field_name = $this->createLinkField();
24 24

  
25
    $permission = 'create page content';
26
    $this->checkPermissions(array($permission), TRUE);
27

  
28
    $this->drupalGet('node/add/page');
29

  
30 25
    $label = $this->randomName();
31
    $edit = array(
26
    $settings = array(
32 27
      'title' => $label,
33
      $field_name . '[und][0][title]' => $label,
34
      $field_name . '[und][0][url]' => $url,
28
      $field_name => array(
29
        LANGUAGE_NONE=> array(
30
          array(
31
            'title' => $label,
32
            'url' => $url,
33
          )
34
        ),
35
      ),
35 36
    );
36
    $this->drupalPost(NULL, $edit, t('Save'));
37
    $this->assertRaw(' has been created.', 'Node created');
38 37

  
39
    $nid = 1; //$matches[1];
38
    $node = $this->drupalCreateNode($settings);
40 39

  
41
    $node = node_load($nid);
40
    $this->assertNotNull($node, ' has been created.', 'Node created');
42 41

  
43
    $this->assertEqual($url, $node->{$field_name}['und'][0]['url']);
42
    $this->assertEqual($url, $node->{$field_name}[LANGUAGE_NONE][0]['url']);
44 43
  }
45 44
}
46 45

  
......
269 268

  
270 269
  // Validate that an internal url would be accepted.
271 270
  function test_link_internal_url() {
272
    $this->link_test_validate_url('node/32');
271
    // Create the content first.
272
    $node = $this->drupalCreateNode();
273

  
274
    $link = 'node/' . $node->nid;
275
    $this->link_test_validate_url($link);
276
    $type = link_url_type($link);
277
    $this->assertEqual(LINK_INTERNAL, $type, 'Test ' . $link . ' is an internal link.');
273 278
  }
274 279

  
275 280
  // Validate a simple mailto.
......
340 345
  /**
341 346
   * Here, we're testing that a very long url is stored properly in the db.
342 347
   *
343
   * Basicly, trying to test http://drupal.org/node/376818
348
   * Basically, trying to test http://drupal.org/node/376818
344 349
   */
345 350
  function testLinkURLFieldIsBig() {
346 351
    $long_url = 'http://th.wikipedia.org/wiki/%E0%B9%82%E0%B8%A3%E0%B8%87%E0%B9%80%E0%B8%A3%E0%B8%B5%E0%B8%A2%E0%B8%99%E0%B9%80%E0%B8%9A%E0%B8%8D%E0%B8%88%E0%B8%A1%E0%B8%A3%E0%B8%B2%E0%B8%8A%E0%B8%B9%E0%B8%97%E0%B8%B4%E0%B8%A8_%E0%B8%99%E0%B8%84%E0%B8%A3%E0%B8%A8%E0%B8%A3%E0%B8%B5%E0%B8%98%E0%B8%A3%E0%B8%A3%E0%B8%A1%E0%B8%A3%E0%B8%B2%E0%B8%8A';
......
363 368
      'group' => 'Link',
364 369
    );
365 370
  }
371
  
372
  function setUp() {
373
    parent::setUp('link');
374
  }
366 375

  
367 376
  /**
368 377
   * Translates the LINK type constants to english for display and debugging of tests
......
386 395
    }
387 396
  }
388 397

  
389
  // Make sure that a link labelled <front> works.
398
  // Make sure that a link labeled <front> works.
390 399
  function testValidateFrontLink() {
391 400
    $valid = link_validate_url('<front>');
392
    $this->assertEqual(LINK_FRONT, $valid, 'Make sure that front link is verfied and identified');
401
    $this->assertEqual(LINK_FRONT, $valid, 'Make sure that front link is verified and identified');
393 402
  }
394 403

  
395 404
  function testValidateEmailLink() {
......
409 418

  
410 419
  function testValidateNewsArticleLink() {
411 420
    $valid = link_validate_url('news:hj0db8$vrm$1@news.eternal-september.org');
412
    $this->assertEqual(LINK_NEWS, $valid, 'Make sure link to specific article valiates as news.');
421
    $this->assertEqual(LINK_NEWS, $valid, 'Make sure link to specific article validates as news.');
413 422
  }
414 423

  
415 424
  function testValidateBadNewsgroupLink() {
......
418 427
  }
419 428

  
420 429
  function testValidateInternalLinks() {
430
    $tempfile = drupal_tempnam('public://files', 'test');
421 431
    $links = array(
422
      'node/5',
423 432
      'rss.xml',
424
      'files/test.jpg',
425
      '/var/www/test',
433
      file_uri_target($tempfile),
434
      drupal_realpath($tempfile),
426 435
    );
427 436
    
428 437
    foreach ($links as $link) {
438
      $type = link_url_type($link);
439
      $this->assertEqual(LINK_INTERNAL, $type, 'Test ' . $link . ' is an internal link.');
429 440
      $valid = link_validate_url($link);
430
      $this->assertEqual(LINK_INTERNAL, $valid, 'Test ' . $link . ' internal link.');
441
      $this->assertTrue($valid, 'Test ' . $link . ' is valid internal link.');
431 442
    }
432 443
  }
433 444

  
......
446 457
      'http://255.255.255.255:4823/',
447 458
      'www.test-site.com',
448 459
      'http://example.com/index.php?q=node/123',
449
      'http://example.com/index.php?page=this\that',
450 460
      'http://example.com/?first_name=Joe Bob&last_name=Smith',
451 461
      // Anchors
452 462
      'http://www.example.com/index.php#test',
......
464 474
      }
465 475
    }
466 476
    foreach ($links as $link) {
477
      $type = link_url_type($link);
478
      $this->assertEqual(LINK_EXTERNAL, $type, 'Testing that ' . $link . ' is an external link.');
467 479
      $valid = link_validate_url($link);
468
      $this->assertEqual(LINK_EXTERNAL, $valid, 'Testing that ' . $link . ' is a valid external link.');
480
      $this->assertTrue($valid, 'Test ' . $link . ' is valid external link.');
469 481
      // The following two lines are commented out and only used for comparisons.
470 482
      //$valid2 = valid_url($link, TRUE);
471 483
      //$this->assertEqual(TRUE, $valid2, "Using valid_url() on $link.");
......
485 497
      'http://www.testß.com/', // ß not allowed in domain names!
486 498
      'http://www.example.frog/', // Bad TLD
487 499
      //'http://www.-fudge.com/', // domains can't have sections starting with a dash.
500
      'http://example.com/index.php?page=this\that',
501
      'example@example.com',
488 502
    );
489 503
    foreach ($links as $link) {
490 504
      $valid = link_validate_url($link);

Formats disponibles : Unified diff