ServerTest.php 5.9 KB

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