2
// Call Zend_Amf_AuthTest::main() if this source file is executed directly.
3
if (!defined("PHPUnit_MAIN_METHOD")) {
4
define("PHPUnit_MAIN_METHOD", "Zend_Amf_ResourceTest::main");
7
require_once 'PHPUnit/Framework/TestCase.php';
8
require_once dirname(__FILE__) . '/../../TestHelper.php';
9
require_once 'Zend/Amf/Server.php';
10
require_once 'Zend/Amf/Request.php';
11
require_once 'Zend/Amf/Parse/TypeLoader.php';
12
require_once 'Zend/Amf/Value/Messaging/RemotingMessage.php';
17
class Zend_Amf_ResourceTest extends PHPUnit_Framework_TestCase
21
* Enter description here...
23
* @var Zend_Amf_Server
27
public static function main()
29
$suite = new PHPUnit_Framework_TestSuite("Zend_Amf_ResourceTest");
30
PHPUnit_TextUI_TestRunner::run($suite);
33
public function setUp()
35
$this->_server = new Zend_Amf_Server();
36
$this->_server->setProduction(false);
37
Zend_Amf_Parse_TypeLoader::resetMap();
40
protected function tearDown()
42
unset($this->_server);
45
protected function _callService($method, $class = 'Zend_Amf_Resource_testclass')
47
$request = new Zend_Amf_Request();
48
$request->setObjectEncoding(0x03);
49
$this->_server->setClass($class);
50
$newBody = new Zend_Amf_Value_MessageBody("$class.$method","/1",array("test"));
51
$request->addAmfBody($newBody);
52
$this->_server->handle($request);
53
$response = $this->_server->getResponse();
57
public function testFile()
59
$resp = $this->_callService("returnFile");
60
$this->assertContains("test data", $resp->getResponse());
64
* Defining new unknown resource type
66
* @expectException Zend_Amf_Server_Exception
69
public function testCtxNoResource()
72
$this->_callService("returnCtx");
73
} catch(Zend_Amf_Server_Exception $e) {
74
$this->assertContains("serialize resource type", $e->getMessage());
77
$this->fail("Failed to throw exception on unknown resource");
81
* Defining new unknown resource type via plugin loader and handling it
84
public function testCtxLoader()
86
Zend_Amf_Parse_TypeLoader::addResourceDirectory("Test_Resource", dirname(__FILE__)."/Resources");
87
$resp = $this->_callService("returnCtx");
88
$this->assertContains("Accept-language:", $resp->getResponse());
89
$this->assertContains("foo=bar", $resp->getResponse());
93
* Defining new unknown resource type and handling it
96
public function testCtx()
98
Zend_Amf_Parse_TypeLoader::setResourceLoader(new Zend_Amf_TestResourceLoader("2"));
99
$resp = $this->_callService("returnCtx");
100
$this->assertContains("Accept-language:", $resp->getResponse());
101
$this->assertContains("foo=bar", $resp->getResponse());
105
* Defining new unknown resource type, handler has no parse()
108
public function testCtxNoParse()
110
Zend_Amf_Parse_TypeLoader::setResourceLoader(new Zend_Amf_TestResourceLoader("3"));
112
$resp = $this->_callService("returnCtx");
113
} catch(Zend_Amf_Server_Exception $e) {
114
$this->assertContains("Could not call parse()", $e->getMessage());
117
$this->fail("Failed to throw exception on unknown resource");
122
class Zend_Amf_Resource_testclass {
123
function returnFile()
125
return fopen(dirname(__FILE__)."/_files/testdata", "r");
132
'header'=>"Accept-language: en\r\n" .
133
"Cookie: foo=bar\r\n"
136
$context = stream_context_create($opts);
143
public function parse($resource) {
144
return stream_context_get_options($resource);
149
protected function parse($resource) {
150
return stream_context_get_options($resource);
153
class Zend_Amf_TestResourceLoader implements Zend_Loader_PluginLoader_Interface {
155
public function __construct($suffix) {
156
$this->suffix = $suffix;
158
public function addPrefixPath($prefix, $path) {}
159
public function removePrefixPath($prefix, $path = null) {}
160
public function isLoaded($name) {}
161
public function getClassName($name) {}
162
public function load($name) {
163
return $name.$this->suffix;
167
if (PHPUnit_MAIN_METHOD == "Zend_Amf_ResourceTest::main") {
168
Zend_Amf_ResourceTest::main();