WsdlGenerationFromDataObjectTest.php 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Webapi;
  7. use Magento\TestFramework\Helper\Bootstrap;
  8. /**
  9. * Test WSDL generation mechanisms.
  10. */
  11. class WsdlGenerationFromDataObjectTest extends \Magento\TestFramework\TestCase\WebapiAbstract
  12. {
  13. /** @var string */
  14. protected $_baseUrl = TESTS_BASE_URL;
  15. /** @var string */
  16. protected $_storeCode;
  17. /** @var string */
  18. protected $_soapUrl;
  19. /** @var bool */
  20. protected $isSingleService;
  21. protected function setUp()
  22. {
  23. $this->_markTestAsSoapOnly("WSDL generation tests are intended to be executed for SOAP adapter only.");
  24. $this->_storeCode = Bootstrap::getObjectManager()->get(\Magento\Store\Model\StoreManagerInterface::class)
  25. ->getStore()->getCode();
  26. parent::setUp();
  27. }
  28. public function testMultiServiceWsdl()
  29. {
  30. $this->_soapUrl = "{$this->_baseUrl}/soap/{$this->_storeCode}"
  31. . "?services=testModule5AllSoapAndRestV1%2CtestModule5AllSoapAndRestV2";
  32. $wsdlUrl = $this->_getBaseWsdlUrl() . 'testModule5AllSoapAndRestV1,testModule5AllSoapAndRestV2';
  33. $wsdlContent = $this->_convertXmlToString($this->_getWsdlContent($wsdlUrl));
  34. $this->isSingleService = false;
  35. $this->_checkTypesDeclaration($wsdlContent);
  36. $this->_checkPortTypeDeclaration($wsdlContent);
  37. $this->_checkBindingDeclaration($wsdlContent);
  38. $this->_checkServiceDeclaration($wsdlContent);
  39. $this->_checkMessagesDeclaration($wsdlContent);
  40. $this->_checkFaultsDeclaration($wsdlContent);
  41. }
  42. public function testSingleServiceWsdl()
  43. {
  44. $this->_soapUrl = "{$this->_baseUrl}/soap/{$this->_storeCode}?services=testModule5AllSoapAndRestV2";
  45. $wsdlUrl = $this->_getBaseWsdlUrl() . 'testModule5AllSoapAndRestV2';
  46. $wsdlContent = $this->_convertXmlToString($this->_getWsdlContent($wsdlUrl));
  47. $this->isSingleService = true;
  48. $this->_checkTypesDeclaration($wsdlContent);
  49. $this->_checkPortTypeDeclaration($wsdlContent);
  50. $this->_checkBindingDeclaration($wsdlContent);
  51. $this->_checkServiceDeclaration($wsdlContent);
  52. $this->_checkMessagesDeclaration($wsdlContent);
  53. $this->_checkFaultsDeclaration($wsdlContent);
  54. }
  55. public function testNoAuthorizedServices()
  56. {
  57. $wsdlUrl = $this->_getBaseWsdlUrl() . 'testModule5AllSoapAndRestV2';
  58. $connection = curl_init($wsdlUrl);
  59. curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1);
  60. $responseContent = curl_exec($connection);
  61. $this->assertEquals(curl_getinfo($connection, CURLINFO_HTTP_CODE), 401);
  62. $this->assertContains("The consumer isn't authorized to access %resources.", $responseContent);
  63. }
  64. public function testInvalidWsdlUrlNoServices()
  65. {
  66. $responseContent = $this->_getWsdlContent($this->_getBaseWsdlUrl());
  67. $this->assertContains("Requested services are missing.", $responseContent);
  68. }
  69. public function testInvalidWsdlUrlInvalidParameter()
  70. {
  71. $wsdlUrl = $this->_getBaseWsdlUrl() . '&invalid';
  72. $responseContent = $this->_getWsdlContent($wsdlUrl);
  73. $this->assertContains("Not allowed parameters", $responseContent);
  74. }
  75. /**
  76. * Remove unnecessary spaces and line breaks from xml string.
  77. *
  78. * @param string $xml
  79. * @return string
  80. */
  81. protected function _convertXmlToString($xml)
  82. {
  83. return str_replace([' ', "\n", "\r", "&#13;", "&#10;"], '', $xml);
  84. }
  85. /**
  86. * Retrieve WSDL content.
  87. *
  88. * @param string $wsdlUrl
  89. * @return string|boolean
  90. */
  91. protected function _getWsdlContent($wsdlUrl)
  92. {
  93. $accessCredentials = \Magento\TestFramework\Authentication\OauthHelper::getApiAccessCredentials()['key'];
  94. $connection = curl_init($wsdlUrl);
  95. curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1);
  96. curl_setopt($connection, CURLOPT_HTTPHEADER, ['header' => "Authorization: Bearer " . $accessCredentials]);
  97. $responseContent = curl_exec($connection);
  98. $responseDom = new \DOMDocument();
  99. $this->assertTrue(
  100. $responseDom->loadXML($responseContent),
  101. "Valid XML is always expected as a response for WSDL request."
  102. );
  103. return $responseContent;
  104. }
  105. /**
  106. * Generate base WSDL URL (without any services specified)
  107. *
  108. * @return string
  109. */
  110. protected function _getBaseWsdlUrl()
  111. {
  112. /** @var \Magento\TestFramework\TestCase\Webapi\Adapter\Soap $soapAdapter */
  113. $soapAdapter = $this->_getWebApiAdapter(self::ADAPTER_SOAP);
  114. $wsdlUrl = $soapAdapter->generateWsdlUrl([]);
  115. return $wsdlUrl;
  116. }
  117. /**
  118. * Ensure that types section has correct structure.
  119. *
  120. * @param string $wsdlContent
  121. */
  122. protected function _checkTypesDeclaration($wsdlContent)
  123. {
  124. // @codingStandardsIgnoreStart
  125. $typesSectionDeclaration = <<< TYPES_SECTION_DECLARATION
  126. <types>
  127. <xsd:schema targetNamespace="{$this->_soapUrl}">
  128. TYPES_SECTION_DECLARATION;
  129. // @codingStandardsIgnoreEnd
  130. $this->assertContains(
  131. $this->_convertXmlToString($typesSectionDeclaration),
  132. $wsdlContent,
  133. 'Types section declaration is invalid'
  134. );
  135. $this->_checkElementsDeclaration($wsdlContent);
  136. $this->_checkComplexTypesDeclaration($wsdlContent);
  137. }
  138. /**
  139. * @param string $wsdlContent
  140. */
  141. protected function _checkElementsDeclaration($wsdlContent)
  142. {
  143. if ($this->isSingleService) {
  144. $requestElement = <<< REQUEST_ELEMENT
  145. <xsd:element name="testModule5AllSoapAndRestV2ItemRequest" type="tns:TestModule5AllSoapAndRestV2ItemRequest"/>
  146. REQUEST_ELEMENT;
  147. } else {
  148. $requestElement = <<< REQUEST_ELEMENT
  149. <xsd:element name="testModule5AllSoapAndRestV1ItemRequest" type="tns:TestModule5AllSoapAndRestV1ItemRequest"/>
  150. REQUEST_ELEMENT;
  151. }
  152. $this->assertContains(
  153. $this->_convertXmlToString($requestElement),
  154. $wsdlContent,
  155. 'Request element declaration in types section is invalid'
  156. );
  157. if ($this->isSingleService) {
  158. $responseElement = <<< RESPONSE_ELEMENT
  159. <xsd:element name="testModule5AllSoapAndRestV2ItemResponse" type="tns:TestModule5AllSoapAndRestV2ItemResponse"/>
  160. RESPONSE_ELEMENT;
  161. } else {
  162. $responseElement = <<< RESPONSE_ELEMENT
  163. <xsd:element name="testModule5AllSoapAndRestV1ItemResponse" type="tns:TestModule5AllSoapAndRestV1ItemResponse"/>
  164. RESPONSE_ELEMENT;
  165. }
  166. $this->assertContains(
  167. $this->_convertXmlToString($responseElement),
  168. $wsdlContent,
  169. 'Response element declaration in types section is invalid'
  170. );
  171. }
  172. /**
  173. * @param string $wsdlContent
  174. * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  175. */
  176. protected function _checkComplexTypesDeclaration($wsdlContent)
  177. {
  178. // @codingStandardsIgnoreStart
  179. if ($this->isSingleService) {
  180. $requestType = <<< REQUEST_TYPE
  181. <xsd:complexType name="TestModule5AllSoapAndRestV2ItemRequest">
  182. <xsd:annotation>
  183. <xsd:documentation>Retrieve existing item.</xsd:documentation>
  184. <xsd:appinfo xmlns:inf="{$this->_soapUrl}"/>
  185. </xsd:annotation>
  186. <xsd:sequence>
  187. <xsd:element name="id" minOccurs="1" maxOccurs="1" type="xsd:int">
  188. <xsd:annotation>
  189. <xsd:documentation></xsd:documentation>
  190. <xsd:appinfo xmlns:inf="{$this->_soapUrl}">
  191. <inf:min/>
  192. <inf:max/>
  193. <inf:callInfo>
  194. <inf:callName>testModule5AllSoapAndRestV2Item</inf:callName>
  195. <inf:requiredInput>Yes</inf:requiredInput>
  196. </inf:callInfo>
  197. </xsd:appinfo>
  198. </xsd:annotation>
  199. </xsd:element>
  200. </xsd:sequence>
  201. </xsd:complexType>
  202. REQUEST_TYPE;
  203. } else {
  204. $requestType = <<< REQUEST_TYPE
  205. <xsd:complexType name="TestModule5AllSoapAndRestV1ItemRequest">
  206. <xsd:annotation>
  207. <xsd:documentation>Retrieve an item.</xsd:documentation>
  208. <xsd:appinfo xmlns:inf="{$this->_soapUrl}"/>
  209. </xsd:annotation>
  210. <xsd:sequence>
  211. <xsd:element name="entityId" minOccurs="1" maxOccurs="1" type="xsd:int">
  212. <xsd:annotation>
  213. <xsd:documentation></xsd:documentation>
  214. <xsd:appinfo xmlns:inf="{$this->_soapUrl}">
  215. <inf:min/>
  216. <inf:max/>
  217. <inf:callInfo>
  218. <inf:callName>testModule5AllSoapAndRestV1Item</inf:callName>
  219. <inf:requiredInput>Yes</inf:requiredInput>
  220. </inf:callInfo>
  221. </xsd:appinfo>
  222. </xsd:annotation>
  223. </xsd:element>
  224. </xsd:sequence>
  225. </xsd:complexType>
  226. REQUEST_TYPE;
  227. }
  228. // @codingStandardsIgnoreEnd
  229. $this->assertContains(
  230. $this->_convertXmlToString($requestType),
  231. $wsdlContent,
  232. 'Request type declaration in types section is invalid'
  233. );
  234. // @codingStandardsIgnoreStart
  235. if ($this->isSingleService) {
  236. $responseType = <<< RESPONSE_TYPE
  237. <xsd:complexType name="TestModule5AllSoapAndRestV2ItemResponse">
  238. <xsd:annotation>
  239. <xsd:documentation>
  240. Response container for the testModule5AllSoapAndRestV2Item call.
  241. </xsd:documentation>
  242. <xsd:appinfo xmlns:inf="{$this->_soapUrl}"/>
  243. </xsd:annotation>
  244. <xsd:sequence>
  245. <xsd:element name="result" minOccurs="1" maxOccurs="1" type="tns:TestModule5V2EntityAllSoapAndRest">
  246. <xsd:annotation>
  247. <xsd:documentation></xsd:documentation>
  248. <xsd:appinfo xmlns:inf="{$this->_soapUrl}">
  249. <inf:callInfo>
  250. <inf:callName>testModule5AllSoapAndRestV2Item</inf:callName>
  251. <inf:returned>Always</inf:returned>
  252. </inf:callInfo>
  253. </xsd:appinfo>
  254. </xsd:annotation>
  255. </xsd:element>
  256. </xsd:sequence>
  257. </xsd:complexType>
  258. RESPONSE_TYPE;
  259. } else {
  260. $responseType = <<< RESPONSE_TYPE
  261. <xsd:complexType name="TestModule5AllSoapAndRestV1ItemResponse">
  262. <xsd:annotation>
  263. <xsd:documentation>
  264. Response container for the testModule5AllSoapAndRestV1Item call.
  265. </xsd:documentation>
  266. <xsd:appinfo xmlns:inf="{$this->_soapUrl}"/>
  267. </xsd:annotation>
  268. <xsd:sequence>
  269. <xsd:element name="result" minOccurs="1" maxOccurs="1" type="tns:TestModule5V1EntityAllSoapAndRest">
  270. <xsd:annotation>
  271. <xsd:documentation></xsd:documentation>
  272. <xsd:appinfo xmlns:inf="{$this->_soapUrl}">
  273. <inf:callInfo>
  274. <inf:callName>testModule5AllSoapAndRestV1Item</inf:callName>
  275. <inf:returned>Always</inf:returned>
  276. </inf:callInfo>
  277. </xsd:appinfo>
  278. </xsd:annotation>
  279. </xsd:element>
  280. </xsd:sequence>
  281. </xsd:complexType>
  282. RESPONSE_TYPE;
  283. }
  284. // @codingStandardsIgnoreEnd
  285. $this->assertContains(
  286. $this->_convertXmlToString($responseType),
  287. $wsdlContent,
  288. 'Response type declaration in types section is invalid'
  289. );
  290. $this->_checkReferencedTypeDeclaration($wsdlContent);
  291. }
  292. /**
  293. * Ensure that complex type generated from Data Object is correct.
  294. *
  295. * @param string $wsdlContent
  296. * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  297. */
  298. protected function _checkReferencedTypeDeclaration($wsdlContent)
  299. {
  300. // @codingStandardsIgnoreStart
  301. if ($this->isSingleService) {
  302. $referencedType = <<< RESPONSE_TYPE
  303. <xsd:complexType name="TestModule5V2EntityAllSoapAndRest">
  304. <xsd:annotation>
  305. <xsd:documentation>Some Data Object short description. Data Object long multi line description.</xsd:documentation>
  306. <xsd:appinfo xmlns:inf="{$this->_soapUrl}"/>
  307. </xsd:annotation>
  308. <xsd:sequence>
  309. <xsd:element name="price" minOccurs="1" maxOccurs="1" type="xsd:int">
  310. <xsd:annotation>
  311. <xsd:documentation></xsd:documentation>
  312. <xsd:appinfo xmlns:inf="{$this->_soapUrl}">
  313. <inf:min/>
  314. <inf:max/>
  315. <inf:callInfo>
  316. <inf:callName>testModule5AllSoapAndRestV2Item</inf:callName>
  317. <inf:callName>testModule5AllSoapAndRestV2Create</inf:callName>
  318. <inf:callName>testModule5AllSoapAndRestV2Update</inf:callName>
  319. <inf:callName>testModule5AllSoapAndRestV2Delete</inf:callName>
  320. <inf:returned>Always</inf:returned>
  321. </inf:callInfo>
  322. <inf:callInfo>
  323. <inf:callName>testModule5AllSoapAndRestV2Create</inf:callName>
  324. <inf:callName>testModule5AllSoapAndRestV2Update</inf:callName>
  325. <inf:requiredInput>Yes</inf:requiredInput>
  326. </inf:callInfo>
  327. </xsd:appinfo>
  328. </xsd:annotation>
  329. </xsd:element>
  330. </xsd:sequence>
  331. </xsd:complexType>
  332. RESPONSE_TYPE;
  333. } else {
  334. $referencedType = <<< RESPONSE_TYPE
  335. <xsd:complexType name="TestModule5V1EntityAllSoapAndRest">
  336. <xsd:annotation>
  337. <xsd:documentation>Some Data Object short description. Data Object long multi line description.</xsd:documentation>
  338. <xsd:appinfo xmlns:inf="{$this->_soapUrl}"/>
  339. </xsd:annotation>
  340. <xsd:sequence>
  341. <xsd:element name="entityId" minOccurs="1" maxOccurs="1" type="xsd:int">
  342. <xsd:annotation>
  343. <xsd:documentation>Item ID</xsd:documentation>
  344. <xsd:appinfo xmlns:inf="{$this->_soapUrl}">
  345. <inf:min/>
  346. <inf:max/>
  347. <inf:callInfo>
  348. <inf:callName>testModule5AllSoapAndRestV1Item</inf:callName>
  349. <inf:callName>testModule5AllSoapAndRestV1Create</inf:callName>
  350. <inf:callName>testModule5AllSoapAndRestV1Update</inf:callName>
  351. <inf:callName>testModule5AllSoapAndRestV1NestedUpdate</inf:callName>
  352. <inf:returned>Always</inf:returned>
  353. </inf:callInfo>
  354. <inf:callInfo>
  355. <inf:callName>testModule5AllSoapAndRestV1Create</inf:callName>
  356. <inf:callName>testModule5AllSoapAndRestV1Update</inf:callName>
  357. <inf:callName>testModule5AllSoapAndRestV1NestedUpdate</inf:callName>
  358. <inf:requiredInput>Yes</inf:requiredInput>
  359. </inf:callInfo>
  360. </xsd:appinfo>
  361. </xsd:annotation>
  362. </xsd:element>
  363. <xsd:element name="name" minOccurs="0" maxOccurs="1" type="xsd:string">
  364. <xsd:annotation>
  365. <xsd:documentation>Item name</xsd:documentation>
  366. <xsd:appinfo xmlns:inf="{$this->_soapUrl}">
  367. <inf:maxLength/>
  368. <inf:callInfo>
  369. <inf:callName>testModule5AllSoapAndRestV1Item</inf:callName>
  370. <inf:callName>testModule5AllSoapAndRestV1Create</inf:callName>
  371. <inf:callName>testModule5AllSoapAndRestV1Update</inf:callName>
  372. <inf:callName>testModule5AllSoapAndRestV1NestedUpdate</inf:callName>
  373. <inf:returned>Conditionally</inf:returned>
  374. </inf:callInfo>
  375. <inf:callInfo>
  376. <inf:callName>testModule5AllSoapAndRestV1Create</inf:callName>
  377. <inf:callName>testModule5AllSoapAndRestV1Update</inf:callName>
  378. <inf:callName>testModule5AllSoapAndRestV1NestedUpdate</inf:callName>
  379. <inf:requiredInput>No</inf:requiredInput>
  380. </inf:callInfo>
  381. </xsd:appinfo>
  382. </xsd:annotation>
  383. </xsd:element>
  384. <xsd:element name="enabled" minOccurs="1" maxOccurs="1" type="xsd:boolean">
  385. <xsd:annotation>
  386. <xsd:documentation>If entity is enabled</xsd:documentation>
  387. <xsd:appinfo xmlns:inf="{$this->_soapUrl}">
  388. <inf:default>false</inf:default>
  389. <inf:callInfo>
  390. <inf:callName>testModule5AllSoapAndRestV1Item</inf:callName>
  391. <inf:callName>testModule5AllSoapAndRestV1Create</inf:callName>
  392. <inf:callName>testModule5AllSoapAndRestV1Update</inf:callName>
  393. <inf:callName>testModule5AllSoapAndRestV1NestedUpdate</inf:callName>
  394. <inf:returned>Conditionally</inf:returned>
  395. </inf:callInfo>
  396. <inf:callInfo>
  397. <inf:callName>testModule5AllSoapAndRestV1Create</inf:callName>
  398. <inf:callName>testModule5AllSoapAndRestV1Update</inf:callName>
  399. <inf:callName>testModule5AllSoapAndRestV1NestedUpdate</inf:callName>
  400. <inf:requiredInput>No</inf:requiredInput>
  401. </inf:callInfo>
  402. </xsd:appinfo>
  403. </xsd:annotation>
  404. </xsd:element>
  405. <xsd:element name="orders" minOccurs="1" maxOccurs="1" type="xsd:boolean">
  406. <xsd:annotation>
  407. <xsd:documentation>If current entity has a property defined</xsd:documentation>
  408. <xsd:appinfo xmlns:inf="{$this->_soapUrl}">
  409. <inf:default>false</inf:default>
  410. <inf:callInfo>
  411. <inf:callName>testModule5AllSoapAndRestV1Item</inf:callName>
  412. <inf:callName>testModule5AllSoapAndRestV1Create</inf:callName>
  413. <inf:callName>testModule5AllSoapAndRestV1Update</inf:callName>
  414. <inf:callName>testModule5AllSoapAndRestV1NestedUpdate</inf:callName>
  415. <inf:returned>Conditionally</inf:returned>
  416. </inf:callInfo>
  417. <inf:callInfo>
  418. <inf:callName>testModule5AllSoapAndRestV1Create</inf:callName>
  419. <inf:callName>testModule5AllSoapAndRestV1Update</inf:callName>
  420. <inf:callName>testModule5AllSoapAndRestV1NestedUpdate</inf:callName>
  421. <inf:requiredInput>No</inf:requiredInput>
  422. </inf:callInfo>
  423. </xsd:appinfo>
  424. </xsd:annotation>
  425. </xsd:element>
  426. <xsd:element name="customAttributes" type="tns:ArrayOfFrameworkAttributeInterface" minOccurs="0">
  427. <xsd:annotation>
  428. <xsd:documentation>Custom attributes values.</xsd:documentation>
  429. <xsd:appinfo xmlns:inf="{$this->_soapUrl}">
  430. <inf:natureOfType>array</inf:natureOfType>
  431. <inf:callInfo>
  432. <inf:callName>testModule5AllSoapAndRestV1Item</inf:callName>
  433. <inf:callName>testModule5AllSoapAndRestV1Create</inf:callName>
  434. <inf:callName>testModule5AllSoapAndRestV1Update</inf:callName>
  435. <inf:callName>testModule5AllSoapAndRestV1NestedUpdate</inf:callName>
  436. <inf:returned>Conditionally</inf:returned>
  437. </inf:callInfo>
  438. <inf:callInfo>
  439. <inf:callName>testModule5AllSoapAndRestV1Create</inf:callName>
  440. <inf:callName>testModule5AllSoapAndRestV1Update</inf:callName>
  441. <inf:callName>testModule5AllSoapAndRestV1NestedUpdate</inf:callName>
  442. <inf:requiredInput>No</inf:requiredInput>
  443. </inf:callInfo>
  444. </xsd:appinfo>
  445. </xsd:annotation>
  446. </xsd:element>
  447. </xsd:sequence>
  448. </xsd:complexType>
  449. RESPONSE_TYPE;
  450. }
  451. // @codingStandardsIgnoreEnd
  452. $this->assertContains(
  453. $this->_convertXmlToString($referencedType),
  454. $wsdlContent,
  455. 'Declaration of complex type generated from Data Object, which is referenced in response, is invalid'
  456. );
  457. }
  458. /**
  459. * Ensure that port type sections have correct structure.
  460. *
  461. * @param string $wsdlContent
  462. */
  463. protected function _checkPortTypeDeclaration($wsdlContent)
  464. {
  465. if ($this->isSingleService) {
  466. $firstPortType = <<< FIRST_PORT_TYPE
  467. <portType name="testModule5AllSoapAndRestV2PortType">
  468. FIRST_PORT_TYPE;
  469. } else {
  470. $firstPortType = <<< FIRST_PORT_TYPE
  471. <portType name="testModule5AllSoapAndRestV1PortType">
  472. FIRST_PORT_TYPE;
  473. }
  474. $this->assertContains(
  475. $this->_convertXmlToString($firstPortType),
  476. $wsdlContent,
  477. 'Port type declaration is missing or invalid'
  478. );
  479. if (!$this->isSingleService) {
  480. $secondPortType = <<< SECOND_PORT_TYPE
  481. <portType name="testModule5AllSoapAndRestV2PortType">
  482. SECOND_PORT_TYPE;
  483. $this->assertContains(
  484. $this->_convertXmlToString($secondPortType),
  485. $wsdlContent,
  486. 'Port type declaration is missing or invalid'
  487. );
  488. }
  489. if ($this->isSingleService) {
  490. $operationDeclaration = <<< OPERATION_DECLARATION
  491. <operation name="testModule5AllSoapAndRestV2Item">
  492. <input message="tns:testModule5AllSoapAndRestV2ItemRequest"/>
  493. <output message="tns:testModule5AllSoapAndRestV2ItemResponse"/>
  494. <fault name="GenericFault" message="tns:GenericFault"/>
  495. </operation>
  496. <operation name="testModule5AllSoapAndRestV2Items">
  497. <input message="tns:testModule5AllSoapAndRestV2ItemsRequest"/>
  498. <output message="tns:testModule5AllSoapAndRestV2ItemsResponse"/>
  499. <fault name="GenericFault" message="tns:GenericFault"/>
  500. </operation>
  501. OPERATION_DECLARATION;
  502. } else {
  503. $operationDeclaration = <<< OPERATION_DECLARATION
  504. <operation name="testModule5AllSoapAndRestV2Item">
  505. <input message="tns:testModule5AllSoapAndRestV2ItemRequest"/>
  506. <output message="tns:testModule5AllSoapAndRestV2ItemResponse"/>
  507. <fault name="GenericFault" message="tns:GenericFault"/>
  508. </operation>
  509. <operation name="testModule5AllSoapAndRestV2Items">
  510. <input message="tns:testModule5AllSoapAndRestV2ItemsRequest"/>
  511. <output message="tns:testModule5AllSoapAndRestV2ItemsResponse"/>
  512. <fault name="GenericFault" message="tns:GenericFault"/>
  513. </operation>
  514. OPERATION_DECLARATION;
  515. }
  516. $this->assertContains(
  517. $this->_convertXmlToString($operationDeclaration),
  518. $wsdlContent,
  519. 'Operation in port type is invalid'
  520. );
  521. }
  522. /**
  523. * Ensure that binding sections have correct structure.
  524. *
  525. * @param string $wsdlContent
  526. */
  527. protected function _checkBindingDeclaration($wsdlContent)
  528. {
  529. if ($this->isSingleService) {
  530. $firstBinding = <<< FIRST_BINDING
  531. <binding name="testModule5AllSoapAndRestV2Binding" type="tns:testModule5AllSoapAndRestV2PortType">
  532. <soap12:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
  533. FIRST_BINDING;
  534. } else {
  535. $firstBinding = <<< FIRST_BINDING
  536. <binding name="testModule5AllSoapAndRestV1Binding" type="tns:testModule5AllSoapAndRestV1PortType">
  537. <soap12:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
  538. FIRST_BINDING;
  539. }
  540. $this->assertContains(
  541. $this->_convertXmlToString($firstBinding),
  542. $wsdlContent,
  543. 'Binding declaration is missing or invalid'
  544. );
  545. if (!$this->isSingleService) {
  546. $secondBinding = <<< SECOND_BINDING
  547. <binding name="testModule5AllSoapAndRestV2Binding" type="tns:testModule5AllSoapAndRestV2PortType">
  548. <soap12:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
  549. SECOND_BINDING;
  550. $this->assertContains(
  551. $this->_convertXmlToString($secondBinding),
  552. $wsdlContent,
  553. 'Binding declaration is missing or invalid'
  554. );
  555. }
  556. if ($this->isSingleService) {
  557. $operationDeclaration = <<< OPERATION_DECLARATION
  558. <operation name="testModule5AllSoapAndRestV2Item">
  559. <soap12:operation soapAction="testModule5AllSoapAndRestV2Item"/>
  560. <input>
  561. <soap12:body use="literal"/>
  562. </input>
  563. <output>
  564. <soap12:body use="literal"/>
  565. </output>
  566. <fault name="GenericFault"/>
  567. </operation>
  568. <operation name="testModule5AllSoapAndRestV2Items">
  569. <soap12:operation soapAction="testModule5AllSoapAndRestV2Items"/>
  570. <input>
  571. <soap12:body use="literal"/>
  572. </input>
  573. <output>
  574. <soap12:body use="literal"/>
  575. </output>
  576. <fault name="GenericFault"/>
  577. </operation>
  578. OPERATION_DECLARATION;
  579. } else {
  580. $operationDeclaration = <<< OPERATION_DECLARATION
  581. <operation name="testModule5AllSoapAndRestV1Item">
  582. <soap12:operation soapAction="testModule5AllSoapAndRestV1Item"/>
  583. <input>
  584. <soap12:body use="literal"/>
  585. </input>
  586. <output>
  587. <soap12:body use="literal"/>
  588. </output>
  589. <fault name="GenericFault"/>
  590. </operation>
  591. <operation name="testModule5AllSoapAndRestV1Items">
  592. <soap12:operation soapAction="testModule5AllSoapAndRestV1Items"/>
  593. <input>
  594. <soap12:body use="literal"/>
  595. </input>
  596. <output>
  597. <soap12:body use="literal"/>
  598. </output>
  599. <fault name="GenericFault"/>
  600. </operation>
  601. OPERATION_DECLARATION;
  602. }
  603. $this->assertContains(
  604. $this->_convertXmlToString($operationDeclaration),
  605. $wsdlContent,
  606. 'Operation in binding is invalid'
  607. );
  608. }
  609. /**
  610. * Ensure that service sections have correct structure.
  611. *
  612. * @param string $wsdlContent
  613. */
  614. protected function _checkServiceDeclaration($wsdlContent)
  615. {
  616. // @codingStandardsIgnoreStart
  617. if ($this->isSingleService) {
  618. $firstServiceDeclaration = <<< FIRST_SERVICE_DECLARATION
  619. <service name="testModule5AllSoapAndRestV2Service">
  620. <port name="testModule5AllSoapAndRestV2Port" binding="tns:testModule5AllSoapAndRestV2Binding">
  621. <soap12:address location="{$this->_baseUrl}/soap/{$this->_storeCode}?services=testModule5AllSoapAndRestV2"/>
  622. </port>
  623. </service>
  624. FIRST_SERVICE_DECLARATION;
  625. } else {
  626. $firstServiceDeclaration = <<< FIRST_SERVICE_DECLARATION
  627. <service name="testModule5AllSoapAndRestV1Service">
  628. <port name="testModule5AllSoapAndRestV1Port" binding="tns:testModule5AllSoapAndRestV1Binding">
  629. <soap12:address location="{$this->_baseUrl}/soap/{$this->_storeCode}?services=testModule5AllSoapAndRestV1%2CtestModule5AllSoapAndRestV2"/>
  630. </port>
  631. </service>
  632. FIRST_SERVICE_DECLARATION;
  633. }
  634. // @codingStandardsIgnoreEnd
  635. $this->assertContains(
  636. $this->_convertXmlToString($firstServiceDeclaration),
  637. $wsdlContent,
  638. 'First service section is invalid'
  639. );
  640. // @codingStandardsIgnoreStart
  641. if (!$this->isSingleService) {
  642. $secondServiceDeclaration = <<< SECOND_SERVICE_DECLARATION
  643. <service name="testModule5AllSoapAndRestV2Service">
  644. <port name="testModule5AllSoapAndRestV2Port" binding="tns:testModule5AllSoapAndRestV2Binding">
  645. <soap12:address location="{$this->_baseUrl}/soap/{$this->_storeCode}?services=testModule5AllSoapAndRestV1%2CtestModule5AllSoapAndRestV2"/>
  646. </port>
  647. </service>
  648. SECOND_SERVICE_DECLARATION;
  649. // @codingStandardsIgnoreEnd
  650. $this->assertContains(
  651. $this->_convertXmlToString($secondServiceDeclaration),
  652. $wsdlContent,
  653. 'Second service section is invalid'
  654. );
  655. }
  656. }
  657. /**
  658. * Ensure that messages sections have correct structure.
  659. *
  660. * @param string $wsdlContent
  661. */
  662. protected function _checkMessagesDeclaration($wsdlContent)
  663. {
  664. $itemMessagesDeclaration = <<< MESSAGES_DECLARATION
  665. <message name="testModule5AllSoapAndRestV2ItemRequest">
  666. <part name="messageParameters" element="tns:testModule5AllSoapAndRestV2ItemRequest"/>
  667. </message>
  668. <message name="testModule5AllSoapAndRestV2ItemResponse">
  669. <part name="messageParameters" element="tns:testModule5AllSoapAndRestV2ItemResponse"/>
  670. </message>
  671. MESSAGES_DECLARATION;
  672. $this->assertContains(
  673. $this->_convertXmlToString($itemMessagesDeclaration),
  674. $wsdlContent,
  675. 'Messages section for "item" operation is invalid'
  676. );
  677. $itemsMessagesDeclaration = <<< MESSAGES_DECLARATION
  678. <message name="testModule5AllSoapAndRestV2ItemsRequest">
  679. <part name="messageParameters" element="tns:testModule5AllSoapAndRestV2ItemsRequest"/>
  680. </message>
  681. <message name="testModule5AllSoapAndRestV2ItemsResponse">
  682. <part name="messageParameters" element="tns:testModule5AllSoapAndRestV2ItemsResponse"/>
  683. </message>
  684. MESSAGES_DECLARATION;
  685. $this->assertContains(
  686. $this->_convertXmlToString($itemsMessagesDeclaration),
  687. $wsdlContent,
  688. 'Messages section for "items" operation is invalid'
  689. );
  690. }
  691. /**
  692. * Ensure that SOAP faults are declared properly.
  693. *
  694. * @param string $wsdlContent
  695. */
  696. protected function _checkFaultsDeclaration($wsdlContent)
  697. {
  698. $this->_checkFaultsPortTypeSection($wsdlContent);
  699. $this->_checkFaultsBindingSection($wsdlContent);
  700. $this->_checkFaultsMessagesSection($wsdlContent);
  701. $this->_checkFaultsComplexTypeSection($wsdlContent);
  702. }
  703. /**
  704. * @param string $wsdlContent
  705. */
  706. protected function _checkFaultsPortTypeSection($wsdlContent)
  707. {
  708. $faultsInPortType = <<< FAULT_IN_PORT_TYPE
  709. <fault name="GenericFault" message="tns:GenericFault"/>
  710. FAULT_IN_PORT_TYPE;
  711. $this->assertContains(
  712. $this->_convertXmlToString($faultsInPortType),
  713. $wsdlContent,
  714. 'SOAP Fault section in port type section is invalid'
  715. );
  716. }
  717. /**
  718. * @param string $wsdlContent
  719. */
  720. protected function _checkFaultsBindingSection($wsdlContent)
  721. {
  722. $faultsInBinding = <<< FAULT_IN_BINDING
  723. <fault name="GenericFault"/>
  724. FAULT_IN_BINDING;
  725. $this->assertContains(
  726. $this->_convertXmlToString($faultsInBinding),
  727. $wsdlContent,
  728. 'SOAP Fault section in binding section is invalid'
  729. );
  730. }
  731. /**
  732. * @param string $wsdlContent
  733. */
  734. protected function _checkFaultsMessagesSection($wsdlContent)
  735. {
  736. $genericFaultMessage = <<< GENERIC_FAULT_IN_MESSAGES
  737. <message name="GenericFault">
  738. <part name="messageParameters" element="tns:GenericFault"/>
  739. </message>
  740. GENERIC_FAULT_IN_MESSAGES;
  741. $this->assertContains(
  742. $this->_convertXmlToString($genericFaultMessage),
  743. $wsdlContent,
  744. 'Generic SOAP Fault declaration in messages section is invalid'
  745. );
  746. }
  747. /**
  748. * @param string $wsdlContent
  749. * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  750. */
  751. protected function _checkFaultsComplexTypeSection($wsdlContent)
  752. {
  753. $this->assertContains(
  754. $this->_convertXmlToString('<xsd:element name="GenericFault" type="tns:GenericFault"/>'),
  755. $wsdlContent,
  756. 'Default SOAP Fault complex type element declaration is invalid'
  757. );
  758. // @codingStandardsIgnoreStart
  759. $genericFaultType = <<< GENERIC_FAULT_COMPLEX_TYPE
  760. <xsd:complexType name="GenericFault">
  761. <xsd:sequence>
  762. <xsd:element name="Trace" minOccurs="0" maxOccurs="1" type="xsd:string">
  763. <xsd:annotation>
  764. <xsd:documentation>Exception calls stack trace.</xsd:documentation>
  765. <xsd:appinfo xmlns:inf="{$this->_soapUrl}">
  766. <inf:maxLength/>
  767. </xsd:appinfo>
  768. </xsd:annotation>
  769. </xsd:element>
  770. <xsd:element name="Parameters" type="tns:ArrayOfGenericFaultParameter" minOccurs="0">
  771. <xsd:annotation>
  772. <xsd:documentation>Additional exception parameters.</xsd:documentation>
  773. <xsd:appinfo xmlns:inf="{$this->_soapUrl}">
  774. <inf:natureOfType>array</inf:natureOfType>
  775. </xsd:appinfo>
  776. </xsd:annotation>
  777. </xsd:element>
  778. <xsd:element name="WrappedErrors" type="tns:ArrayOfWrappedError" minOccurs="0">
  779. <xsd:annotation>
  780. <xsd:documentation>Additional wrapped errors.</xsd:documentation>
  781. <xsd:appinfo xmlns:inf="{$this->_soapUrl}">
  782. <inf:natureOfType>array</inf:natureOfType>
  783. </xsd:appinfo>
  784. </xsd:annotation>
  785. </xsd:element>
  786. </xsd:sequence>
  787. </xsd:complexType>
  788. GENERIC_FAULT_COMPLEX_TYPE;
  789. $this->assertContains(
  790. $this->_convertXmlToString($genericFaultType),
  791. $wsdlContent,
  792. 'Default SOAP Fault complex types declaration is invalid'
  793. );
  794. $detailsParameterType = <<< PARAM_COMPLEX_TYPE
  795. <xsd:complexType name="GenericFaultParameter">
  796. <xsd:sequence>
  797. <xsd:element name="key" minOccurs="1" maxOccurs="1" type="xsd:string">
  798. <xsd:annotation>
  799. <xsd:documentation></xsd:documentation>
  800. <xsd:appinfo xmlns:inf="{$this->_soapUrl}">
  801. <inf:maxLength/>
  802. </xsd:appinfo>
  803. </xsd:annotation>
  804. </xsd:element>
  805. <xsd:element name="value" minOccurs="1" maxOccurs="1" type="xsd:string">
  806. <xsd:annotation>
  807. <xsd:documentation></xsd:documentation>
  808. <xsd:appinfo xmlns:inf="{$this->_soapUrl}">
  809. <inf:maxLength/>
  810. </xsd:appinfo>
  811. </xsd:annotation>
  812. </xsd:element>
  813. </xsd:sequence>
  814. </xsd:complexType>
  815. PARAM_COMPLEX_TYPE;
  816. $this->assertContains(
  817. $this->_convertXmlToString($detailsParameterType),
  818. $wsdlContent,
  819. 'Details parameter complex types declaration is invalid.'
  820. );
  821. // @codingStandardsIgnoreStart
  822. if ($this->isSingleService) {
  823. $detailsWrappedErrorType = <<< WRAPPED_ERROR_COMPLEX_TYPE
  824. <xsd:complexType name="WrappedError">
  825. <xsd:sequence>
  826. <xsd:element name="message" minOccurs="1" maxOccurs="1" type="xsd:string">
  827. <xsd:annotation>
  828. <xsd:documentation></xsd:documentation>
  829. <xsd:appinfo xmlns:inf="{$this->_baseUrl}/soap/{$this->_storeCode}?services=testModule5AllSoapAndRestV2">
  830. <inf:maxLength/>
  831. </xsd:appinfo>
  832. </xsd:annotation>
  833. </xsd:element>
  834. <xsd:element name="parameters" type="tns:ArrayOfGenericFaultParameter" minOccurs="0">
  835. <xsd:annotation>
  836. <xsd:documentation>Message parameters.</xsd:documentation>
  837. <xsd:appinfo xmlns:inf="{$this->_baseUrl}/soap/{$this->_storeCode}?services=testModule5AllSoapAndRestV2">
  838. <inf:natureOfType>array</inf:natureOfType>
  839. </xsd:appinfo>
  840. </xsd:annotation>
  841. </xsd:element>
  842. </xsd:sequence>
  843. </xsd:complexType>
  844. WRAPPED_ERROR_COMPLEX_TYPE;
  845. } else {
  846. $detailsWrappedErrorType = <<< WRAPPED_ERROR_COMPLEX_TYPE
  847. <xsd:complexType name="WrappedError">
  848. <xsd:sequence>
  849. <xsd:element name="message" minOccurs="1" maxOccurs="1" type="xsd:string">
  850. <xsd:annotation>
  851. <xsd:documentation></xsd:documentation>
  852. <xsd:appinfo xmlns:inf="{$this->_baseUrl}/soap/{$this->_storeCode}?services=testModule5AllSoapAndRestV1%2CtestModule5AllSoapAndRestV2">
  853. <inf:maxLength/>
  854. </xsd:appinfo>
  855. </xsd:annotation>
  856. </xsd:element>
  857. <xsd:element name="parameters" type="tns:ArrayOfGenericFaultParameter" minOccurs="0">
  858. <xsd:annotation>
  859. <xsd:documentation>Message parameters.</xsd:documentation>
  860. <xsd:appinfo xmlns:inf="{$this->_baseUrl}/soap/{$this->_storeCode}?services=testModule5AllSoapAndRestV1%2CtestModule5AllSoapAndRestV2">
  861. <inf:natureOfType>array</inf:natureOfType>
  862. </xsd:appinfo>
  863. </xsd:annotation>
  864. </xsd:element>
  865. </xsd:sequence>
  866. </xsd:complexType>
  867. WRAPPED_ERROR_COMPLEX_TYPE;
  868. }
  869. // @codingStandardsIgnoreEnd
  870. $this->assertContains(
  871. $this->_convertXmlToString($detailsWrappedErrorType),
  872. $wsdlContent,
  873. 'Details wrapped error complex types declaration is invalid.'
  874. );
  875. $detailsParametersType = <<< PARAMETERS_COMPLEX_TYPE
  876. <xsd:complexType name="ArrayOfGenericFaultParameter">
  877. <xsd:annotation>
  878. <xsd:documentation>An array of GenericFaultParameter items.</xsd:documentation>
  879. <xsd:appinfo xmlns:inf="{$this->_soapUrl}"/>
  880. </xsd:annotation>
  881. <xsd:sequence>
  882. <xsd:element name="item" minOccurs="0" maxOccurs="unbounded" type="tns:GenericFaultParameter">
  883. <xsd:annotation>
  884. <xsd:documentation>An item of ArrayOfGenericFaultParameter.</xsd:documentation>
  885. <xsd:appinfo xmlns:inf="{$this->_soapUrl}"/>
  886. </xsd:annotation>
  887. </xsd:element>
  888. </xsd:sequence>
  889. </xsd:complexType>
  890. PARAMETERS_COMPLEX_TYPE;
  891. // @codingStandardsIgnoreEnd
  892. $this->assertContains(
  893. $this->_convertXmlToString($detailsParametersType),
  894. $wsdlContent,
  895. 'Details parameters (array of parameters) complex types declaration is invalid.'
  896. );
  897. if ($this->isSingleService) {
  898. // @codingStandardsIgnoreStart
  899. $detailsWrappedErrorsType = <<< WRAPPED_ERRORS_COMPLEX_TYPE
  900. <xsd:complexType name="ArrayOfWrappedError">
  901. <xsd:annotation>
  902. <xsd:documentation>An array of WrappedError items.</xsd:documentation>
  903. <xsd:appinfo xmlns:inf="{$this->_baseUrl}/soap/{$this->_storeCode}?services=testModule5AllSoapAndRestV2"/>
  904. </xsd:annotation>
  905. <xsd:sequence>
  906. <xsd:element name="item" minOccurs="0" maxOccurs="unbounded" type="tns:WrappedError">
  907. <xsd:annotation>
  908. <xsd:documentation>An item of ArrayOfWrappedError.</xsd:documentation>
  909. <xsd:appinfo xmlns:inf="{$this->_baseUrl}/soap/{$this->_storeCode}?services=testModule5AllSoapAndRestV2"/>
  910. </xsd:annotation>
  911. </xsd:element>
  912. </xsd:sequence>
  913. </xsd:complexType>
  914. WRAPPED_ERRORS_COMPLEX_TYPE;
  915. } else {
  916. $detailsWrappedErrorsType = <<< WRAPPED_ERRORS_COMPLEX_TYPE
  917. <xsd:complexType name="ArrayOfWrappedError">
  918. <xsd:annotation>
  919. <xsd:documentation>An array of WrappedError items.</xsd:documentation>
  920. <xsd:appinfo xmlns:inf="{$this->_baseUrl}/soap/{$this->_storeCode}?services=testModule5AllSoapAndRestV1%2CtestModule5AllSoapAndRestV2"/>
  921. </xsd:annotation>
  922. <xsd:sequence>
  923. <xsd:element name="item" minOccurs="0" maxOccurs="unbounded" type="tns:WrappedError">
  924. <xsd:annotation>
  925. <xsd:documentation>An item of ArrayOfWrappedError.</xsd:documentation>
  926. <xsd:appinfo xmlns:inf="{$this->_baseUrl}/soap/{$this->_storeCode}?services=testModule5AllSoapAndRestV1%2CtestModule5AllSoapAndRestV2"/>
  927. </xsd:annotation>
  928. </xsd:element>
  929. </xsd:sequence>
  930. </xsd:complexType>
  931. WRAPPED_ERRORS_COMPLEX_TYPE;
  932. }
  933. // @codingStandardsIgnoreEnd
  934. $this->assertContains(
  935. $this->_convertXmlToString($detailsWrappedErrorsType),
  936. $wsdlContent,
  937. 'Details wrapped errors (array of wrapped errors) complex types declaration is invalid.'
  938. );
  939. }
  940. }