link.validate.test 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. <?php
  2. /**
  3. * @file
  4. * Tests that exercise the validation functions in the link module.
  5. */
  6. /**
  7. * Validate Test Case.
  8. */
  9. class LinkValidateTestCase extends LinkBaseTestClass {
  10. /**
  11. * Create Link.
  12. */
  13. protected function createLink($url, $title, $attributes = array()) {
  14. return array(
  15. 'url' => $url,
  16. 'title' => $title,
  17. 'attributes' => $attributes,
  18. );
  19. }
  20. /**
  21. * Takes a URL, sees if it can validate that the URL is valid.
  22. */
  23. protected function linkTestValidateUrl($url) {
  24. $field_name = $this->createLinkField();
  25. $label = $this->randomName();
  26. $settings = array(
  27. 'title' => $label,
  28. $field_name => array(
  29. LANGUAGE_NONE => array(
  30. array(
  31. 'title' => $label,
  32. 'url' => $url,
  33. ),
  34. ),
  35. ),
  36. );
  37. $node = $this->drupalCreateNode($settings);
  38. $this->assertNotNull($node, ' has been created.', 'Node created');
  39. $this->assertEqual($url, $node->{$field_name}[LANGUAGE_NONE][0]['url']);
  40. }
  41. }
  42. /**
  43. * Class for Validate Test.
  44. */
  45. class LinkValidateTest extends LinkValidateTestCase {
  46. /**
  47. * Get Info.
  48. */
  49. public static function getInfo() {
  50. return array(
  51. 'name' => 'Link Validation Tests',
  52. 'description' => 'Tests the field validation.',
  53. 'group' => 'Link',
  54. );
  55. }
  56. /**
  57. * Validate basic URL.
  58. */
  59. public function testLinkValidateBasicUrl() {
  60. $this->linkTestValidateUrl('http://www.example.com');
  61. }
  62. /**
  63. * Test if we're stopped from posting a bad url on default validation.
  64. */
  65. public function testLinkValidateBadUrlValidateDefault() {
  66. $this->web_user = $this->drupalCreateUser(array(
  67. 'administer content types',
  68. 'administer fields',
  69. 'administer nodes',
  70. 'administer filters',
  71. 'access content',
  72. 'create page content',
  73. 'access administration pages',
  74. ));
  75. $this->drupalLogin($this->web_user);
  76. // Create field.
  77. $name = strtolower($this->randomName());
  78. $edit = array(
  79. 'fields[_add_new_field][label]' => $name,
  80. 'fields[_add_new_field][field_name]' => $name,
  81. 'fields[_add_new_field][type]' => 'link_field',
  82. 'fields[_add_new_field][widget_type]' => 'link_field',
  83. );
  84. $this->drupalPost('admin/structure/types/manage/page/fields', $edit, t('Save'));
  85. $this->drupalPost(NULL, array(), t('Save field settings'));
  86. $this->drupalPost(NULL, array(), t('Save settings'));
  87. // Is field created?
  88. $this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
  89. node_types_rebuild();
  90. menu_rebuild();
  91. // Create page form.
  92. $this->drupalGet('node/add/page');
  93. $field_name = 'field_' . $name;
  94. $this->assertField('edit-field-' . $name . '-und-0-title', 'Title found');
  95. $this->assertField('edit-field-' . $name . '-und-0-url', 'URL found');
  96. $edit = array(
  97. 'title' => 'Simple Title',
  98. $field_name . '[und][0][url]' => 'edik:naw',
  99. );
  100. $this->drupalPost(NULL, $edit, t('Save'));
  101. $this->assertText(t('The value @value provided for @field is not a valid URL.', array(
  102. '@value' => 'edik:naw',
  103. '@field' => $name,
  104. )));
  105. }
  106. /**
  107. * Test if we're stopped from posting a bad url with validation on.
  108. */
  109. public function testLinkValidateBadUrlValidateOn() {
  110. $this->web_user = $this->drupalCreateUser(array(
  111. 'administer content types',
  112. 'administer fields',
  113. 'administer nodes',
  114. 'administer filters',
  115. 'access content',
  116. 'create page content',
  117. 'access administration pages',
  118. ));
  119. $this->drupalLogin($this->web_user);
  120. // Create field.
  121. $name = strtolower($this->randomName());
  122. $edit = array(
  123. 'fields[_add_new_field][label]' => $name,
  124. 'fields[_add_new_field][field_name]' => $name,
  125. 'fields[_add_new_field][type]' => 'link_field',
  126. 'fields[_add_new_field][widget_type]' => 'link_field',
  127. );
  128. $this->drupalPost('admin/structure/types/manage/page/fields', $edit, t('Save'));
  129. $this->drupalPost(NULL, array(), t('Save field settings'));
  130. $this->drupalPost(NULL, array('instance[settings][validate_url]' => TRUE), t('Save settings'));
  131. // Is field created?
  132. $this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
  133. node_types_rebuild();
  134. menu_rebuild();
  135. // Create page form.
  136. $this->drupalGet('node/add/page');
  137. $field_name = 'field_' . $name;
  138. $this->assertField('edit-field-' . $name . '-und-0-title', 'Title found');
  139. $this->assertField('edit-field-' . $name . '-und-0-url', 'URL found');
  140. $edit = array(
  141. 'title' => 'Simple Title',
  142. $field_name . '[und][0][url]' => 'edik:naw',
  143. );
  144. $this->drupalPost(NULL, $edit, t('Save'));
  145. $this->assertText(t('The value @value provided for @field is not a valid URL.', array(
  146. '@field' => $name,
  147. '@value' => 'edik:naw',
  148. )));
  149. }
  150. /**
  151. * Test if we can post a bad url if the validation is expressly turned off.
  152. */
  153. public function testLinkValidateBadUrlValidateOff() {
  154. $this->web_user = $this->drupalCreateUser(array(
  155. 'administer content types',
  156. 'administer fields',
  157. 'administer nodes',
  158. 'administer filters',
  159. 'access content',
  160. 'create page content',
  161. 'access administration pages',
  162. ));
  163. $this->drupalLogin($this->web_user);
  164. // Create field.
  165. $name = strtolower($this->randomName());
  166. $edit = array(
  167. 'fields[_add_new_field][label]' => $name,
  168. 'fields[_add_new_field][field_name]' => $name,
  169. 'fields[_add_new_field][type]' => 'link_field',
  170. 'fields[_add_new_field][widget_type]' => 'link_field',
  171. );
  172. $this->drupalPost('admin/structure/types/manage/page/fields', $edit, t('Save'));
  173. $this->drupalPost(NULL, array(), t('Save field settings'));
  174. $this->drupalPost(NULL, array('instance[settings][validate_url]' => FALSE), t('Save settings'));
  175. // @codingStandardsIgnoreLine
  176. /*$instance_details = db_query("SELECT * FROM {field_config_instance} WHERE field_name = :field_name AND bundle = 'page'", array(':field_name' => 'field_'. $name))->fetchObject();
  177. $this->fail('<pre>'. print_r($instance_details, TRUE) .'</pre>');
  178. $this->fail('<pre>'. print_r(unserialize($instance_details->data), TRUE) .'</pre>');*/
  179. // Is field created?
  180. $this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
  181. node_types_rebuild();
  182. menu_rebuild();
  183. // Create page form.
  184. $this->drupalGet('node/add/page');
  185. $field_name = 'field_' . $name;
  186. $this->assertField('edit-field-' . $name . '-und-0-title', 'Title found');
  187. $this->assertField('edit-field-' . $name . '-und-0-url', 'URL found');
  188. $edit = array(
  189. 'title' => 'Simple Title',
  190. $field_name . '[und][0][url]' => 'edik:naw',
  191. );
  192. $this->drupalPost(NULL, $edit, t('Save'));
  193. $this->assertNoText(t('The value %value provided for %field is not a valid URL.', array(
  194. '%field' => $name,
  195. '%value' => 'edik:naw',
  196. )));
  197. }
  198. /**
  199. * Validate switching between validation status.
  200. *
  201. * Test if a bad url can sneak through un-filtered if we play with the
  202. * validation...
  203. */
  204. public function xTestLinkValidateSwitchingBetweenValidationStatus() {
  205. $this->acquireContentTypes(1);
  206. $this->web_user = $this->drupalCreateUser(array(
  207. 'administer content types',
  208. 'administer fields',
  209. 'administer nodes',
  210. 'access administration pages',
  211. 'access content',
  212. 'create ' . $this->content_types[0]->type . ' content',
  213. 'edit any ' . $this->content_types[0]->type . ' content',
  214. ));
  215. $this->drupalLogin($this->web_user);
  216. variable_set('node_options_' . $this->content_types[0]->name, array(
  217. 'status',
  218. 'promote',
  219. ));
  220. $field_settings = array(
  221. 'type' => 'link',
  222. 'widget_type' => 'link',
  223. 'type_name' => $this->content_types[0]->name,
  224. // <-- This is needed or we have an error.
  225. 'attributes' => array(),
  226. 'validate_url' => 0,
  227. );
  228. $field = $this->createField($field_settings, 0);
  229. $this->acquireNodes(2);
  230. $this->drupalGet('node/' . $this->nodes[0]->nid);
  231. $edit = array();
  232. $title = $this->randomName();
  233. $url = 'javascript:alert("http://example.com/' . $this->randomName() . '")';
  234. $edit[$field['field_name'] . '[0][url]'] = $url;
  235. $edit[$field['field_name'] . '[0][title]'] = $title;
  236. $this->drupalPost('node/' . $this->nodes[0]->nid . '/edit', $edit, t('Save'));
  237. // $this->pass($this->content);.
  238. // @codingStandardsIgnoreLine
  239. $this->assertNoText(t('The value %value provided for %field is not a valid URL.', array(
  240. // @codingStandardsIgnoreLine
  241. '%field' => $name,
  242. '%value' => trim($url),
  243. )));
  244. // Make sure we get a new version!
  245. $node = node_load($this->nodes[0]->nid, NULL, TRUE);
  246. $this->assertEqual($url, $node->{$field['field_name']}[0]['url']);
  247. $this->drupalGet('node/' . $node->nid);
  248. $this->assertNoRaw($url, 'Make sure Javascript does not display.');
  249. // Turn the array validation back _on_.
  250. $edit = array('validate_url' => TRUE);
  251. $node_type_link = str_replace('_', '-', $node->type);
  252. // @codingStandardsIgnoreLine
  253. // $this->drupalGet('admin/content/node-type/'. $node_type_link .'/fields'); ///'. $field['field_name']);
  254. // $this->fail($this->content);.
  255. $this->drupalPost('admin/content/node-type/' . $node_type_link . '/fields/' . $field['field_name'], $edit, t('Save field settings'));
  256. $this->drupalGet('node/' . $node->nid);
  257. // This actually works because the display_url goes through the core
  258. // url() function. But we should have a test that makes sure it continues
  259. // to work.
  260. $this->assertNoRaw($url, 'Make sure Javascript does not display.');
  261. // $this->fail($this->content);.
  262. }
  263. /**
  264. * Validate that '<front>' is a valid url.
  265. */
  266. public function testLinkFrontUrl() {
  267. $this->linkTestValidateUrl('<front>');
  268. }
  269. /**
  270. * Validate that an internal url would be accepted.
  271. */
  272. public function testLinkInternalUrl() {
  273. // Create the content first.
  274. $node = $this->drupalCreateNode();
  275. $link = 'node/' . $node->nid;
  276. $this->linkTestValidateUrl($link);
  277. $type = link_url_type($link);
  278. $this->assertEqual(LINK_INTERNAL, $type, 'Test ' . $link . ' is an internal link.');
  279. }
  280. /**
  281. * Validate a simple mailto.
  282. */
  283. public function testLinkMailto() {
  284. $this->linkTestValidateUrl('mailto:jcfiala@gmail.com');
  285. }
  286. /**
  287. * Check link external https.
  288. */
  289. public function testLinkExternalHttps() {
  290. $this->linkTestValidateUrl('https://www.example.com/');
  291. }
  292. /**
  293. * Check link FTP.
  294. */
  295. public function testLinkFtp() {
  296. $this->linkTestValidateUrl('ftp://www.example.com/');
  297. }
  298. }
  299. /**
  300. * Validate Test News.
  301. */
  302. class LinkValidateTestNews extends LinkValidateTestCase {
  303. /**
  304. * Get Info.
  305. */
  306. public static function getInfo() {
  307. return array(
  308. 'name' => 'Link News Validation Tests',
  309. 'description' => 'Tests the field validation for usenet urls.',
  310. 'group' => 'Link',
  311. );
  312. }
  313. /**
  314. * Validate a news link to a message group.
  315. */
  316. public function testLinkNews() {
  317. $this->linkTestValidateUrl('news:comp.infosystems.www.misc');
  318. }
  319. /**
  320. * Validate a news link to a message id. Said ID copied off of google groups.
  321. */
  322. public function testLinkNewsMessage() {
  323. $this->linkTestValidateUrl('news:hj0db8$vrm$1@news.eternal-september.org');
  324. }
  325. }
  326. /**
  327. * Validate Specific URL.
  328. */
  329. class LinkValidateSpecificURL extends LinkValidateTestCase {
  330. /**
  331. * Get Info.
  332. */
  333. public static function getInfo() {
  334. return array(
  335. 'name' => 'Link Specific URL Validation Tests',
  336. 'description' => 'Tests field validation with unusual urls',
  337. 'group' => 'Link',
  338. );
  339. }
  340. /**
  341. * Lets throw in a lot of umlouts for testing!
  342. */
  343. public function testUmloutUrl() {
  344. $this->linkTestValidateUrl('http://üÜü.exämple.com/nöde');
  345. }
  346. /**
  347. * Check umlout mailto.
  348. */
  349. public function testUmloutMailto() {
  350. $this->linkTestValidateUrl('mailto:Üser@exÅmple.com');
  351. }
  352. /**
  353. * Check German b in URL, aka Eszett.
  354. */
  355. public function testGermanEszettUrl() {
  356. $this->linkTestValidateUrl('http://www.test.com/ßstuff');
  357. }
  358. /**
  359. * Check Spanish ñ in URL.
  360. */
  361. public function testSpecialEneUrl() {
  362. $this->linkTestValidateUrl('http://www.testÑñ.com/');
  363. }
  364. /**
  365. * Curly brackets in query.
  366. */
  367. public function testCurlyBracketsInQuery() {
  368. $this->linkTestValidateUrl('http://www.healthyteennetwork.org/index.asp?Type=B_PR&SEC={2AE1D600-4FC6-4B4D-8822-F1D5F072ED7B}&DE={235FD1E7-208D-4363-9854-4E6775EB8A4C}');
  369. }
  370. /**
  371. * Here, we're testing that a very long url is stored properly in the db.
  372. *
  373. * Basically, trying to test http://drupal.org/node/376818
  374. */
  375. public function testLinkUrlFieldIsBig() {
  376. $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';
  377. $this->linkTestValidateUrl($long_url);
  378. }
  379. }
  380. /**
  381. * Validate Url Light.
  382. *
  383. * A series of tests of links, only going against the link_validate_url function
  384. * in link.module.
  385. *
  386. * Validation is guided by the rules in http://tools.ietf.org/html/rfc1738 !
  387. */
  388. class LinkValidateUrlLight extends DrupalWebTestCase {
  389. /**
  390. * Get Info.
  391. */
  392. public static function getInfo() {
  393. return array(
  394. 'name' => 'Link Light Validation Tests',
  395. 'description' => 'Tests the link_validate_url() function by itself, without invoking the full drupal/cck lifecycle.',
  396. 'group' => 'Link',
  397. );
  398. }
  399. /**
  400. * {@inheritdoc}
  401. */
  402. public function setUp(array $modules = array()) {
  403. $modules[] = 'link';
  404. parent::setUp($modules);
  405. }
  406. /**
  407. * Name Link Type.
  408. *
  409. * Translates the LINK type constants to english for display and debugging of
  410. * tests.
  411. *
  412. * @codingStandardsIgnoreStart
  413. */
  414. public function name_Link_Type($type) {
  415. // @codingStandardsIgnoreEnd
  416. switch ($type) {
  417. case LINK_FRONT:
  418. return "Front";
  419. case LINK_EMAIL:
  420. return "Email";
  421. case LINK_TEL:
  422. return "Telephone";
  423. case LINK_NEWS:
  424. return "Newsgroup";
  425. case LINK_INTERNAL:
  426. return "Internal Link";
  427. case LINK_EXTERNAL:
  428. return "External Link";
  429. case FALSE:
  430. return "Invalid Link";
  431. default:
  432. return "Bad Value:" . $type;
  433. }
  434. }
  435. /**
  436. * Make sure that a link labeled <front> works.
  437. */
  438. public function testValidateFrontLink() {
  439. $valid = link_validate_url('<front>');
  440. $this->assertEqual(LINK_FRONT, $valid, 'Make sure that front link is verified and identified');
  441. }
  442. /**
  443. * Validate Email Link.
  444. */
  445. public function testValidateEmailLink() {
  446. $valid = link_validate_url('mailto:bob@example.com');
  447. $this->assertEqual(LINK_EMAIL, $valid, "Make sure a basic mailto is verified and identified");
  448. }
  449. /**
  450. * Validate Email Link Bad.
  451. */
  452. public function testValidateEmailLinkBad() {
  453. $valid = link_validate_url(':bob@example.com');
  454. $this->assertEqual(FALSE, $valid, 'Make sure just a bad address is correctly failed');
  455. }
  456. /**
  457. * Confirm that valid tel: links work as expected.
  458. */
  459. public function testValidateTelLinks() {
  460. $links = array(
  461. 'tel:01',
  462. 'tel:123456789012345',
  463. 'tel:+123456789012345',
  464. );
  465. foreach ($links as $link) {
  466. $type = link_url_type($link);
  467. $this->assertEqual(LINK_TEL, $type, 'Test ' . $link . ' is a tel link.');
  468. $valid = link_validate_url($link);
  469. $this->assertTrue($valid, 'Test ' . $link . ' is valid tel link.');
  470. }
  471. }
  472. /**
  473. * Confirm that invalid tel: links work as expected.
  474. */
  475. public function testValidateTelLinksBad() {
  476. $links = array(
  477. 'tel:0',
  478. 'tel:1234567890123456',
  479. 'tel:+1',
  480. 'tel:+0123456789',
  481. 'tel:+1234567890123456',
  482. ':12345678',
  483. );
  484. foreach ($links as $link) {
  485. $type = link_url_type($link);
  486. $this->assertFalse($type, 'Test ' . $link . ' is not a tel link.');
  487. $valid = link_validate_url($link);
  488. $this->assertFalse($valid, 'Test ' . $link . ' is not a valid tel link.');
  489. }
  490. }
  491. /**
  492. * Validate Newsgroup Link.
  493. */
  494. public function testValidateNewsgroupLink() {
  495. $valid = link_validate_url('news:comp.infosystems.www.misc');
  496. $this->assertEqual(LINK_NEWS, $valid, 'Make sure link to newsgroup validates as news.');
  497. }
  498. /**
  499. * Validate News Article Link.
  500. */
  501. public function testValidateNewsArticleLink() {
  502. $valid = link_validate_url('news:hj0db8$vrm$1@news.eternal-september.org');
  503. $this->assertEqual(LINK_NEWS, $valid, 'Make sure link to specific article validates as news.');
  504. }
  505. /**
  506. * Validate Bad Newsgroup Link.
  507. */
  508. public function testValidateBadNewsgroupLink() {
  509. $valid = link_validate_url('news:comp.bad_name.misc');
  510. $this->assertEqual(FALSE, $valid, 'newsgroup names can\'t contain underscores, so it should come back as invalid.');
  511. }
  512. /**
  513. * Validate Internal Links.
  514. */
  515. public function testValidateInternalLinks() {
  516. $tempfile = drupal_tempnam('public://files', 'test');
  517. $links = array(
  518. 'rss.xml',
  519. 'foo#bar',
  520. file_uri_target($tempfile),
  521. drupal_realpath($tempfile),
  522. );
  523. foreach ($links as $link) {
  524. $type = link_url_type($link);
  525. $this->assertEqual(LINK_INTERNAL, $type, 'Test ' . $link . ' is an internal link.');
  526. $valid = link_validate_url($link);
  527. $this->assertTrue($valid, 'Test ' . $link . ' is valid internal link.');
  528. }
  529. }
  530. /**
  531. * Validate External Links.
  532. */
  533. public function testValidateExternalLinks() {
  534. $links = array(
  535. 'http://localhost:8080/',
  536. 'www.example.com',
  537. 'www.example.com/',
  538. 'http://username:p%40ssw0rd!@www.example.com/',
  539. 'http://@www.example.com/',
  540. 'http://username:@www.example.com/',
  541. 'http://username:password@www.example.com:8080/',
  542. 'http://127.0.0.1:80/',
  543. 'http://127.173.24.255:4723/',
  544. '127.173.24.255:4723/',
  545. 'http://255.255.255.255:4823/',
  546. 'www.test-site.com',
  547. 'http://example.com/index.php?q=node/123',
  548. 'http://example.com/?first_name=Joe Bob&last_name=Smith',
  549. // Anchors.
  550. 'http://www.example.com/index.php#test',
  551. 'http://www.example.com/index.php#this@that.',
  552. 'http://www.example.com/index.php#',
  553. 'http://www.cnn.com/video/#/video/politics/2008/12/09/intv.madeleine.albright.cnn',
  554. 'http://www.archive.org/stream/aesopsfables00aesorich#page/n7/mode/2up',
  555. 'http://www.example.com/blah/#this@that?',
  556. );
  557. // Test all of the protocols.
  558. $allowed_protocols = variable_get('filter_allowed_protocols', array(
  559. 'http',
  560. 'https',
  561. 'ftp',
  562. 'news',
  563. 'nntp',
  564. 'telnet',
  565. 'mailto',
  566. 'irc',
  567. 'ssh',
  568. 'sftp',
  569. 'webcal',
  570. ));
  571. foreach ($allowed_protocols as $protocol) {
  572. if ($protocol !== 'news' && $protocol !== 'mailto') {
  573. $links[] = $protocol . '://www.example.com';
  574. }
  575. }
  576. foreach ($links as $link) {
  577. $type = link_url_type($link);
  578. $this->assertEqual(LINK_EXTERNAL, $type, 'Testing that ' . $link . ' is an external link.');
  579. $valid = link_validate_url($link);
  580. $this->assertTrue($valid, 'Test ' . $link . ' is valid external link.');
  581. // The following two lines are commented out and only used for
  582. // comparisons.
  583. // $valid2 = valid_url($link, TRUE);
  584. // $this->assertEqual(TRUE, $valid2, "Using valid_url() on $link.");.
  585. }
  586. }
  587. /**
  588. * Check Invalid External Links.
  589. */
  590. public function testInvalidExternalLinks() {
  591. $links = array(
  592. 'http://www.ex ample.com/',
  593. // Bad ip!
  594. 'http://25.0.0/',
  595. 'http://4827.0.0.2/',
  596. // ß not allowed in domain names!
  597. 'http://www.testß.com/',
  598. // Bad TLD.
  599. 'http://.www.foo.bar./',
  600. // Domains can't have sections starting with a dash.
  601. // 'http://www.-fudge.com/',
  602. 'http://example.com/index.php?page=this\that',
  603. 'example@example.com',
  604. );
  605. foreach ($links as $link) {
  606. $valid = link_validate_url($link);
  607. $this->assertEqual(FALSE, $valid, 'Testing that ' . $link . ' is not a valid link.');
  608. }
  609. }
  610. }