init
This commit is contained in:
+18
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\WebapiAsync\Controller\Rest;
|
||||
|
||||
class AsynchronousSchemaRequestProcessorMock extends AsynchronousSchemaRequestProcessor
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function canProcess(\Magento\Framework\Webapi\Rest\Request $request)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\WebapiAsync\Controller\Rest;
|
||||
|
||||
use Magento\TestFramework\TestCase\AbstractController;
|
||||
|
||||
class AsynchronousSchemaRequestProcessorTest extends AbstractController
|
||||
{
|
||||
/**
|
||||
* Test that the rest controller returns the correct async schema response.
|
||||
*
|
||||
* @param string $path
|
||||
* @magentoAppArea webapi_rest
|
||||
* @dataProvider schemaRequestProvider
|
||||
*/
|
||||
public function testSchemaRequest($path)
|
||||
{
|
||||
ob_start();
|
||||
$this->dispatch($path);
|
||||
ob_end_clean();
|
||||
$schema = $this->getResponse()->getBody();
|
||||
|
||||
// Check that an HTTP 202 response is visible for what is normally an HTTP 200.
|
||||
$this->assertMatchesRegularExpression('/202 Accepted/', $schema);
|
||||
|
||||
// Make sure that the async interface definition is included in the response.
|
||||
$this->assertMatchesRegularExpression('/asynchronous-operations-data-async-response-interface/', $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/async/schema'],
|
||||
['rest/async/schema?services=all'],
|
||||
['rest/all/async/schema?services=all'],
|
||||
['rest/default/async/schema?services=all'],
|
||||
['rest/async/schema?services=all'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\WebapiAsync\Model;
|
||||
|
||||
use Magento\Framework\Webapi\Authorization;
|
||||
|
||||
class AuthorizationMock extends Authorization
|
||||
{
|
||||
/**
|
||||
* @param string[] $aclResources
|
||||
* @return bool
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function isAllowed($aclResources)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\WebapiAsync\Model\Rest\Swagger;
|
||||
|
||||
use Magento\Framework\Webapi\Authorization;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\Webapi\Model\Rest\Swagger\Generator;
|
||||
use Magento\Webapi\Model\ServiceMetadata;
|
||||
use Magento\WebapiAsync\Controller\Rest\AsynchronousSchemaRequestProcessor;
|
||||
use Magento\WebapiAsync\Controller\Rest\AsynchronousSchemaRequestProcessorMock;
|
||||
use Magento\WebapiAsync\Model\AuthorizationMock;
|
||||
|
||||
class GeneratorTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var Generator
|
||||
*/
|
||||
private $generator;
|
||||
|
||||
/**
|
||||
* @var ServiceMetadata
|
||||
*/
|
||||
private $serviceMetadata;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$objectManager->configure([
|
||||
'preferences' => [
|
||||
Authorization::class => AuthorizationMock::class,
|
||||
AsynchronousSchemaRequestProcessor::class => AsynchronousSchemaRequestProcessorMock::class
|
||||
]
|
||||
]);
|
||||
|
||||
$this->generator = $objectManager->create(Generator::class);
|
||||
$this->serviceMetadata = $objectManager->create(ServiceMetadata::class);
|
||||
}
|
||||
|
||||
public function testGenerateAsync()
|
||||
{
|
||||
$schema = json_decode(
|
||||
$this->generator->generate(
|
||||
['customerAccountManagementV1'],
|
||||
'https',
|
||||
'localhost',
|
||||
'/async/schema/V1?services=customerAccountManagementV1'
|
||||
),
|
||||
true
|
||||
);
|
||||
|
||||
// Ensure that the correct HTTP response has been described in the schema.
|
||||
$this->assertArrayHasKey(
|
||||
'202',
|
||||
$schema['paths']['/V1/customers']['post']['responses']
|
||||
);
|
||||
|
||||
$this->assertArrayNotHasKey(
|
||||
'200',
|
||||
$schema['paths']['/V1/customers']['post']['responses']
|
||||
);
|
||||
|
||||
// 202 Response should not apply to GET requests.
|
||||
$this->assertArrayNotHasKey(
|
||||
'/V1/customers/me/shippingAddress',
|
||||
$schema['paths']
|
||||
);
|
||||
|
||||
// Ensure that the response type has been replaced with the async version.
|
||||
$this->assertEquals(
|
||||
'#/definitions/asynchronous-operations-data-async-response-interface',
|
||||
$schema['paths']['/V1/customers']['post']['responses']['202']['schema']['$ref']
|
||||
);
|
||||
|
||||
// Ensure that the base path output correctly
|
||||
$this->assertEquals('/async', $schema['basePath']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\WebapiAsync\Plugin;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\Customer\Api\AccountManagementInterface;
|
||||
use Magento\Webapi\Model\ServiceMetadata;
|
||||
use Magento\WebapiAsync\Controller\Rest\AsynchronousSchemaRequestProcessor;
|
||||
use Magento\WebapiAsync\Controller\Rest\AsynchronousSchemaRequestProcessorMock;
|
||||
|
||||
class ServiceMetadataTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var ServiceMetadata
|
||||
*/
|
||||
private $serviceMetadata;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$objectManager->configure([
|
||||
'preferences' => [
|
||||
AsynchronousSchemaRequestProcessor::class => AsynchronousSchemaRequestProcessorMock::class
|
||||
]
|
||||
]);
|
||||
|
||||
$this->serviceMetadata = $objectManager->create(ServiceMetadata::class);
|
||||
}
|
||||
|
||||
public function testGetServiceMetadata()
|
||||
{
|
||||
$expected = [
|
||||
'methods' => [
|
||||
'activate' => [
|
||||
'method' => 'activate',
|
||||
'inputRequired' => false,
|
||||
'isSecure' => false,
|
||||
'resources' => [
|
||||
'Magento_Customer::manage'
|
||||
],
|
||||
'documentation' => 'Activate a customer account using a key that was sent in a confirmation email.',
|
||||
'interface' => [
|
||||
'in' => [
|
||||
'parameters' => [
|
||||
'email' => [
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
'documentation' => null
|
||||
],
|
||||
'confirmationKey' => [
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
'documentation' => null
|
||||
]
|
||||
]
|
||||
],
|
||||
'out' => [
|
||||
'parameters' => [
|
||||
'result' => [
|
||||
'type' => 'AsynchronousOperationsDataAsyncResponseInterface',
|
||||
'required' => true,
|
||||
'documentation' => 'Returns response information for the asynchronous request.',
|
||||
'response_codes' => [
|
||||
'success' => [
|
||||
'code' => '202',
|
||||
'description' => '202 Accepted.'
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
'class' => AccountManagementInterface::class,
|
||||
'description' => 'Interface for managing customers accounts.',
|
||||
];
|
||||
$actual = $this->serviceMetadata->getServiceMetadata('customerAccountManagementV1');
|
||||
$this->assertEquals(array_replace_recursive($actual, $expected), $actual);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user