Autoload.php
9 years ago
TestEmbera.php
9 years ago
TestFakeResponse.php
9 years ago
TestFormatter.php
9 years ago
TestHttpRequest.php
9 years ago
TestOembed.php
9 years ago
TestProviders.php
9 years ago
TestServiceAmCharts.php
9 years ago
TestServiceAnimatron.php
9 years ago
TestServiceAnimoto.php
9 years ago
TestServiceAolOn.php
9 years ago
TestServiceAppNet.php
9 years ago
TestServiceAudioSnaps.php
9 years ago
TestServiceBambuser.php
9 years ago
TestServiceBlipTv.php
9 years ago
TestServiceCacoo.php
9 years ago
TestServiceChartblocks.php
9 years ago
TestServiceChirbit.php
9 years ago
TestServiceCircuitLab.php
9 years ago
TestServiceClyp.php
9 years ago
TestServiceCodepoints.php
9 years ago
TestServiceCollegeHumor.php
9 years ago
TestServiceCoub.php
9 years ago
TestServiceCrowdRanking.php
9 years ago
TestServiceDailyMile.php
9 years ago
TestServiceDailyMotion.php
9 years ago
TestServiceDeviantart.php
9 years ago
TestServiceDipity.php
9 years ago
TestServiceDotSub.php
9 years ago
TestServiceEdocr.php
9 years ago
TestServiceEgliseInfo.php
9 years ago
TestServiceFacebook.php
9 years ago
TestServiceFlickr.php
9 years ago
TestServiceFunnyOrDie.php
9 years ago
TestServiceGeographCI.php
9 years ago
TestServiceGeographDe.php
9 years ago
TestServiceGeographUk.php
9 years ago
TestServiceGettyImages.php
9 years ago
TestServiceGfycat.php
9 years ago
TestServiceGithubGist.php
9 years ago
TestServiceGmep.php
9 years ago
TestServiceHq23.php
9 years ago
TestServiceHuffduffer.php
9 years ago
TestServiceHulu.php
9 years ago
TestServiceIFTTT.php
9 years ago
TestServiceIFixIt.php
9 years ago
TestServiceInfogram.php
9 years ago
TestServiceInstagram.php
9 years ago
TestServiceIssuu.php
9 years ago
TestServiceIssuuFakeResponse.php
9 years ago
TestServiceKickstarter.php
9 years ago
TestServiceLearningApps.php
9 years ago
TestServiceMeetup.php
9 years ago
TestServiceMixCloud.php
9 years ago
TestServiceMobyPicture.php
9 years ago
TestServiceNFB.php
9 years ago
TestServiceOfficeMix.php
9 years ago
TestServiceOfficialFM.php
9 years ago
TestServiceOumy.php
9 years ago
TestServicePastery.php
9 years ago
TestServicePollDaddy.php
9 years ago
TestServicePollEverywhere.php
9 years ago
TestServicePortfolium.php
9 years ago
TestServiceRapidengage.php
9 years ago
TestServiceRdio.php
9 years ago
TestServiceReleaseWire.php
9 years ago
TestServiceRepubHub.php
9 years ago
TestServiceReverbnation.php
9 years ago
TestServiceRevision3.php
9 years ago
TestServiceRoomshare.php
9 years ago
TestServiceRutube.php
9 years ago
TestServiceSapo.php
9 years ago
TestServiceScreenr.php
9 years ago
TestServiceScribd.php
9 years ago
TestServiceShortNote.php
9 years ago
TestServiceShoudio.php
9 years ago
TestServiceShowTheWay.php
9 years ago
TestServiceSilk.php
9 years ago
TestServiceSketchfab.php
9 years ago
TestServiceSlideshare.php
9 years ago
TestServiceSoundCloud.php
9 years ago
TestServiceSpeakerDeck.php
9 years ago
TestServiceSpotify.php
9 years ago
TestServiceSway.php
9 years ago
TestServiceTed.php
9 years ago
TestServiceTheySaidSo.php
9 years ago
TestServiceTwitter.php
9 years ago
TestServiceUstream.php
9 years ago
TestServiceVerse.php
9 years ago
TestServiceViddler.php
9 years ago
TestServiceVideoFork.php
9 years ago
TestServiceVideoJug.php
9 years ago
TestServiceVimeo.php
9 years ago
TestServiceVine.php
9 years ago
TestServiceWordpressTV.php
9 years ago
TestServiceYFrog.php
9 years ago
TestServiceYandex.php
9 years ago
TestServiceYoutube.php
9 years ago
TestUrl.php
9 years ago
TestHttpRequest.php
170 lines
| 1 | <?php |
| 2 | /** |
| 3 | * TestHttpRequest.php |
| 4 | * |
| 5 | * @package Tests |
| 6 | * @author Michael Pratt <pratt@hablarmierda.net> |
| 7 | * @link http://www.michael-pratt.com/ |
| 8 | * |
| 9 | * For the full copyright and license information, please view the LICENSE |
| 10 | * file that was distributed with this source code. |
| 11 | */ |
| 12 | |
| 13 | class TestHttpRequest extends PHPUnit_Framework_TestCase |
| 14 | { |
| 15 | /** |
| 16 | * This needs more execution time .. |
| 17 | * @large |
| 18 | */ |
| 19 | public function testInvalidUrl() |
| 20 | { |
| 21 | $this->setExpectedException('Exception'); |
| 22 | |
| 23 | $http = new \Embera\HttpRequest(); |
| 24 | $http->fetch('this is an invalid url'); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * This needs more execution time .. |
| 29 | * @large |
| 30 | */ |
| 31 | public function testInvalidUrl2() |
| 32 | { |
| 33 | $this->setExpectedException('Exception'); |
| 34 | |
| 35 | if (!ini_get('allow_url_fopen')) |
| 36 | { |
| 37 | $this->markTestIncomplete('Could not test file_get_contents wrapper, allow_url_fopen is closed'); |
| 38 | return ; |
| 39 | } |
| 40 | |
| 41 | $http = new \Embera\HttpRequest(array('prefer_curl' => false)); |
| 42 | $http->fetch('this is an invalid url'); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * This needs more execution time .. |
| 47 | * @large |
| 48 | */ |
| 49 | public function testFetchCurl() |
| 50 | { |
| 51 | $http = new \Embera\HttpRequest(); |
| 52 | $response = $http->fetch('http://httpbin.org/user-agent'); |
| 53 | $response = json_decode($response, true); |
| 54 | |
| 55 | $this->assertEquals('Mozilla/5.0 PHP/Embera', $response['user-agent']); |
| 56 | |
| 57 | $config = array( |
| 58 | 'curl' => array( |
| 59 | CURLOPT_USERAGENT => 'PHP/Morcilla', |
| 60 | ) |
| 61 | ); |
| 62 | |
| 63 | $http = new \Embera\HttpRequest($config); |
| 64 | $response = $http->fetch('http://httpbin.org/user-agent'); |
| 65 | $response = json_decode($response, true); |
| 66 | |
| 67 | $this->assertEquals('PHP/Morcilla', $response['user-agent']); |
| 68 | |
| 69 | $config = array( |
| 70 | 'curl' => array( |
| 71 | CURLOPT_FOLLOWLOCATION => 0, |
| 72 | CURLOPT_USERAGENT => 'PHP/Morcilla 2', |
| 73 | ), |
| 74 | 'force_redirects' => true |
| 75 | ); |
| 76 | |
| 77 | $http = new \Embera\HttpRequest($config); |
| 78 | $response = $http->fetch('http://httpbin.org/relative-redirect/2'); |
| 79 | $response = json_decode($response, true); |
| 80 | |
| 81 | $this->assertEquals('http://httpbin.org/get', $response['url']); |
| 82 | |
| 83 | $response = $http->fetch('http://httpbin.org/redirect-to?url=' . urlencode('http://httpbin.org/user-agent')); |
| 84 | $response = json_decode($response, true); |
| 85 | |
| 86 | $this->assertEquals('PHP/Morcilla 2', $response['user-agent']); |
| 87 | |
| 88 | $config = array( |
| 89 | 'curl' => array( |
| 90 | CURLOPT_FOLLOWLOCATION => 1, |
| 91 | CURLOPT_USERAGENT => 'PHP/Morcilla 3', |
| 92 | ), |
| 93 | ); |
| 94 | |
| 95 | $http = new \Embera\HttpRequest($config); |
| 96 | $response = $http->fetch('http://httpbin.org/relative-redirect/2'); |
| 97 | $response = json_decode($response, true); |
| 98 | |
| 99 | $this->assertEquals('http://httpbin.org/get', $response['url']); |
| 100 | |
| 101 | $response = $http->fetch('http://httpbin.org/redirect-to?url=' . urlencode('http://httpbin.org/user-agent')); |
| 102 | $response = json_decode($response, true); |
| 103 | |
| 104 | $this->assertEquals('PHP/Morcilla 3', $response['user-agent']); |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * This needs more execution time .. |
| 109 | * @large |
| 110 | */ |
| 111 | public function testFetchFileGetcontents() |
| 112 | { |
| 113 | if (!ini_get('allow_url_fopen')) |
| 114 | { |
| 115 | $this->markTestIncomplete('Could not test file_get_contents wrapper, allow_url_fopen is closed'); |
| 116 | return ; |
| 117 | } |
| 118 | |
| 119 | $config = array( |
| 120 | 'prefer_curl' => false, |
| 121 | 'fopen' => array( |
| 122 | 'user_agent' => 'PHP/FGC Morcilla' |
| 123 | ) |
| 124 | ); |
| 125 | |
| 126 | $http = new \Embera\HttpRequest($config); |
| 127 | $response = $http->fetch('http://httpbin.org/user-agent'); |
| 128 | $response = json_decode($response, true); |
| 129 | |
| 130 | $this->assertEquals('PHP/FGC Morcilla', $response['user-agent']); |
| 131 | |
| 132 | $http = new \Embera\HttpRequest($config); |
| 133 | $response = $http->fetch('http://httpbin.org/relative-redirect/2'); |
| 134 | $response = json_decode($response, true); |
| 135 | |
| 136 | $this->assertEquals('http://httpbin.org/get', $response['url']); |
| 137 | |
| 138 | $response = $http->fetch('http://httpbin.org/redirect-to?url=' . urlencode('http://httpbin.org/user-agent')); |
| 139 | $response = json_decode($response, true); |
| 140 | |
| 141 | $this->assertEquals('PHP/FGC Morcilla', $response['user-agent']); |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * This needs more execution time .. |
| 146 | * @large |
| 147 | */ |
| 148 | public function testOptionsPrecedence() |
| 149 | { |
| 150 | $config = array( |
| 151 | 'curl' => array( |
| 152 | CURLOPT_USERAGENT => 'PHP/Morcilla 1', |
| 153 | ) |
| 154 | ); |
| 155 | |
| 156 | $http = new \Embera\HttpRequest($config); |
| 157 | $response = $http->fetch('http://httpbin.org/user-agent', array( |
| 158 | 'curl' => array( |
| 159 | CURLOPT_USERAGENT => 'PHP/Morcilla 2', |
| 160 | ) |
| 161 | )); |
| 162 | |
| 163 | $response = json_decode($response, true); |
| 164 | |
| 165 | $this->assertEquals('PHP/Morcilla 2', $response['user-agent']); |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | ?> |
| 170 |