/usr/share/php/kohana3.1/system/tests/kohana/request/client/ExternalTest.php is in libkohana3.1-core-php 3.1.5-1.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | <?php defined('SYSPATH') OR die('Kohana bootstrap needs to be included before tests run');
/**
* Unit tests for external request client
*
* @group kohana
* @group kohana.request
* @group kohana.request.client
* @group kohana.request.client.external
*
* @package Kohana
* @category Tests
* @author Kohana Team
* @copyright (c) 2008-2011 Kohana Team
* @license http://kohanaframework.org/license
*/
class Kohana_Request_Client_ExternalTest extends Unittest_TestCase {
/**
* Provider for test_factory()
*
* @return array
*/
public function provider_factory()
{
Request_Client_External::$client = 'Request_Client_Stream';
$return = array(
array(
array(),
NULL,
'Request_Client_Stream'
),
array(
array(),
'Request_Client_Stream',
'Request_Client_Stream'
)
);
if (extension_loaded('curl'))
{
$return[] = array(
array(),
'Request_Client_Curl',
'Request_Client_Curl'
);
}
if (extension_loaded('http'))
{
$return[] = array(
array(),
'Request_Client_HTTP',
'Request_Client_HTTP'
);
}
return $return;
}
/**
* Tests the [Request_Client_External::factory()] method
*
* @dataProvider provider_factory
*
* @param array params
* @param string client
* @param Request_Client_External expected
* @return void
*/
public function test_factory($params, $client, $expected)
{
$this->assertInstanceOf($expected, Request_Client_External::factory($params, $client));
}
/**
* Data provider for test_options
*
* @return array
*/
public function provider_options()
{
return array(
array(
NULL,
NULL,
array()
),
array(
array('foo' => 'bar', 'stfu' => 'snafu'),
NULL,
array('foo' => 'bar', 'stfu' => 'snafu')
),
array(
'foo',
'bar',
array('foo' => 'bar')
),
array(
array('foo' => 'bar'),
'foo',
array('foo' => 'bar')
)
);
}
/**
* Tests the [Request_Client_External::options()] method
*
* @dataProvider provider_options
*
* @param mixed key
* @param mixed value
* @param array expected
* @return void
*/
public function test_options($key, $value, $expected)
{
// Create a mock external client
$client = new Request_Client_Stream;
$client->options($key, $value);
$this->assertSame($expected, $client->options());
}
/**
* Data provider for test_execute
*
* @return array
*/
public function provider_execute()
{
$json = '{"foo": "bar", "snafu": "stfu"}';
$post = array('foo' => 'bar', 'snafu' => 'stfu');
return array(
array(
'application/json',
$json,
array(),
array(
'content-type' => 'application/json',
'body' => $json
)
),
array(
'application/json',
$json,
$post,
array(
'content-type' => 'application/x-www-form-urlencoded',
'body' => http_build_query($post, NULL, '&')
)
)
);
}
/**
* Tests the [Request_Client_External::_send_message()] method
*
* @dataProvider provider_execute
*
* @return void
*/
public function test_execute($content_type, $body, $post, $expected)
{
$old_request = Request::$initial;
Request::$initial = TRUE;
// Create a mock Request
$request = new Request('http://kohanaframework.org/');
$request->method(HTTP_Request::POST)
->headers('content-type', $content_type)
->body($body)
->post($post);
$client = $this->getMock('Request_Client_External', array('_send_message'));
$client->expects($this->once())
->method('_send_message')
->with($request)
->will($this->returnValue($this->getMock('Response')));
$request->client($client);
$this->assertInstanceOf('Response', $request->execute());
$this->assertSame($expected['body'], $request->body());
$this->assertSame($expected['content-type'], (string) $request->headers('content-type'));
Request::$initial = $old_request;
}
}
|