public function testGenerateWsdl() { $generator = new CWsdlGenerator(); // we use any URL location since unit test is executed via CLI and not real HTTP request $wsdl = $generator->generateWsdl('SoapController', 'http://10.20.30.40/index.php?r=soap/calculator&ws=1'); // try to save XML output for manual checkup // uncomment to save WSDL into file //$this->assertTrue( 0 < file_put_contents($this->path, $wsdl), 'Failed saving WSDL into ['.$this->path.']'); $xml = simplexml_load_string($wsdl); // check input attribute with all attributes (minOccurs, maxOccurs, nillable) $node = $xml->xpath('//xsd:element[@name="subject"]'); $minOccurs = (string) $node[0]->attributes()->minOccurs; $this->assertTrue($minOccurs === '1'); $maxOccurs = (string) $node[0]->attributes()->maxOccurs; $this->assertTrue($maxOccurs === '1'); $nillable = (string) $node[0]->attributes()->nillable; $this->assertTrue($nillable === 'false'); $type = (string) $node[0]->attributes()->type; $this->assertTrue($type === 'xsd:integer'); // check input attribute with only nillable $node = $xml->xpath('//xsd:element[@name="ins_start_date"]'); $minOccurs = (string) $node[0]->attributes()->minOccurs; $this->assertTrue($minOccurs === ''); // null converts to empty string $maxOccurs = (string) $node[0]->attributes()->maxOccurs; $this->assertTrue($maxOccurs === ''); $nillable = (string) $node[0]->attributes()->nillable; $this->assertTrue($nillable === 'true'); $type = (string) $node[0]->attributes()->type; $this->assertTrue($type === 'xsd:date'); // check some output attribute $node = $xml->xpath('//xsd:element[@name="company_key"]'); $minOccurs = (string) $node[0]->attributes()->minOccurs; $this->assertTrue($minOccurs === '1'); $maxOccurs = (string) $node[0]->attributes()->maxOccurs; $this->assertTrue($maxOccurs === '1'); $nillable = (string) $node[0]->attributes()->nillable; $this->assertTrue($nillable === 'false'); $type = (string) $node[0]->attributes()->type; $this->assertTrue($type === 'xsd:string'); }
/** * Generates the WSDL as defined by the provider. * The cached version may be used if the WSDL is found valid in cache. * @return string the generated WSDL * @see wsdlCacheDuration */ public function generateWsdl() { $providerClass = is_object($this->provider) ? get_class($this->provider) : Yii::import($this->provider, true); if ($this->wsdlCacheDuration > 0 && $this->cacheID !== false && ($cache = Yii::app()->getComponent($this->cacheID)) !== null) { $key = 'Yii.CWebService.' . $providerClass . $this->serviceUrl . $this->encoding; if (($wsdl = $cache->get($key)) !== false) { return $wsdl; } } $generator = new CWsdlGenerator(); $wsdl = $generator->generateWsdl($providerClass, $this->serviceUrl, $this->encoding); if (isset($key)) { $cache->set($key, $wsdl, $this->wsdlCacheDuration); } return $wsdl; }
/** * Test generation of HTML documentation */ public function testGenerateHtmlDocumentation() { $generator = new CWsdlGenerator(); // we dont care this time about WSDL, we simple must craete some parsed data $generator->generateWsdl('SoapController', 'http://10.20.30.40/index.php?r=soap/calculator&ws=1'); // get HTML documentation $html = $generator->buildHtmlDocs(true); // uncomment to save WSDL into file /* $this->path=Yii::getPathOfAlias('application.runtime').DIRECTORY_SEPARATOR.'soap-wsdl-test-doc.html'; if(is_file($this->path)) unlink($this->path); $this->assertTrue( 0 < file_put_contents($this->path, $html), 'Failed saving WSDL into ['.$this->path.']'); */ // check we have table for object SoapPovCalculationInput $this->assertTrue(false !== strpos($html, 'SoapPovCalculationInput')); // check column Attribute in table SoapPovCalculationInput $this->assertTrue(false !== strpos($html, 'use_kind')); // check column Type in table SoapPovCalculationInput $this->assertTrue(false !== strpos($html, 'integer')); // check column Required in table SoapPovCalculationInput $this->assertTrue(false !== strpos($html, 'unbounded')); // check column Description in table SoapPovCalculationInput $this->assertTrue(false !== strpos($html, 'the date of birth RRRR.MM.DD')); // check column Example in table SoapPovCalculationInput $this->assertTrue(false !== strpos($html, '85HN65')); }