1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
<?php
/**
* Copyright 2007-2014 Horde LLC (http://www.horde.org/)
*
* @category Horde
* @package Http
* @subpackage UnitTests
* @license http://www.horde.org/licenses/bsd
*/
/**
* Copyright 2007-2014 Horde LLC (http://www.horde.org/)
*
* @category Horde
* @package Http
* @subpackage UnitTests
* @license http://www.horde.org/licenses/bsd
*/
class Horde_Http_CurlTest extends Horde_Test_Case
{
private $_server;
public function setUp()
{
if (!function_exists('curl_exec')) {
$this->markTestSkipped('Missing PHP extension "curl"!');
}
$config = self::getConfig('HTTP_TEST_CONFIG');
if ($config && !empty($config['http']['server'])) {
$this->_server = $config['http']['server'];
}
}
/**
* @expectedException Horde_Http_Exception
*/
public function testThrowsOnBadUri()
{
$client = new Horde_Http_Client(array('request' => new Horde_Http_Request_Curl()));
$client->get('http://doesntexist/');
}
/**
* @expectedException Horde_Http_Exception
*/
public function testThrowsOnInvalidProxyType()
{
$client = new Horde_Http_Client(
array(
'request' => new Horde_Http_Request_Curl(
array(
'proxyServer' => 'localhost',
'proxyType' => Horde_Http::PROXY_SOCKS4
)
)
)
);
$client->get('http://www.example.com/');
}
public function testReturnsResponseInsteadOfExceptionOn404()
{
$this->_skipMissingConfig();
$client = new Horde_Http_Client(array('request' => new Horde_Http_Request_Curl()));
$response = $client->get('http://' . $this->_server . '/doesntexist');
$this->assertEquals(404, $response->code);
}
public function testGetBodyAfter404()
{
$this->_skipMissingConfig();
$client = new Horde_Http_Client(array('request' => new Horde_Http_Request_Curl()));
$response = $client->get('http://' . $this->_server . '/doesntexist');
$content = $response->getBody();
$this->assertTrue(!empty($content));
}
private function _skipMissingConfig()
{
if (empty($this->_server)) {
$this->markTestSkipped('Missing configuration!');
}
}
}
|