| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359 | 
							- <?php
 
- /**
 
-  * @file
 
-  * Tests for http_request.inc.
 
-  */
 
- /**
 
-  * Tests for the http library.
 
-  */
 
- class FeedsHTTPRequestTestCase extends FeedsUnitTestHelper {
 
-   public static function getInfo() {
 
-     return array(
 
-       'name' => 'HTTP library',
 
-       'description' => 'Tests for Feeds HTTP library.',
 
-       'group' => 'Feeds',
 
-     );
 
-   }
 
-   public function setUp() {
 
-     parent::setUp();
 
-     feeds_include_library('http_request.inc', 'http_request');
 
-   }
 
-   /**
 
-    * Tests http_request_find_feeds().
 
-    */
 
-   public function testHTTPRequestFindFeeds() {
 
-     $html = <<<EOF
 
- <html>
 
-   <head>
 
-     <title>Welcome to Example.com</title>
 
-     <link rel="stylesheet" type="text/css" media="screen, projection" href="/stuff.css" >
 
-     <link rel="search"    title="Something" href="//example.com/search">
 
-     <link rel="alternate" title="Something RSS" href="http://example.com/rss.xml" type="application/rss+xml">
 
-     <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
 
-   </head>
 
-   <body>
 
-     This is a body.
 
-   </body>
 
- </html
 
- EOF;
 
-     $links = http_request_find_feeds($html);
 
-     $this->assertEqual(count($links), 1);
 
-     $this->assertEqual($links[0], 'http://example.com/rss.xml');
 
-     // Test single quoted HTML.
 
-     $links = http_request_find_feeds(str_replace('"', "'", $html));
 
-     $this->assertEqual(count($links), 1);
 
-     $this->assertEqual($links[0], 'http://example.com/rss.xml');
 
-   }
 
-   /**
 
-    * Tests http_request_create_absolute_url().
 
-    */
 
-   public function testHTTPRequestCreateAbsoluteUrl() {
 
-     $test_urls = array(
 
-       // Rels that do not start with "/".
 
-       array(
 
-         'rel'    => 'h',
 
-         'base'   => 'http://www',
 
-         'expected' => 'http://www/h',
 
-       ),
 
-       array(
 
-         'rel'    => 'h',
 
-         'base'   => 'http://www/',
 
-         'expected' => 'http://www/h',
 
-       ),
 
-       array(
 
-         'rel'    => 'h',
 
-         'base'   => 'http://www/?c;d=e#f',
 
-         'expected' => 'http://www/h',
 
-       ),
 
-       array(
 
-         'rel'    => 'h',
 
-         'base'   => 'http://www/a/b',
 
-         'expected' => 'http://www/a/h',
 
-       ),
 
-       array(
 
-         'rel'    => 'h/j',
 
-         'base'   => 'http://www',
 
-         'expected' => 'http://www/h/j',
 
-       ),
 
-       array(
 
-         'rel'    => 'h/j',
 
-         'base'   => 'http://www/',
 
-         'expected' => 'http://www/h/j',
 
-       ),
 
-       array(
 
-         'rel'    => 'h/j',
 
-         'base'   => 'http://www/?c;d=e#f',
 
-         'expected' => 'http://www/h/j',
 
-       ),
 
-       array(
 
-         'rel'    => 'h/j',
 
-         'base'   => 'http://www/a/b',
 
-         'expected' => 'http://www/a/h/j',
 
-       ),
 
-       array(
 
-         'rel'    => 'h/j',
 
-         'base'   => 'http://www/a/b/',
 
-         'expected' => 'http://www/a/b/h/j',
 
-       ),
 
-       // Rels that start with "/".
 
-       array(
 
-         'rel'    => '/h',
 
-         'base'   => 'http://www',
 
-         'expected' => 'http://www/h',
 
-       ),
 
-       array(
 
-         'rel'    => '/h',
 
-         'base'   => 'http://www/',
 
-         'expected' => 'http://www/h',
 
-       ),
 
-       array(
 
-         'rel'    => '/h',
 
-         'base'   => 'http://www/?c;d=e#f',
 
-         'expected' => 'http://www/h',
 
-       ),
 
-       array(
 
-         'rel'    => '/h',
 
-         'base'   => 'http://www/a/b',
 
-         'expected' => 'http://www/h',
 
-       ),
 
-       array(
 
-         'rel'    => '/h/j',
 
-         'base'   => 'http://www',
 
-         'expected' => 'http://www/h/j',
 
-       ),
 
-       array(
 
-         'rel'    => '/h/j',
 
-         'base'   => 'http://www/',
 
-         'expected' => 'http://www/h/j',
 
-       ),
 
-       array(
 
-         'rel'    => '/h/j',
 
-         'base'   => 'http://www/?c;d=e#f',
 
-         'expected' => 'http://www/h/j',
 
-       ),
 
-       array(
 
-         'rel'    => '/h/j',
 
-         'base'   => 'http://www/a/b',
 
-         'expected' => 'http://www/h/j',
 
-       ),
 
-       array(
 
-         'rel'    => '/h/j',
 
-         'base'   => 'http://www/a/b/',
 
-         'expected' => 'http://www/h/j',
 
-       ),
 
-       // Rels that contain ".".
 
-       array(
 
-         'rel'    => './h',
 
-         'base'   => 'http://www',
 
-         'expected' => 'http://www/h',
 
-       ),
 
-       array(
 
-         'rel'    => './h',
 
-         'base'   => 'http://www/',
 
-         'expected' => 'http://www/h',
 
-       ),
 
-       array(
 
-         'rel'    => './h',
 
-         'base'   => 'http://www/?c;d=e#f',
 
-         'expected' => 'http://www/h',
 
-       ),
 
-       array(
 
-         'rel'    => './h',
 
-         'base'   => 'http://www/a/b',
 
-         'expected' => 'http://www/a/h',
 
-       ),
 
-       array(
 
-         'rel'    => './h/j',
 
-         'base'   => 'http://www',
 
-         'expected' => 'http://www/h/j',
 
-       ),
 
-       array(
 
-         'rel'    => './h/j',
 
-         'base'   => 'http://www/',
 
-         'expected' => 'http://www/h/j',
 
-       ),
 
-       array(
 
-         'rel'    => './h/j',
 
-         'base'   => 'http://www/?c;d=e#f',
 
-         'expected' => 'http://www/h/j',
 
-       ),
 
-       array(
 
-         'rel'    => './h/j',
 
-         'base'   => 'http://www/a/b',
 
-         'expected' => 'http://www/a/h/j',
 
-       ),
 
-       array(
 
-         'rel'    => './h/j',
 
-         'base'   => 'http://www/a/b/',
 
-         'expected' => 'http://www/a/b/h/j',
 
-       ),
 
-       array(
 
-         'rel'    => 'h/./j',
 
-         'base'   => 'http://www',
 
-         'expected' => 'http://www/h/j',
 
-       ),
 
-       array(
 
-         'rel'    => 'h/./j',
 
-         'base'   => 'http://www/',
 
-         'expected' => 'http://www/h/j',
 
-       ),
 
-       array(
 
-         'rel'    => 'h/./j',
 
-         'base'   => 'http://www/?c;d=e#f',
 
-         'expected' => 'http://www/h/j',
 
-       ),
 
-       array(
 
-         'rel'    => 'h/./j',
 
-         'base'   => 'http://www/a/b',
 
-         'expected' => 'http://www/a/h/j',
 
-       ),
 
-       array(
 
-         'rel'    => 'h/./j',
 
-         'base'   => 'http://www/a/b/',
 
-         'expected' => 'http://www/a/b/h/j',
 
-       ),
 
-       array(
 
-         'rel'    => '/h/./j',
 
-         'base'   => 'http://www',
 
-         'expected' => 'http://www/h/j',
 
-       ),
 
-       array(
 
-         'rel'    => '/h/./j',
 
-         'base'   => 'http://www/',
 
-         'expected' => 'http://www/h/j',
 
-       ),
 
-       array(
 
-         'rel'    => '/h/./j',
 
-         'base'   => 'http://www/?c;d=e#f',
 
-         'expected' => 'http://www/h/j',
 
-       ),
 
-       array(
 
-         'rel'    => '/h/./j',
 
-         'base'   => 'http://www/a/b',
 
-         'expected' => 'http://www/h/j',
 
-       ),
 
-       array(
 
-         'rel'    => '/h/./j',
 
-         'base'   => 'http://www/a/b/',
 
-         'expected' => 'http://www/h/j',
 
-       ),
 
-       // Rels that starts with "../".
 
-       array(
 
-         'rel'    => '../h/j',
 
-         'base'   => 'http://www',
 
-         'expected' => 'http://www/h/j',
 
-       ),
 
-       array(
 
-         'rel'    => '../h/j',
 
-         'base'   => 'http://www/',
 
-         'expected' => 'http://www/h/j',
 
-       ),
 
-       array(
 
-         'rel'    => '../h/j',
 
-         'base'   => 'http://www/?c;d=e#f',
 
-         'expected' => 'http://www/h/j',
 
-       ),
 
-       array(
 
-         'rel'    => '../h/j',
 
-         'base'   => 'http://www/a/b',
 
-         'expected' => 'http://www/h/j',
 
-       ),
 
-       array(
 
-         'rel'    => '../h/j',
 
-         'base'   => 'http://www/a/b/',
 
-         'expected' => 'http://www/a/h/j',
 
-       ),
 
-       array(
 
-         'rel'    => '../h/j',
 
-         'base'   => 'http://www/a/b/c/',
 
-         'expected' => 'http://www/a/b/h/j',
 
-       ),
 
-       // Rels that start with "../../".
 
-       array(
 
-         'rel'    => '../../h/j',
 
-         'base'   => 'http://www',
 
-         'expected' => 'http://www/h/j',
 
-       ),
 
-       array(
 
-         'rel'    => '../../h/j',
 
-         'base'   => 'http://www/',
 
-         'expected' => 'http://www/h/j',
 
-       ),
 
-       array(
 
-         'rel'    => '../../h/j',
 
-         'base'   => 'http://www/?c;d=e#f',
 
-         'expected' => 'http://www/h/j',
 
-       ),
 
-       array(
 
-         'rel'    => '../../h/j',
 
-         'base'   => 'http://www/a/b',
 
-         'expected' => 'http://www/h/j',
 
-       ),
 
-       array(
 
-         'rel'    => '../../h/j',
 
-         'base'   => 'http://www/a/b/',
 
-         'expected' => 'http://www/h/j',
 
-       ),
 
-       array(
 
-         'rel'    => '../../h/j',
 
-         'base'   => 'http://www/a/b/c/',
 
-         'expected' => 'http://www/a/h/j',
 
-       ),
 
-       array(
 
-         'rel'    => '../../h/j',
 
-         'base'   => 'http://www/a/b/c/d',
 
-         'expected' => 'http://www/a/h/j',
 
-       ),
 
-       // Crazy rels.
 
-       array(
 
-         'rel'    => 'h/../../j/./k',
 
-         'base'   => 'http://www/a/b/c/',
 
-         'expected' => 'http://www/a/b/j/k',
 
-       ),
 
-       array(
 
-         'rel'    => 'h/../../j/./k',
 
-         'base'   => 'http://www/a/b/c/d',
 
-         'expected' => 'http://www/a/b/j/k',
 
-       ),
 
-       array(
 
-         'rel'    => '../../../',
 
-         'base'   => 'http://www/a/b/c/',
 
-         'expected' => 'http://www/',
 
-       ),
 
-       array(
 
-         'rel'    => 'h/j/k/../../',
 
-         'base'   => 'http://www/a/b/c/',
 
-         'expected' => 'http://www/a/b/c/h',
 
-       ),
 
-     );
 
-     foreach ($test_urls as $test_url) {
 
-       $result_url = http_request_create_absolute_url($test_url['rel'], $test_url['base']);
 
-       $this->assertEqual($test_url['expected'], $result_url, format_string('Creating an absolute URL from base @base and rel @rel resulted into @expected (actual: @actual).', array(
 
-         '@actual' => var_export($result_url, TRUE),
 
-         '@expected' => var_export($test_url['expected'], TRUE),
 
-         '@rel' => var_export($test_url['rel'], TRUE),
 
-         '@base' => var_export($test_url['base'], TRUE),
 
-       )));
 
-     }
 
-   }
 
- }
 
 
  |