init
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Webapi\Controller;
|
||||
|
||||
use Magento\Store\Model\Store;
|
||||
|
||||
/**
|
||||
* Test for Magento\Webapi\Controller\PathProcessor class.
|
||||
*/
|
||||
class PathProcessorTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Store\Model\StoreManagerInterface
|
||||
*/
|
||||
protected $storeManager;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Locale\ResolverInterface::class
|
||||
*/
|
||||
private $localeResolver;
|
||||
|
||||
/**
|
||||
* @var \Magento\Webapi\Controller\PathProcessor
|
||||
*/
|
||||
protected $pathProcessor;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$this->storeManager = $objectManager->get(\Magento\Store\Model\StoreManagerInterface::class);
|
||||
$this->storeManager->reinitStores();
|
||||
$this->localeResolver = $objectManager->get(\Magento\Framework\Locale\ResolverInterface::class);
|
||||
$this->pathProcessor = $objectManager->get(\Magento\Webapi\Controller\PathProcessor::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Store/_files/core_fixturestore.php
|
||||
*/
|
||||
public function testProcessWithValidStoreCode()
|
||||
{
|
||||
$storeCode = 'fixturestore';
|
||||
$basePath = "rest/{$storeCode}";
|
||||
$path = $basePath . '/V1/customerAccounts/createCustomer';
|
||||
$resultPath = $this->pathProcessor->process($path);
|
||||
$this->assertEquals(str_replace($basePath, "", $path), $resultPath);
|
||||
$this->assertEquals($storeCode, $this->storeManager->getStore()->getCode());
|
||||
}
|
||||
|
||||
public function testProcessWithAllStoreCode()
|
||||
{
|
||||
$storeCode = 'all';
|
||||
$path = '/V1/customerAccounts/createCustomer';
|
||||
$uri = 'rest/' . $storeCode . $path;
|
||||
$result = $this->pathProcessor->process($uri);
|
||||
$this->assertEquals($path, $result);
|
||||
$this->assertEquals(Store::ADMIN_CODE, $this->storeManager->getStore()->getCode());
|
||||
}
|
||||
|
||||
public function testProcessWithoutStoreCode()
|
||||
{
|
||||
$path = '/V1/customerAccounts/createCustomer';
|
||||
$uri = 'rest' . $path;
|
||||
$result = $this->pathProcessor->process($uri);
|
||||
$this->assertEquals($path, $result);
|
||||
$this->assertEquals('default', $this->storeManager->getStore()->getCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Store/_files/core_fixturestore.php
|
||||
* @magentoConfigFixture default_store general/locale/code en_US
|
||||
* @magentoConfigFixture fixturestore_store general/locale/code de_DE
|
||||
*/
|
||||
public function testProcessWithValidStoreCodeApplyLocale()
|
||||
{
|
||||
$locale = 'de_DE';
|
||||
$storeCode = 'fixturestore';
|
||||
$basePath = "rest/{$storeCode}";
|
||||
$path = $basePath . '/V1/customerAccounts/createCustomer';
|
||||
$this->pathProcessor->process($path);
|
||||
$this->assertEquals($locale, $this->localeResolver->getLocale());
|
||||
$this->assertNotEquals('en_US', $this->localeResolver->getLocale());
|
||||
}
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Webapi\Controller\Rest;
|
||||
|
||||
use Magento\TestFramework\TestCase\AbstractController;
|
||||
|
||||
class SchemaRequestProcessorTest extends AbstractController
|
||||
{
|
||||
/**
|
||||
* Test that the rest controller returns the correct schema response.
|
||||
*
|
||||
* @param string $path
|
||||
* @dataProvider schemaRequestProvider
|
||||
*/
|
||||
public function testSchemaRequest($path)
|
||||
{
|
||||
ob_start();
|
||||
$this->dispatch($path);
|
||||
ob_end_clean();
|
||||
$schema = $this->getResponse()->getBody();
|
||||
|
||||
// Check that an HTTP 200 response status is visible in the schema.
|
||||
$this->assertMatchesRegularExpression('/200 Success/', $schema);
|
||||
}
|
||||
|
||||
/**
|
||||
* Response getter
|
||||
*
|
||||
* @return \Magento\Framework\App\ResponseInterface
|
||||
*/
|
||||
public function getResponse()
|
||||
{
|
||||
if (!$this->_response) {
|
||||
$this->_response = $this->_objectManager->get(\Magento\Framework\Webapi\Rest\Response::class);
|
||||
}
|
||||
return $this->_response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function schemaRequestProvider()
|
||||
{
|
||||
return [
|
||||
['rest/schema'],
|
||||
['rest/schema?services=all'],
|
||||
['rest/all/schema?services=all'],
|
||||
['rest/default/schema?services=all'],
|
||||
['rest/schema?services=all'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Webapi\Controller;
|
||||
|
||||
use Magento\Framework\Webapi\Exception as WebapiException;
|
||||
use Magento\Framework\Webapi\Rest\Request;
|
||||
use Magento\Framework\Webapi\Rest\Response;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class RestTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var Request
|
||||
*/
|
||||
private $request;
|
||||
|
||||
/**
|
||||
* @var Response
|
||||
*/
|
||||
private $response;
|
||||
|
||||
/**
|
||||
* @var Rest
|
||||
*/
|
||||
private $controller;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->request = Bootstrap::getObjectManager()->create(Request::class);
|
||||
$this->response = Bootstrap::getObjectManager()->create(Response::class);
|
||||
$this->controller = Bootstrap::getObjectManager()->create(
|
||||
Rest::class,
|
||||
[
|
||||
'request' => $this->request,
|
||||
'response' => $this->response,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function testDispatchUnsupportedMethod(): void
|
||||
{
|
||||
$this->request->setMethod('OPTIONS');
|
||||
$this->controller->dispatch($this->request);
|
||||
self::assertTrue($this->response->isException());
|
||||
/** @var WebapiException $exception */
|
||||
$exception = $this->response->getException()[0];
|
||||
self::assertInstanceOf(WebapiException::class, $exception);
|
||||
self::assertEquals(405, $exception->getHttpCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Webapi\Controller;
|
||||
|
||||
/**
|
||||
* Test for Magento\Webapi\Controller\Soap class.
|
||||
*/
|
||||
class SoapTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Webapi\Controller\Soap
|
||||
*/
|
||||
protected $soapController;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
protected $objectManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$this->soapController = $this->objectManager->get(\Magento\Webapi\Controller\Soap::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the public wsdl with anonymous credentials
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDispatchWsdlRequest(): void
|
||||
{
|
||||
$request = $this->objectManager->get(\Magento\Framework\Webapi\Request::class);
|
||||
$request->setParam(\Magento\Webapi\Model\Soap\Server::REQUEST_PARAM_LIST_WSDL, true);
|
||||
$response = $this->soapController->dispatch($request);
|
||||
$decodedWsdl = json_decode($response->getContent(), true);
|
||||
|
||||
$this->assertWsdlServices($decodedWsdl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check wsdl available methods.
|
||||
*
|
||||
* @param array $decodedWsdl
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function assertWsdlServices(array $decodedWsdl): void
|
||||
{
|
||||
$this->assertArrayHasKey('customerAccountManagementV1', $decodedWsdl);
|
||||
$this->assertArrayHasKey('integrationAdminTokenServiceV1', $decodedWsdl);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user