1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
/**
* Test SOAP server model.
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Webapi\Test\Unit\Model\Soap;
class ServerTest extends \PHPUnit\Framework\TestCase
{
/** @var \Magento\Webapi\Model\Soap\Server */
protected $_soapServer;
/** @var \Magento\Store\Model\Store */
protected $_storeMock;
/** @var \Magento\Framework\Webapi\Request */
protected $_requestMock;
/** @var \Magento\Store\Model\StoreManagerInterface */
protected $_storeManagerMock;
/** @var \Magento\Webapi\Model\Soap\ServerFactory */
protected $_soapServerFactory;
/** @var \Magento\Framework\Reflection\TypeProcessor|\PHPUnit_Framework_MockObject_MockObject */
protected $_typeProcessor;
/** @var \Magento\Webapi\Model\Soap\Wsdl\Generator|\PHPUnit_Framework_MockObject_MockObject */
protected $wsdlGenerator;
/** @var \PHPUnit_Framework_MockObject_MockObject */
protected $_scopeConfig;
protected function setUp()
{
$this->_storeManagerMock = $this->getMockBuilder(
\Magento\Store\Model\StoreManager::class
)->disableOriginalConstructor()->getMock();
$this->_storeMock = $this->getMockBuilder(
\Magento\Store\Model\Store::class
)->disableOriginalConstructor()->getMock();
$this->_storeMock->expects(
$this->any()
)->method(
'getBaseUrl'
)->will(
$this->returnValue('http://magento.com/')
);
$this->_storeMock->expects($this->any())->method('getCode')->will($this->returnValue('storeCode'));
$this->_storeManagerMock->expects(
$this->any()
)->method(
'getStore'
)->will(
$this->returnValue($this->_storeMock)
);
$areaListMock = $this->createMock(\Magento\Framework\App\AreaList::class);
$configScopeMock = $this->createMock(\Magento\Framework\Config\ScopeInterface::class);
$areaListMock->expects($this->any())->method('getFrontName')->will($this->returnValue('soap'));
$this->_requestMock = $this->getMockBuilder(
\Magento\Framework\Webapi\Request::class
)->disableOriginalConstructor()->getMock();
$this->_soapServerFactory = $this->getMockBuilder(
\Magento\Webapi\Model\Soap\ServerFactory::class
)->disableOriginalConstructor()->getMock();
$this->_typeProcessor = $this->createMock(\Magento\Framework\Reflection\TypeProcessor::class);
$this->wsdlGenerator = $this->createMock(\Magento\Webapi\Model\Soap\Wsdl\Generator::class);
$this->_scopeConfig = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
/** Init SUT. */
$this->_soapServer = new \Magento\Webapi\Model\Soap\Server(
$areaListMock,
$configScopeMock,
$this->_requestMock,
$this->_storeManagerMock,
$this->_soapServerFactory,
$this->_typeProcessor,
$this->_scopeConfig,
$this->wsdlGenerator
);
parent::setUp();
}
protected function tearDown()
{
unset($this->_soapServer);
unset($this->_requestMock);
unset($this->_domDocumentFactory);
unset($this->_storeMock);
unset($this->_storeManagerMock);
unset($this->_soapServerFactory);
parent::tearDown();
}
/**
* Test getApiCharset method.
*/
public function testGetApiCharset()
{
$this->_scopeConfig->expects($this->once())->method('getValue')->will($this->returnValue('Windows-1251'));
$this->assertEquals(
'Windows-1251',
$this->_soapServer->getApiCharset(),
'API charset encoding getting is invalid.'
);
}
/**
* Test getApiCharset method with default encoding.
*/
public function testGetApiCharsetDefaultEncoding()
{
$this->_scopeConfig->expects($this->once())->method('getValue')->will($this->returnValue(null));
$this->assertEquals(
\Magento\Webapi\Model\Soap\Server::SOAP_DEFAULT_ENCODING,
$this->_soapServer->getApiCharset(),
'Default API charset encoding getting is invalid.'
);
}
/**
* Test getEndpointUri method.
*/
public function testGetEndpointUri()
{
$expectedResult = 'http://magento.com/soap/storeCode';
$actualResult = $this->_soapServer->getEndpointUri();
$this->assertEquals($expectedResult, $actualResult, 'Endpoint URI building is invalid.');
}
/**
* Test generate uri with wsdl param as true
*/
public function testGenerateUriWithWsdlParam()
{
$param = "testModule1AllSoapAndRest:V1,testModule2AllSoapNoRest:V1";
$serviceKey = \Magento\Webapi\Model\Soap\Server::REQUEST_PARAM_SERVICES;
$this->_requestMock->expects($this->any())->method('getParam')->will($this->returnValue($param));
$expectedResult = "http://magento.com/soap/storeCode?{$serviceKey}={$param}&wsdl=1";
$actualResult = $this->_soapServer->generateUri(true);
$this->assertEquals($expectedResult, urldecode($actualResult), 'URI (with WSDL param) generated is invalid.');
}
/**
* Test generate uri with wsdl param as true
*/
public function testGenerateUriWithNoWsdlParam()
{
$param = "testModule1AllSoapAndRest:V1,testModule2AllSoapNoRest:V1";
$serviceKey = \Magento\Webapi\Model\Soap\Server::REQUEST_PARAM_SERVICES;
$this->_requestMock->expects($this->any())->method('getParam')->will($this->returnValue($param));
$expectedResult = "http://magento.com/soap/storeCode?{$serviceKey}={$param}";
$actualResult = $this->_soapServer->generateUri(false);
$this->assertEquals(
$expectedResult,
urldecode($actualResult),
'URI (without WSDL param) generated is invalid.'
);
}
}