feeds.test 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. <?php
  2. /**
  3. * @file
  4. * Common functionality for all Feeds tests.
  5. */
  6. /**
  7. * Test basic Data API functionality.
  8. */
  9. class FeedsWebTestCase extends DrupalWebTestCase {
  10. protected $profile = 'testing';
  11. public function setUp() {
  12. $args = func_get_args();
  13. // Build the list of required modules which can be altered by passing in an
  14. // array of module names to setUp().
  15. if (isset($args[0])) {
  16. if (is_array($args[0])) {
  17. $modules = $args[0];
  18. }
  19. else {
  20. $modules = $args;
  21. }
  22. }
  23. else {
  24. $modules = array();
  25. }
  26. $modules[] = 'taxonomy';
  27. $modules[] = 'image';
  28. $modules[] = 'file';
  29. $modules[] = 'field';
  30. $modules[] = 'field_ui';
  31. $modules[] = 'feeds';
  32. $modules[] = 'feeds_ui';
  33. $modules[] = 'feeds_tests';
  34. $modules[] = 'ctools';
  35. $modules[] = 'job_scheduler';
  36. $modules = array_unique($modules);
  37. parent::setUp($modules);
  38. // Add text formats Directly.
  39. $filtered_html_format = array(
  40. 'format' => 'filtered_html',
  41. 'name' => 'Filtered HTML',
  42. 'weight' => 0,
  43. 'filters' => array(
  44. // URL filter.
  45. 'filter_url' => array(
  46. 'weight' => 0,
  47. 'status' => 1,
  48. ),
  49. // HTML filter.
  50. 'filter_html' => array(
  51. 'weight' => 1,
  52. 'status' => 1,
  53. ),
  54. // Line break filter.
  55. 'filter_autop' => array(
  56. 'weight' => 2,
  57. 'status' => 1,
  58. ),
  59. // HTML corrector filter.
  60. 'filter_htmlcorrector' => array(
  61. 'weight' => 10,
  62. 'status' => 1,
  63. ),
  64. ),
  65. );
  66. $filtered_html_format = (object) $filtered_html_format;
  67. filter_format_save($filtered_html_format);
  68. // Build the list of required administration permissions. Additional
  69. // permissions can be passed as an array into setUp()'s second parameter.
  70. if (isset($args[1]) && is_array($args[1])) {
  71. $permissions = $args[1];
  72. }
  73. else {
  74. $permissions = array();
  75. }
  76. $permissions[] = 'access content';
  77. $permissions[] = 'administer site configuration';
  78. $permissions[] = 'administer content types';
  79. $permissions[] = 'administer nodes';
  80. $permissions[] = 'bypass node access';
  81. $permissions[] = 'administer taxonomy';
  82. $permissions[] = 'administer users';
  83. $permissions[] = 'administer feeds';
  84. // Create an admin user and log in.
  85. $this->admin_user = $this->drupalCreateUser($permissions);
  86. $this->drupalLogin($this->admin_user);
  87. $types = array(
  88. array(
  89. 'type' => 'page',
  90. 'name' => 'Basic page',
  91. 'node_options[status]' => 1,
  92. 'node_options[promote]' => 0,
  93. ),
  94. array(
  95. 'type' => 'article',
  96. 'name' => 'Article',
  97. 'node_options[status]' => 1,
  98. 'node_options[promote]' => 1,
  99. ),
  100. );
  101. foreach ($types as $type) {
  102. $this->drupalPost('admin/structure/types/add', $type, 'Save content type');
  103. $this->assertText("The content type " . $type['name'] . " has been added.");
  104. }
  105. }
  106. /**
  107. * Absolute path to Drupal root.
  108. */
  109. public function absolute() {
  110. return realpath(getcwd());
  111. }
  112. /**
  113. * Get the absolute directory path of the feeds module.
  114. */
  115. public function absolutePath() {
  116. return $this->absolute() . '/' . drupal_get_path('module', 'feeds');
  117. }
  118. /**
  119. * Generate an OPML test feed.
  120. *
  121. * The purpose of this function is to create a dynamic OPML feed that points
  122. * to feeds included in this test.
  123. */
  124. public function generateOPML() {
  125. $path = $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/';
  126. $output =
  127. '<?xml version="1.0" encoding="utf-8"?>
  128. <opml version="1.1">
  129. <head>
  130. <title>Feeds test OPML</title>
  131. <dateCreated>Fri, 16 Oct 2009 02:53:17 GMT</dateCreated>
  132. <ownerName></ownerName>
  133. </head>
  134. <body>
  135. <outline text="Feeds test group" >
  136. <outline title="Development Seed - Technological Solutions for Progressive Organizations" text="" xmlUrl="' . $path . 'developmentseed.rss2" type="rss" />
  137. <outline title="Magyar Nemzet Online - H\'rek" text="" xmlUrl="' . $path . 'feed_without_guid.rss2" type="rss" />
  138. <outline title="Drupal planet" text="" type="rss" xmlUrl="' . $path . 'drupalplanet.rss2" />
  139. </outline>
  140. </body>
  141. </opml>';
  142. // UTF 8 encode output string and write it to disk
  143. $output = utf8_encode($output);
  144. $filename = file_default_scheme() . '://test-opml-' . $this->randomName() . '.opml';
  145. $filename = file_unmanaged_save_data($output, $filename);
  146. return $filename;
  147. }
  148. /**
  149. * Create an importer configuration.
  150. *
  151. * @param $name
  152. * The natural name of the feed.
  153. * @param $id
  154. * The persistent id of the feed.
  155. * @param $edit
  156. * Optional array that defines the basic settings for the feed in a format
  157. * that can be posted to the feed's basic settings form.
  158. */
  159. public function createImporterConfiguration($name = 'Syndication', $id = 'syndication') {
  160. // Create new feed configuration.
  161. $this->drupalGet('admin/structure/feeds');
  162. $this->clickLink('Add importer');
  163. $edit = array(
  164. 'name' => $name,
  165. 'id' => $id,
  166. );
  167. $this->drupalPost('admin/structure/feeds/create', $edit, 'Create');
  168. // Assert message and presence of default plugins.
  169. $this->assertText('Your configuration has been created with default settings.');
  170. $this->assertPlugins($id, 'FeedsHTTPFetcher', 'FeedsSyndicationParser', 'FeedsNodeProcessor');
  171. // Per default attach to page content type.
  172. $this->setSettings($id, NULL, array('content_type' => 'page'));
  173. }
  174. /**
  175. * Choose a plugin for a importer configuration and assert it.
  176. *
  177. * @param $id
  178. * The importer configuration's id.
  179. * @param $plugin_key
  180. * The key string of the plugin to choose (one of the keys defined in
  181. * feeds_feeds_plugins()).
  182. */
  183. public function setPlugin($id, $plugin_key) {
  184. if ($type = FeedsPlugin::typeOf($plugin_key)) {
  185. $edit = array(
  186. 'plugin_key' => $plugin_key,
  187. );
  188. $this->drupalPost("admin/structure/feeds/$id/$type", $edit, 'Save');
  189. // Assert actual configuration.
  190. $config = unserialize(db_query("SELECT config FROM {feeds_importer} WHERE id = :id", array(':id' => $id))->fetchField());
  191. $this->assertEqual($config[$type]['plugin_key'], $plugin_key, 'Verified correct ' . $type . ' (' . $plugin_key . ').');
  192. }
  193. }
  194. /**
  195. * Set importer or plugin settings.
  196. *
  197. * @param $id
  198. * The importer configuration's id.
  199. * @param $plugin
  200. * The plugin (class) name, or NULL to set importer's settings
  201. * @param $settings
  202. * The settings to set.
  203. */
  204. public function setSettings($id, $plugin, $settings) {
  205. $this->drupalPost('admin/structure/feeds/' . $id . '/settings/' . $plugin, $settings, 'Save');
  206. $this->assertText('Your changes have been saved.');
  207. }
  208. /**
  209. * Create a test feed node. Test user has to have sufficient permissions:
  210. *
  211. * * create [type] content
  212. * * use feeds
  213. *
  214. * Assumes that page content type has been configured with
  215. * createImporterConfiguration() as a feed content type.
  216. *
  217. * @return
  218. * The node id of the node created.
  219. */
  220. public function createFeedNode($id = 'syndication', $feed_url = NULL, $title = '', $content_type = NULL) {
  221. if (empty($feed_url)) {
  222. $feed_url = $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/developmentseed.rss2';
  223. }
  224. // If content type not given, retrieve it.
  225. if (!$content_type) {
  226. $result= db_select('feeds_importer', 'f')
  227. ->condition('f.id', $id, '=')
  228. ->fields('f', array('config'))
  229. ->execute();
  230. $config = unserialize($result->fetchField());
  231. $content_type = $config['content_type'];
  232. $this->assertFalse(empty($content_type), 'Valid content type found: ' . $content_type);
  233. }
  234. // Create a feed node.
  235. $edit = array(
  236. 'title' => $title,
  237. 'feeds[FeedsHTTPFetcher][source]' => $feed_url,
  238. );
  239. $this->drupalPost('node/add/' . str_replace('_', '-', $content_type), $edit, 'Save');
  240. $this->assertText('has been created.');
  241. // Get the node id from URL.
  242. $nid = $this->getNid($this->getUrl());
  243. // Check whether feed got recorded in feeds_source table.
  244. $query = db_select('feeds_source', 's')
  245. ->condition('s.id', $id, '=')
  246. ->condition('s.feed_nid', $nid, '=');
  247. $query->addExpression("COUNT(*)");
  248. $result = $query->execute()->fetchField();
  249. $this->assertEqual(1, $result);
  250. $source = db_select('feeds_source', 's')
  251. ->condition('s.id', $id, '=')
  252. ->condition('s.feed_nid', $nid, '=')
  253. ->fields('s', array('config'))
  254. ->execute()->fetchObject();
  255. $config = unserialize($source->config);
  256. $this->assertEqual($config['FeedsHTTPFetcher']['source'], $feed_url, t('URL in DB correct.'));
  257. return $nid;
  258. }
  259. /**
  260. * Edit the configuration of a feed node to test update behavior.
  261. *
  262. * @param $nid
  263. * The nid to edit.
  264. * @param $feed_url
  265. * The new (absolute) feed URL to use.
  266. * @param $title
  267. * Optional parameter to change title of feed node.
  268. */
  269. public function editFeedNode($nid, $feed_url, $title = '') {
  270. $edit = array(
  271. 'title' => $title,
  272. 'feeds[FeedsHTTPFetcher][source]' => $feed_url,
  273. );
  274. // Check that the update was saved.
  275. $this->drupalPost('node/' . $nid . '/edit', $edit, 'Save');
  276. $this->assertText('has been updated.');
  277. // Check that the URL was updated in the feeds_source table.
  278. $source = db_query("SELECT * FROM {feeds_source} WHERE feed_nid = :nid", array(':nid' => $nid))->fetchObject();
  279. $config = unserialize($source->config);
  280. $this->assertEqual($config['FeedsHTTPFetcher']['source'], $feed_url, t('URL in DB correct.'));
  281. }
  282. /**
  283. * Batch create a variable amount of feed nodes. All will have the
  284. * same URL configured.
  285. *
  286. * @return
  287. * An array of node ids of the nodes created.
  288. */
  289. public function createFeedNodes($id = 'syndication', $num = 20, $content_type = NULL) {
  290. $nids = array();
  291. for ($i = 0; $i < $num; $i++) {
  292. $nids[] = $this->createFeedNode($id, NULL, $this->randomName(), $content_type);
  293. }
  294. return $nids;
  295. }
  296. /**
  297. * Import a URL through the import form. Assumes FeedsHTTPFetcher in place.
  298. */
  299. public function importURL($id, $feed_url = NULL) {
  300. if (empty($feed_url)) {
  301. $feed_url = $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/developmentseed.rss2';
  302. }
  303. $edit = array(
  304. 'feeds[FeedsHTTPFetcher][source]' => $feed_url,
  305. );
  306. $nid = $this->drupalPost('import/' . $id, $edit, 'Import');
  307. // Check whether feed got recorded in feeds_source table.
  308. $this->assertEqual(1, db_query("SELECT COUNT(*) FROM {feeds_source} WHERE id = :id AND feed_nid = 0", array(':id' => $id))->fetchField());
  309. $source = db_query("SELECT * FROM {feeds_source} WHERE id = :id AND feed_nid = 0", array(':id' => $id))->fetchObject();
  310. $config = unserialize($source->config);
  311. $this->assertEqual($config['FeedsHTTPFetcher']['source'], $feed_url, t('URL in DB correct.'));
  312. // Check whether feed got properly added to scheduler.
  313. $this->assertEqual(1, db_query("SELECT COUNT(*) FROM {job_schedule} WHERE type = :id AND id = 0 AND name = 'feeds_source_import' AND last <> 0 AND scheduled = 0", array(':id' => $id))->fetchField());
  314. // There must be only one entry for callback 'expire' - no matter what the feed_nid is.
  315. $this->assertEqual(0, db_query("SELECT COUNT(*) FROM {job_schedule} WHERE type = :id AND name = 'feeds_importer_expire' AND last <> 0 AND scheduled = 0", array(':id' => $id))->fetchField());
  316. }
  317. /**
  318. * Import a file through the import form. Assumes FeedsFileFetcher in place.
  319. */
  320. public function importFile($id, $file) {
  321. $this->assertTrue(file_exists($file), 'Source file exists');
  322. $edit = array(
  323. 'files[feeds]' => $file,
  324. );
  325. $this->drupalPost('import/' . $id, $edit, 'Import');
  326. }
  327. /**
  328. * Assert a feeds configuration's plugins.
  329. *
  330. * @deprecated:
  331. * Use setPlugin() instead.
  332. *
  333. * @todo Refactor users of assertPlugin() and make them use setPugin() instead.
  334. */
  335. public function assertPlugins($id, $fetcher, $parser, $processor) {
  336. // Assert actual configuration.
  337. $config = unserialize(db_query("SELECT config FROM {feeds_importer} WHERE id = :id", array(':id' => $id))->fetchField());
  338. $this->assertEqual($config['fetcher']['plugin_key'], $fetcher, 'Correct fetcher');
  339. $this->assertEqual($config['parser']['plugin_key'], $parser, 'Correct parser');
  340. $this->assertEqual($config['processor']['plugin_key'], $processor, 'Correct processor');
  341. }
  342. /**
  343. * Adds mappings to a given configuration.
  344. *
  345. * @param string $id
  346. * ID of the importer.
  347. * @param array $mappings
  348. * An array of mapping arrays. Each mapping array must have a source and
  349. * an target key and can have a unique key.
  350. * @param bool $test_mappings
  351. * (optional) TRUE to automatically test mapping configs. Defaults to TRUE.
  352. */
  353. public function addMappings($id, $mappings, $test_mappings = TRUE) {
  354. $path = "admin/structure/feeds/$id/mapping";
  355. // Iterate through all mappings and add the mapping via the form.
  356. foreach ($mappings as $i => $mapping) {
  357. if ($test_mappings) {
  358. $current_mapping_key = $this->mappingExists($id, $i, $mapping['source'], $mapping['target']);
  359. $this->assertEqual($current_mapping_key, -1, 'Mapping does not exist before addition.');
  360. }
  361. // Get unique flag and unset it. Otherwise, drupalPost will complain that
  362. // Split up config and mapping.
  363. $config = $mapping;
  364. unset($config['source'], $config['target']);
  365. $mapping = array('source' => $mapping['source'], 'target' => $mapping['target']);
  366. // Add mapping.
  367. $this->drupalPost($path, $mapping, t('Add'));
  368. // If there are other configuration options, set them.
  369. if ($config) {
  370. $this->drupalPostAJAX(NULL, array(), 'mapping_settings_edit_' . $i);
  371. // Set some settings.
  372. $edit = array();
  373. foreach ($config as $key => $value) {
  374. $edit["config[$i][settings][$key]"] = $value;
  375. }
  376. $this->drupalPostAJAX(NULL, $edit, 'mapping_settings_update_' . $i);
  377. $this->drupalPost(NULL, array(), t('Save'));
  378. }
  379. if ($test_mappings) {
  380. $current_mapping_key = $this->mappingExists($id, $i, $mapping['source'], $mapping['target']);
  381. $this->assertTrue($current_mapping_key >= 0, 'Mapping exists after addition.');
  382. }
  383. }
  384. }
  385. /**
  386. * Remove mappings from a given configuration.
  387. *
  388. * This function mimicks the Javascript behavior in feeds_ui.js
  389. *
  390. * @param array $mappings
  391. * An array of mapping arrays. Each mapping array must have a source and
  392. * a target key and can have a unique key.
  393. * @param bool $test_mappings
  394. * (optional) TRUE to automatically test mapping configs. Defaults to TRUE.
  395. */
  396. public function removeMappings($id, $mappings, $test_mappings = TRUE) {
  397. $path = "admin/structure/feeds/$id/mapping";
  398. $current_mappings = $this->getCurrentMappings($id);
  399. // Iterate through all mappings and remove via the form.
  400. foreach ($mappings as $i => $mapping) {
  401. if ($test_mappings) {
  402. $current_mapping_key = $this->mappingExists($id, $i, $mapping['source'], $mapping['target']);
  403. $this->assertEqual($current_mapping_key, $i, 'Mapping exists before removal.');
  404. }
  405. $remove_mapping = array("remove_flags[$i]" => 1);
  406. $this->drupalPost($path, $remove_mapping, t('Save'));
  407. $this->assertText('Your changes have been saved.');
  408. if ($test_mappings) {
  409. $current_mapping_key = $this->mappingExists($id, $i, $mapping['source'], $mapping['target']);
  410. $this->assertEqual($current_mapping_key, -1, 'Mapping does not exist after removal.');
  411. }
  412. }
  413. }
  414. /**
  415. * Gets an array of current mappings from the feeds_importer config.
  416. *
  417. * @param string $id
  418. * ID of the importer.
  419. *
  420. * @return bool|array
  421. * FALSE if the importer has no mappings, or an an array of mappings.
  422. */
  423. public function getCurrentMappings($id) {
  424. $config = db_query("SELECT config FROM {feeds_importer} WHERE id = :id", array(':id' => $id))->fetchField();
  425. $config = unserialize($config);
  426. // We are very specific here. 'mappings' can either be an array or not
  427. // exist.
  428. if (array_key_exists('mappings', $config['processor']['config'])) {
  429. $this->assertTrue(is_array($config['processor']['config']['mappings']), 'Mappings is an array.');
  430. return $config['processor']['config']['mappings'];
  431. }
  432. return FALSE;
  433. }
  434. /**
  435. * Determines if a mapping exists for a given importer.
  436. *
  437. * @param string $id
  438. * ID of the importer.
  439. * @param integer $i
  440. * The key of the mapping.
  441. * @param string $source
  442. * The source field.
  443. * @param string $target
  444. * The target field.
  445. *
  446. * @return integer
  447. * -1 if the mapping doesn't exist, the key of the mapping otherwise.
  448. */
  449. public function mappingExists($id, $i, $source, $target) {
  450. $current_mappings = $this->getCurrentMappings($id);
  451. if ($current_mappings) {
  452. foreach ($current_mappings as $key => $mapping) {
  453. if ($mapping['source'] == $source && $mapping['target'] == $target && $key == $i) {
  454. return $key;
  455. }
  456. }
  457. }
  458. return -1;
  459. }
  460. /**
  461. * Helper function, retrieves node id from a URL.
  462. */
  463. public function getNid($url) {
  464. $matches = array();
  465. preg_match('/node\/(\d+?)$/', $url, $matches);
  466. $nid = $matches[1];
  467. // Test for actual integerness.
  468. $this->assertTrue($nid === (string) (int) $nid, 'Node id is an integer.');
  469. return $nid;
  470. }
  471. /**
  472. * Copies a directory.
  473. */
  474. public function copyDir($source, $dest) {
  475. $result = file_prepare_directory($dest, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
  476. foreach (@scandir($source) as $file) {
  477. if (is_file("$source/$file")) {
  478. $file = file_unmanaged_copy("$source/$file", "$dest/$file");
  479. }
  480. }
  481. }
  482. /**
  483. * Download and extract SimplePIE.
  484. *
  485. * Sets the 'feeds_simplepie_library_dir' variable to the directory where
  486. * SimplePie is downloaded.
  487. */
  488. function downloadExtractSimplePie($version) {
  489. $url = "http://simplepie.org/downloads/simplepie_$version.mini.php";
  490. $filename = 'simplepie.mini.php';
  491. // Avoid downloading the file dozens of times
  492. $library_dir = DRUPAL_ROOT . '/' . $this->originalFileDirectory . '/simpletest/feeds';
  493. $simplepie_library_dir = $library_dir . '/simplepie';
  494. if (!file_exists($library_dir)) {
  495. drupal_mkdir($library_dir);
  496. }
  497. if (!file_exists($simplepie_library_dir)) {
  498. drupal_mkdir($simplepie_library_dir);
  499. }
  500. // Local file name.
  501. $local_file = $simplepie_library_dir . '/' . $filename;
  502. // Begin single threaded code.
  503. if (function_exists('sem_get')) {
  504. $semaphore = sem_get(ftok(__FILE__, 1));
  505. sem_acquire($semaphore);
  506. }
  507. // Download and extact the archive, but only in one thread.
  508. if (!file_exists($local_file)) {
  509. $local_file = system_retrieve_file($url, $local_file, FALSE, FILE_EXISTS_REPLACE);
  510. }
  511. if (function_exists('sem_get')) {
  512. sem_release($semaphore);
  513. }
  514. // End single threaded code.
  515. // Verify that files were successfully extracted.
  516. $this->assertTrue(file_exists($local_file), t('@file found.', array('@file' => $local_file)));
  517. // Set the simpletest library directory.
  518. variable_set('feeds_library_dir', $library_dir);
  519. }
  520. }
  521. /**
  522. * Provides a wrapper for DrupalUnitTestCase for Feeds unit testing.
  523. */
  524. class FeedsUnitTestHelper extends DrupalUnitTestCase {
  525. public function setUp() {
  526. parent::setUp();
  527. // Manually include the feeds module.
  528. // @todo Allow an array of modules from the child class.
  529. drupal_load('module', 'feeds');
  530. }
  531. }
  532. class FeedsUnitTestCase extends FeedsUnitTestHelper {
  533. public static function getInfo() {
  534. return array(
  535. 'name' => 'Unit tests',
  536. 'description' => 'Test basic low-level Feeds module functionality.',
  537. 'group' => 'Feeds',
  538. );
  539. }
  540. /**
  541. * Test valid absolute urls.
  542. *
  543. * @see ValidUrlTestCase
  544. *
  545. * @todo Remove when http://drupal.org/node/1191252 is fixed.
  546. */
  547. function testFeedsValidURL() {
  548. $url_schemes = array('http', 'https', 'ftp', 'feed', 'webcal');
  549. $valid_absolute_urls = array(
  550. 'example.com',
  551. 'www.example.com',
  552. 'ex-ample.com',
  553. '3xampl3.com',
  554. 'example.com/paren(the)sis',
  555. 'example.com/index.html#pagetop',
  556. 'example.com:8080',
  557. 'subdomain.example.com',
  558. 'example.com/index.php?q=node',
  559. 'example.com/index.php?q=node&param=false',
  560. 'user@www.example.com',
  561. 'user:pass@www.example.com:8080/login.php?do=login&style=%23#pagetop',
  562. '127.0.0.1',
  563. 'example.org?',
  564. 'john%20doe:secret:foo@example.org/',
  565. 'example.org/~,$\'*;',
  566. 'caf%C3%A9.example.org',
  567. '[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html',
  568. 'graph.asfdasdfasdf.com/blarg/feed?access_token=133283760145143|tGew8jbxi1ctfVlYh35CPYij1eE',
  569. );
  570. foreach ($url_schemes as $scheme) {
  571. foreach ($valid_absolute_urls as $url) {
  572. $test_url = $scheme . '://' . $url;
  573. $valid_url = feeds_valid_url($test_url, TRUE);
  574. $this->assertTrue($valid_url, t('@url is a valid url.', array('@url' => $test_url)));
  575. }
  576. }
  577. $invalid_ablosule_urls = array(
  578. '',
  579. 'ex!ample.com',
  580. 'ex%ample.com',
  581. );
  582. foreach ($url_schemes as $scheme) {
  583. foreach ($invalid_ablosule_urls as $url) {
  584. $test_url = $scheme . '://' . $url;
  585. $valid_url = feeds_valid_url($test_url, TRUE);
  586. $this->assertFalse($valid_url, t('@url is NOT a valid url.', array('@url' => $test_url)));
  587. }
  588. }
  589. }
  590. }