Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ComplexTypeStrategyTest.php
Go to the documentation of this file.
1 <?php
7 
8 use \Magento\Webapi\Model\Soap\Wsdl\ComplexTypeStrategy;
9 
10 use Zend\Soap\Wsdl;
11 
15 class ComplexTypeStrategyTest extends \PHPUnit\Framework\TestCase
16 {
18  protected $_typeProcessor;
19 
21  protected $_wsdl;
22 
24  protected $_strategy;
25 
29  protected function setUp()
30  {
31  $this->_typeProcessor = $this->getMockBuilder(
32  \Magento\Framework\Reflection\TypeProcessor::class
33  )->setMethods(
34  ['getTypeData']
35  )->disableOriginalConstructor()->getMock();
36  $this->_wsdl = $this->getMockBuilder(
37  \Magento\Webapi\Model\Soap\Wsdl::class
38  )->setMethods(
39  ['toDomDocument', 'getTypes', 'getSchema']
40  )->disableOriginalConstructor()->getMock();
41  $this->_strategy = new ComplexTypeStrategy($this->_typeProcessor);
42  $this->_strategy->setContext($this->_wsdl);
43  parent::setUp();
44  }
45 
49  protected function tearDown()
50  {
51  unset($this->_typeProcessor);
52  unset($this->_strategy);
53  unset($this->_wsdl);
54 
55  parent::tearDown();
56  }
57 
62  public function testCheckTypeName()
63  {
64  $testType = 'testComplexTypeName';
65  $testTypeWsdlName = 'tns:' . $testType;
66  $includedTypes = [$testType => $testTypeWsdlName];
67  $this->_wsdl->expects($this->exactly(2))->method('getTypes')->will($this->returnValue($includedTypes));
68 
69  $this->assertEquals($testTypeWsdlName, $this->_strategy->addComplexType($testType));
70  }
71 
80  {
81  $this->_wsdl->expects($this->any())->method('getTypes')->will($this->returnValue([]));
82 
83  $this->_wsdl->expects($this->any())->method('toDomDocument')->will($this->returnValue(new \DOMDocument()));
84 
85  $schemaMock = $this->getMockBuilder(\DOMElement::class)
86  ->setConstructorArgs(['a'])
87  ->getMock();
88  $schemaMock->expects($this->any())->method('appendChild');
89  $this->_wsdl->expects($this->any())->method('getSchema')->will($this->returnValue($schemaMock));
90 
91  $this->_typeProcessor->expects(
92  $this->at(0)
93  )->method(
94  'getTypeData'
95  )->with(
96  $type
97  )->will(
98  $this->returnValue($data)
99  );
100 
101  $this->assertEquals(Wsdl::TYPES_NS . ':' . $type, $this->_strategy->addComplexType($type));
102  }
103 
109  public static function addComplexTypeDataProvider()
110  {
111  return [
112  'simple parameters' => [
113  'VendorModuleADataStructure',
114  [
115  'documentation' => 'test',
116  'parameters' => [
117  'string_param' => [
118  'type' => 'string',
119  'required' => true,
120  'documentation' => 'Required string param.',
121  ],
122  'int_param' => [
123  'type' => 'int',
124  'required' => true,
125  'documentation' => 'Required int param.',
126  ],
127  'bool_param' => [
128  'type' => 'boolean',
129  'required' => false,
130  'documentation' => 'Optional complex type param.{annotation:test}',
131  ],
132  ]
133  ],
134  ],
135  'type with call info' => [
136  'VendorModuleADataStructure',
137  [
138  'documentation' => 'test',
139  'parameters' => [
140  'string_param' => [
141  'type' => 'string',
142  'required' => false,
143  'documentation' => '{callInfo:VendorModuleACreate:requiredInput:conditionally}',
144  ],
145  ],
146  'callInfo' => [
147  'requiredInput' => ['yes' => ['calls' => ['VendorModuleACreate']]],
148  'returned' => ['always' => ['calls' => ['VendorModuleAGet']]],
149  ]
150  ],
151  ],
152  'parameter with call info' => [
153  'VendorModuleADataStructure',
154  [
155  'documentation' => 'test',
156  'parameters' => [
157  'string_param' => [
158  'type' => 'string',
159  'required' => false,
160  'documentation' => '{callInfo:VendorModuleACreate:requiredInput:conditionally}' .
161  '{callInfo:allCallsExcept(VendorModuleAGet):returned:always}',
162  ],
163  ]
164  ],
165  ],
166  'parameter with see link' => [
167  'VendorModuleADataStructure',
168  [
169  'documentation' => 'test',
170  'parameters' => [
171  'string_param' => [
172  'type' => 'string',
173  'required' => false,
174  'documentation' => '{seeLink:http://google.com/:title:for}',
175  ],
176  ]
177  ],
178  ],
179  'parameter with doc instructions' => [
180  'VendorModuleADataStructure',
181  [
182  'documentation' => 'test',
183  'parameters' => [
184  'string_param' => [
185  'type' => 'string',
186  'required' => false,
187  'documentation' => '{docInstructions:output:noDoc}',
188  ],
189  ]
190  ],
191  ]
192  ];
193  }
194 
199  {
200  $type = 'VendorModuleADataStructure';
201  $parameterType = 'ComplexType';
202  $typeData = [
203  'documentation' => 'test',
204  'parameters' => [
205  'complex_param' => [
206  'type' => $parameterType,
207  'required' => true,
208  'documentation' => 'complex type param.',
209  ],
210  ],
211  ];
212  $parameterData = [
213  'documentation' => 'test',
214  'parameters' => [
215  'string_param' => [
216  'type' => 'ComplexTypeB[]',
217  'required' => true,
218  'documentation' => 'string param.',
219  ],
220  ],
221  ];
222 
223  $this->_wsdl->expects($this->at(0))->method('getTypes')->will($this->returnValue([]));
224  $this->_wsdl->expects(
225  $this->any()
226  )->method(
227  'getTypes'
228  )->will(
229  $this->returnValue([$type => Wsdl::TYPES_NS . ':' . $type])
230  );
231 
232  $this->_wsdl->expects($this->any())->method('toDomDocument')->will($this->returnValue(new \DOMDocument()));
233  $schemaMock = $this->getMockBuilder(\DOMElement::class)
234  ->setConstructorArgs(['a'])
235  ->getMock();
236  $schemaMock->expects($this->any())->method('appendChild');
237  $this->_wsdl->expects($this->any())->method('getSchema')->will($this->returnValue($schemaMock));
238  $this->_typeProcessor->expects(
239  $this->at(0)
240  )->method(
241  'getTypeData'
242  )->with(
243  $type
244  )->will(
245  $this->returnValue($typeData)
246  );
247  $this->_typeProcessor->expects(
248  $this->at(1)
249  )->method(
250  'getTypeData'
251  )->with(
252  $parameterType
253  )->will(
254  $this->returnValue($parameterData)
255  );
256 
257  $this->assertEquals(Wsdl::TYPES_NS . ':' . $type, $this->_strategy->addComplexType($type));
258  }
259 
264  {
265  $dom = new \DOMDocument();
266  $this->_wsdl->expects($this->any())->method('toDomDocument')->will($this->returnValue($dom));
267  $annotationDoc = "test doc";
268  $complexType = $dom->createElement(Wsdl::XSD_NS . ':complexType');
269  $complexType->setAttribute('name', 'testRequest');
270  $this->_strategy->addAnnotation($complexType, $annotationDoc);
271  $this->assertEquals(
272  $annotationDoc,
273  $complexType->getElementsByTagName("xsd:documentation")->item(0)->nodeValue
274  );
275  }
276 }
$type
Definition: item.phtml:13