Ticket #377: testApp.diff

File testApp.diff, 14.3 kB (added by sylvain261, 9 months ago)

Ajout des tests Soap à testApp (inclue la maj de testapp.mn)

  • ../../testapp/www/soap.php

    old new  
     1<?php 
     2/** 
     3* @package       jelix 
     4* @subpackage    testapp 
     5* @author        Sylvain de Vathaire 
     6* @contributor   Jouanneau Laurent 
     7* @copyright     2008 Sylvain de Vathaire 
     8* @copyright     2008 Jouanneau laurent 
     9* @link          http://www.jelix.org 
     10* @licence       http://www.gnu.org/licenses/gpl.html GNU General Public Licence, see LICENCE file 
     11*/ 
     12require_once ('../../lib/jelix/init.php'); 
     13require_once ('../../testapp/application.init.php'); 
     14 
     15require_once (JELIX_LIB_CORE_PATH.'jSoapCoordinator.class.php'); 
     16 
     17require_once (JELIX_LIB_CORE_PATH.'request/jSoapRequest.class.php'); 
     18 
     19ini_set("soap.wsdl_cache_enabled", "0"); // disabling PHP's WSDL cache 
     20 
     21 
     22$config_file = 'index/config.ini.php'; 
     23$jelix = new JSoapCoordinator($config_file); 
     24$jelix->request = new JSoapRequest(); 
     25$jelix->request->initService(); 
     26$jelix->processSoap(); 
     27?> 
  • ../../testapp/modules/testapp/controllers/clientSoap.classic.php

    old new  
     1<?php 
     2/** 
     3* @package     testapp 
     4* @subpackage  testapp module 
     5* @version     1 
     6* @author      Sylvain de Vathaire 
     7* @contributor 
     8* @copyright   2008 Sylvain de Vathaire 
     9* @link        http://www.jelix.org 
     10* @licence     GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html 
     11*/ 
     12 
     13/** 
     14* Tests of soapCtrl web services  
     15*/ 
     16class clientSoapCtrl extends jController { 
     17 
     18    var $module = 'testapp'; 
     19 
     20    var $controller = 'soap'; 
     21 
     22     
     23    /**   
     24     * Test with the soap extension 
     25     * @return string Server date 
     26     */ 
     27    function soapExtension() { 
     28 
     29        ini_set('soap.wsdl_cache_enabled', 0); 
     30        global $gJConfig; 
     31        $rep = $this->getResponse('html'); 
     32        $rep->title = 'Client utilisant l\'extension soap pour faire appel au serveur soap Jelix'; 
     33        $rep->body->assign('page_title','Client utilisant l\'extension soap pour faire appel au serveur soap Jelix'); 
     34 
     35        $tpl = new jTpl(); 
     36        $tpl->assign('liste', array());  
     37 
     38 
     39        // Load the WSDL 
     40        try { 
     41            $wsdlURI = "http://".$_SERVER['HTTP_HOST'].$gJConfig->urlengine['basePath'].'index.php?service='.$this->module.'~'.$this->controller.'&module=jWSDL&action=WSDL:wsdl'; 
     42            $client = new SoapClient($wsdlURI, array('trace' => 1, 'soap_version'  => SOAP_1_1)); 
     43        } catch (SoapFault $fault) { 
     44            throw new Exception($fault->getMessage()); 
     45        } 
     46 
     47        try { 
     48            $result = $client->__soapCall('getServerDate', array()); 
     49            $tpl->assign("getServerDate", $result); 
     50 
     51            $result =  $client->__soapCall('hello', array('Sylvain')); 
     52            $tpl->assign("hello", $result); 
     53 
     54            $result =  $client->__soapCall('concatString', array('Hi ! ', 'Sylvain', 'How are you ?')); 
     55            $tpl->assign("concatString", $result); 
     56 
     57            $result =  $client->__soapCall('concatArray', array(array('Hi ! ', 'Sylvain', 'How are you ?'))); 
     58            $tpl->assign("concatArray", $result); 
     59 
     60            $result =  $client->__soapCall('returnAssociativeArray', array()); 
     61            $tpl->assign("returnAssociativeArray", $result); 
     62 
     63            $result =  $client->__soapCall('returnAssociativeArrayOfObjects', array()); 
     64            $tpl->assign("returnAssociativeArrayOfObjects", $result); 
     65 
     66            $result =  $client->__soapCall('concatAssociativeArray', array(array('arg1'=>'Hi ! ', 'arg2'=>'Sylvain', 'arg3'=>'How are you ?'))); 
     67            $tpl->assign("concatAssociativeArray", $result); 
     68 
     69            $result =  $client->__soapCall('returnObject', array()); 
     70            $tpl->assign("returnObject", $result); 
     71 
     72            $result =  $client->__soapCall('receiveObject', array($result)); 
     73            $tpl->assign("receiveObject", $result); 
     74 
     75            $result =  $client->__soapCall('returnObjects', array()); 
     76            $tpl->assign("returnObjects", $result); 
     77 
     78            $result =  $client->__soapCall('returnObjectBis', array()); 
     79            $tpl->assign("returnObjectBis", $result); 
     80 
     81            $result =  $client->__soapCall('returnCircularReference', array()); 
     82            $tpl->assign("returnCircularReference", $result); 
     83 
     84        } catch (SoapFault $fault) { 
     85            print_r($fault); 
     86            throw new Exception($fault->getMessage()); 
     87        } 
     88 
     89        $rep->body->assign('MAIN',$tpl->fetch('soap')); 
     90        return $rep; 
     91    } 
     92} 
     93?> 
  • ../../testapp/modules/testapp/controllers/soap.soap.php

    old new  
     1<?php 
     2/** 
     3* @package     testapp 
     4* @subpackage  testapp module 
     5* @version     1 
     6* @author      Sylvain de Vathaire 
     7* @contributor 
     8* @copyright   2008 Sylvain de Vathaire 
     9* @link        http://www.jelix.org 
     10* @licence     GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html 
     11*/ 
     12 
     13/** 
     14* Web Services usefull to test SOAP request handling, WSDL generation, web servives documentation generation 
     15*/ 
     16class soapCtrl extends jController { 
     17 
     18    /**   
     19     * Test without any parameter 
     20     * @return string Server date 
     21     */ 
     22    function getServerDate() { 
     23        $rep = $this->getResponse('soap'); 
     24        $rep->data = date('Y-m-d\TH:i:s O'); 
     25        return $rep; 
     26    } 
     27 
     28    /**  
     29     * Test with a simple parameter 
     30     * @param string $name 
     31     * @return string 
     32     */ 
     33    function hello() { 
     34        $rep = $this->getResponse('soap'); 
     35        $rep->data = "Hello ".$this->param('name'); 
     36        return $rep; 
     37    } 
     38 
     39 
     40    /**  
     41     * Test with multiple string param 
     42     * @param string $string1  
     43     * @param string $string2  
     44     * @param string $string3 
     45     * @return string 
     46     */ 
     47    function concatString() { 
     48        $rep = $this->getResponse('soap'); 
     49        $rep->data = $this->param('string1').$this->param('string2').$this->param('string3'); 
     50        return $rep; 
     51    } 
     52 
     53    /**  
     54     * Test with an array as param 
     55     * @param string[] $myArray 
     56     * @return string 
     57     */ 
     58    function concatArray() { 
     59        $rep = $this->getResponse('soap'); 
     60        $rep->data = implode(' ', $this->param('myArray')); 
     61        return $rep; 
     62    } 
     63 
     64   /**  
     65     * Test with an associative array as param 
     66     * @param string[=>] $myArray 
     67     * @return string 
     68     */ 
     69    function concatAssociativeArray() { 
     70        $rep = $this->getResponse('soap'); 
     71        $myArray = $this->param('myArray'); 
     72        $rep->data = $myArray['arg1'].' '.$myArray['arg2'].' '.$myArray['arg3']; 
     73        return $rep; 
     74    } 
     75 
     76   /**  
     77     * Test with an associative array as return value 
     78     * @return string[=>] 
     79     */ 
     80    function returnAssociativeArray() { 
     81        $rep = $this->getResponse('soap'); 
     82        $rep->data = array('arg1'=>'Hi ! ', 'arg2'=>'Sylvain', 'arg3'=>'How are you ?'); 
     83        return $rep; 
     84    } 
     85 
     86   /**  
     87     * Test with an associative array ob object as return value 
     88     * @return MyTestStructQuatre[=>] 
     89     */ 
     90    function returnAssociativeArrayOfObjects() { 
     91        $rep = $this->getResponse('soap'); 
     92        $rep->data = array('arg1'=>new MyTestStructQuatre(), 'arg2'=>new MyTestStructQuatre(), 'arg3'=>new MyTestStructQuatre()); 
     93        return $rep; 
     94    } 
     95 
     96 
     97    /**  
     98     * Test that return an object 
     99     * @return MyTestStruct 
     100     */ 
     101    function returnObject() { 
     102        $rep = $this->getResponse('soap'); 
     103        $rep->data = new MyTestStruct(); 
     104        return $rep; 
     105    } 
     106 
     107   /**  
     108     * Test that return an array of objects 
     109     * @return MyTestStruct[] Tableau d'objet de test 
     110     */ 
     111    function returnObjects() { 
     112        $rep = $this->getResponse('soap'); 
     113        $rep->data = array(new MyTestStruct(), new MyTestStruct(), new MyTestStruct(), new MyTestStruct()); 
     114        return $rep; 
     115    } 
     116 
     117 
     118    /**  
     119     * Test that receive an object and return an object 
     120     * @param MyTestStruct $input 
     121     * @return MyTestStruct 
     122     */ 
     123    function receiveObject() { 
     124        $rep = $this->getResponse('soap'); 
     125        $input = $this->param('input'); 
     126        $input->name = 'Name updated'; 
     127        $rep->data = $input; 
     128        return $rep; 
     129    } 
     130 
     131    /** 
     132     * Test that return an object which have an other object as member propertie 
     133     * @return MyTestStructBis 
     134     */ 
     135    function returnObjectBis() { 
     136        $rep = $this->getResponse('soap'); 
     137        $rep->data = new MyTestStructBis(); 
     138        return $rep; 
     139    } 
     140 
     141    /** 
     142     * Test of circular references 
     143     * @return MyTestStructTer[] 
     144     */ 
     145    function returnCircularReference() { 
     146        $rep = $this->getResponse('soap'); 
     147        $object1 = new MyTestStructTer('object1'); 
     148        $object2 = new MyTestStructTer('object2'); 
     149        $object1->test = $object2; 
     150        $object2->test = $object1; 
     151        $rep->data = array($object1, $object2); 
     152        return $rep; 
     153    } 
     154 
     155} 
     156/** 
     157 * Struct used for tests 
     158 */ 
     159class MyTestStruct{ 
     160    /** 
     161     * @var string 
     162     */ 
     163    public $name = 'De Vathaire'; 
     164 
     165    /** 
     166     * @var string 
     167     */ 
     168    public $firstName = 'Sylvain'; 
     169 
     170    /** 
     171     * @var string 
     172     */ 
     173    public $city = 'Paris'; 
     174} 
     175 
     176/** 
     177 * An other struct used for test, this one have an other object as member propertie 
     178 */ 
     179class MyTestStructBis{ 
     180 
     181    /** 
     182     * @var MyTestStruct 
     183     */ 
     184    public $test; 
     185 
     186    /** 
     187     * @var string 
     188     */ 
     189    public $msg = 'hello'; 
     190 
     191    function __construct(){ 
     192        $this->test = new MyTestStruct(); 
     193    } 
     194 
     195} 
     196 
     197/** 
     198 * An other struct used for test, this one have is used to test circular references 
     199 */ 
     200class MyTestStructTer{ 
     201 
     202    /** 
     203     * @var MyTestStructTer 
     204     */ 
     205    public $test; 
     206 
     207    /** 
     208     * @var string 
     209     */ 
     210    public $msg; 
     211 
     212    function __construct($msg){ 
     213        $this->msg = $msg; 
     214    } 
     215 
     216} 
     217 
     218/** 
     219 * An other struct used for test, this one is used to test associative array of objects 
     220 */ 
     221class MyTestStructQuatre{ 
     222 
     223    /** 
     224     * @var string 
     225     */ 
     226    public $name = 'De Vathaire'; 
     227 
     228    /** 
     229     * @var string 
     230     */ 
     231    public $firstName = 'Sylvain'; 
     232 
     233    /** 
     234     * @var string 
     235     */ 
     236    public $city = 'Paris'; 
     237} 
     238?> 
  • ../../testapp/modules/testapp/templates/soap.tpl

    old new  
     1<h1>getServerDate()</h1> 
     2<p>{$getServerDate}</p> 
     3 
     4<h1>hello('sylvain')</h1> 
     5<p>{$hello}</p> 
     6 
     7<h1>concatString('Hi ! ', 'Sylvain', 'How are you ?')</h1> 
     8<p>{$concatString}</p> 
     9 
     10 
     11<h1>concatArray(array('Hi ! ', 'Sylvain', 'How are you ?'))</h1> 
     12<p>{$concatArray}</p> 
     13 
     14 
     15<h1>concatAssociativeArray(array('arg1'=>'Hi ! ', 'arg2'=>'Sylvain', 'arg3'=>'How are you ?'))</h1> 
     16<p>{$concatAssociativeArray}</p> 
     17 
     18 
     19<h1>returnAssociativeArray()</h1> 
     20<p> 
     21arg1 : {$returnAssociativeArray['arg1']}<br/> 
     22arg2 : {$returnAssociativeArray['arg2']}<br/> 
     23arg3 : {$returnAssociativeArray['arg3']}<br/> 
     24</p> 
     25 
     26<h1>returnObject()</h1> 
     27<p> 
     28Name : {$returnObject->name}<br/> 
     29FirstName : {$returnObject->firstName}<br/> 
     30City : {$returnObject->city}<br/> 
     31</p> 
     32 
     33<h1>receiveObject($returnObject)</h1> 
     34<p> 
     35Name : {$receiveObject->name}<br/> 
     36FirstName : {$receiveObject->firstName}<br/> 
     37City : {$receiveObject->city}<br/> 
     38</p> 
     39 
     40 
     41<h1>returnObjects()</h1> 
     42<p> 
     43{foreach $returnObjects as $object} 
     44        <strong>Object</strong><br/> 
     45        Name : {$object->name}<br/> 
     46        FirstName : {$object->firstName}<br/> 
     47        City : {$object->city}<br/> 
     48{/foreach} 
     49</p> 
     50 
     51<h1>returnAssociativeArrayOfObjects()</h1> 
     52<p> 
     53{for $i=1;$i<=3;$i++} 
     54        <strong>$returnAssociativeArrayOfObjects['arg{$i}']</strong><br/> 
     55        Name : {$returnAssociativeArrayOfObjects['arg'.$i]->name}<br/> 
     56        FirstName : {$returnAssociativeArrayOfObjects['arg'.$i]->firstName}<br/> 
     57        City : {$returnAssociativeArrayOfObjects['arg'.$i]->city}<br/> 
     58{/for} 
     59</p> 
     60 
     61 
     62<h1>returnObjectBis()</h1> 
     63<p>Msg : {$returnObjectBis->msg}<br/> 
     64Name : {$returnObjectBis->test->name}<br/> 
     65FirstName : {$returnObjectBis->test->firstName}<br/> 
     66City : {$returnObjectBis->test->city}<br/> 
     67</p> 
     68 
     69<h1>returnCircularReference()</h1> 
     70<p> 
     71{foreach $returnCircularReference as $object} 
     72        <strong>{$object->msg}</strong><br/> 
     73        $object->test->msg : {$object->test->msg}<br/> 
     74        $object->test->test->msg : {$object->test->test->msg}<br/> 
     75{/foreach} 
     76</p> 
     77 
     78<p><a href="{jurl 'main:index'}">Retour au sommaire</a></p> 
     79 
  • ../../testapp/modules/testapp/templates/sommaire.tpl

    old new  
    3939   <li><a href="{jurl 'syndication:rss'}">Rss 2.0</a></li> 
    4040   <li><a href="{jurl 'syndication:atom'}">Atom 1.0</a></li> 
    4141</ul> 
     42 
     43<h3>Tests soap</h3> 
     44<ul> 
     45   <li><a href="{jurl 'clientSoap:soapExtension'}">client (soap extension)</a></li> 
     46   <li><a href="{jurl 'jWSDL~WSDL:index'}">Web services documentation</a></li> 
     47   <li><a href="{jurl 'jWSDL~WSDL:wsdl', array('service'=>'testapp~soap')}">WSDL</a></li> 
     48</ul> 
  • ../../build/manifests/testapp.mn

    old new  
    1414  .htaccess 
    1515  xmlrpc.php 
    1616  index.php 
     17  soap.php 
    1718  testnews.php 
    1819  check.php 
    1920cd testapp/www/foo 
     
    5152  syndication.classic.php 
    5253  samplecrud.classic.php 
    5354  default.cmdline.php 
     55  clientSoap.classic.php 
     56  soap.soap.php 
    5457cd testapp/modules/testapp/templates 
    5558  hello.tpl 
    5659  hello2.tpl 
     
    6366  forms_edit.tpl 
    6467  forms_liste.tpl 
    6568  forms_view.tpl 
     69  soap.tpl 
    6670cd testapp/modules/testapp/zones 
    6771  test.zone.php 
    6872  sommaire.zone.php 
Download in other formats: Original Format