Parcourir la source

add tests for addDirectory functionality

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@16113 44c647ce-9c0f-0410-b52a-842ac1e357ba
stas il y a 16 ans
Parent
commit
2f04d0a841

+ 77 - 0
tests/Zend/Amf/ServerTest.php

@@ -979,6 +979,82 @@ class Zend_Amf_ServerTest extends PHPUnit_Framework_TestCase
         // Zend_Session::stop();
     }
     
+    public function testAddDirectory()
+    {
+    	$this->_server->addDirectory(dirname(__FILE__)."/_files/services");
+    	$this->_server->addDirectory(dirname(__FILE__)."/_files/");
+    	$dirs = $this->_server->getDirectory();
+    	$this->assertContains(dirname(__FILE__)."/_files/services/", $dirs);
+    	$this->assertContains(dirname(__FILE__)."/_files/", $dirs);
+    }
+    
+    public function testAddDirectoryService()
+    {
+    	$this->_server->addDirectory(dirname(__FILE__)."/_files/services");
+    	// should take it from the path above, not include path
+    	set_include_path(get_include_path().PATH_SEPARATOR.dirname(__FILE__));
+    	// create a mock remoting message
+        $message = new Zend_Amf_Value_Messaging_RemotingMessage();
+        $message->operation = 'getMenu';
+        $message->source = 'ServiceC';
+        $message->body = array();
+        // create a mock message body to place th remoting message inside
+        $newBody = new Zend_Amf_Value_MessageBody(null,"/1", $message);
+        $request = new Zend_Amf_Request();
+        // at the requested service to a request
+        $request->addAmfBody($newBody);
+        $request->setObjectEncoding(0x03);
+        // let the server handle mock request
+        $this->_server->handle($request);
+        $response = $this->_server->getResponse()->getAMFBodies();
+        $this->assertTrue($response[0]->getData() instanceof Zend_Amf_Value_Messaging_AcknowledgeMessage);
+        $this->assertEquals("Service: MenuC", $response[0]->getData()->body);
+    }
+    
+    public function testAddDirectoryService2()
+    {
+    	$this->_server->addDirectory(dirname(__FILE__)."/_files/services");
+    	// create a mock remoting message
+        $message = new Zend_Amf_Value_Messaging_RemotingMessage();
+        $message->operation = 'getMenu';
+        $message->source = 'My.ServiceA';
+        $message->body = array();
+        // create a mock message body to place th remoting message inside
+        $newBody = new Zend_Amf_Value_MessageBody(null,"/1", $message);
+        $request = new Zend_Amf_Request();
+        // at the requested service to a request
+        $request->addAmfBody($newBody);
+        $request->setObjectEncoding(0x03);
+        // let the server handle mock request
+        $this->_server->handle($request);
+        $response = $this->_server->getResponse()->getAMFBodies();
+        $this->assertTrue($response[0]->getData() instanceof Zend_Amf_Value_Messaging_AcknowledgeMessage);
+        $this->assertEquals("Service: myMenuA", $response[0]->getData()->body);
+    }
+    
+    /*
+     * See ZF-6625
+     */
+    public function testAddDirectoryServiceNotFound()
+    {
+    	$this->_server->addDirectory(dirname(__FILE__)."/_files/services");
+    	// create a mock remoting message
+        $message = new Zend_Amf_Value_Messaging_RemotingMessage();
+        $message->operation = 'encode';
+        $message->source = 'Zend_Json';
+        $message->body = array("123");
+        // create a mock message body to place th remoting message inside
+        $newBody = new Zend_Amf_Value_MessageBody(null,"/1", $message);
+        $request = new Zend_Amf_Request();
+        // at the requested service to a request
+        $request->addAmfBody($newBody);
+        $request->setObjectEncoding(0x03);
+        // let the server handle mock request
+        $this->_server->handle($request);
+        $response = $this->_server->getResponse()->getAMFBodies();
+        $this->assertTrue($response[0]->getData() instanceof Zend_Amf_Value_Messaging_ErrorMessage);
+    }
+    
 }
 
 if (PHPUnit_MAIN_METHOD == "Zend_Amf_ServerTest::main") {
@@ -1118,6 +1194,7 @@ class Zend_Amf_testclass
     {
         return array_merge($arrayOne, $arrayTwo);
     }
+    
 }
 
 /**

+ 14 - 0
tests/Zend/Amf/ServiceC.php

@@ -0,0 +1,14 @@
+<?php
+class ServiceC {
+    function __construct() {        
+        //Construction...
+    }
+    
+    /**
+     * @return string
+     */
+    public function getMenu( )
+    {
+        return 'myMenuC';
+    }
+}

+ 14 - 0
tests/Zend/Amf/_files/services/My/ServiceA.php

@@ -0,0 +1,14 @@
+<?php
+class My_ServiceA {
+    function __construct() {        
+        //Construction...
+    }
+    
+    /**
+     * @return string
+     */
+    public function getMenu( )
+    {
+        return 'Service: myMenuA';
+    }
+}

+ 14 - 0
tests/Zend/Amf/_files/services/ServiceC.php

@@ -0,0 +1,14 @@
+<?php
+class ServiceC {
+    function __construct() {        
+        //Construction...
+    }
+    
+    /**
+     * @return string
+     */
+    public function getMenu( )
+    {
+        return 'Service: MenuC';
+    }
+}