This commit is contained in:
2026-09-15 10:26:34 +08:00
commit ecf36afa56
10493 changed files with 1404888 additions and 0 deletions
@@ -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());
}
}
@@ -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);
}
}
@@ -0,0 +1,44 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*
*/
namespace Magento\Webapi\Model\Config;
use Magento\Webapi\Model\Config\Reader as ConfigReader;
/**
* Webapi config reader test.
*/
class ReaderTest extends \PHPUnit\Framework\TestCase
{
/** @var \PHPUnit\Framework\MockObject\MockObject */
protected $_fileResolverMock;
/** @var ConfigReader */
protected $_configReader;
protected function setUp(): void
{
parent::setUp();
$this->_fileResolverMock = $this->createMock(\Magento\Framework\Config\FileResolverInterface::class);
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$this->_configReader = $objectManager->create(
\Magento\Webapi\Model\Config\Reader::class,
['fileResolver' => $this->_fileResolverMock]
);
}
public function testRead()
{
$configFiles = [
file_get_contents(realpath(__DIR__ . '/_files/webapiA.xml')),
file_get_contents(realpath(__DIR__ . '/_files/webapiB.xml')),
];
$this->_fileResolverMock->expects($this->any())->method('get')->willReturn($configFiles);
$expectedResult = require __DIR__ . '/_files/webapi.php';
$this->assertEquals($expectedResult, $this->_configReader->read(), 'Error happened during config reading.');
}
}
@@ -0,0 +1,294 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
return [
'services' => [\Magento\TestModuleMSC\Api\AllSoapAndRestInterface::class => [
'V1' => [
'methods' => [
'item' => [
'resources' => [
'Magento_TestModuleMSC::resource1',
],
'secure' => false,
'realMethod' => 'item',
'parameters' => [],
'input-array-size-limit' => null,
],
'create' => [
'resources' => [
'Magento_TestModuleMSC::resource3',
],
'secure' => false,
'realMethod' => 'create',
'parameters' => [],
'input-array-size-limit' => null,
],
],
],
'V2' => [
'methods' => [
'getPreconfiguredItem' => [
'resources' => [
'Magento_TestModuleMSC::resource1',
'Magento_TestModuleMSC::resource2',
],
'secure' => false,
'realMethod' => 'getPreconfiguredItem',
'parameters' => [],
'input-array-size-limit' => null,
],
],
],
], \Magento\TestModule1\Service\V1\AllSoapAndRestInterface::class => [
'V1' => [
'methods' => [
'item' => [
'resources' => [
'Magento_Test1::resource1',
],
'secure' => false,
'realMethod' => 'item',
'parameters' => [],
'input-array-size-limit' => null,
],
'itemDefault' => [
'resources' => [
'Magento_Test1::default',
],
'secure' => false,
'realMethod' => 'item',
'parameters' => [
'id' => [
'force' => true,
'value' => null,
],
],
'input-array-size-limit' => null,
],
'create' => [
'resources' => [
'Magento_Test1::resource1',
],
'secure' => false,
'realMethod' => 'create',
'parameters' => [
'id' => [
'force' => true,
'value' => null,
],
],
'input-array-size-limit' => null,
],
],
],
], \Magento\TestModule1\Service\V2\AllSoapAndRestInterface::class => [
'V2' => [
'methods' => [
'item' => [
'resources' => [
'Magento_Test1::resource1',
'Magento_Test1::resource2',
],
'secure' => false,
'realMethod' => 'item',
'parameters' => [],
'input-array-size-limit' => null,
],
'create' => [
'resources' => [
'Magento_Test1::resource1',
'Magento_Test1::resource2',
],
'secure' => false,
'realMethod' => 'create',
'parameters' => [
'id' => [
'force' => true,
'value' => null,
],
],
'input-array-size-limit' => 50,
],
'delete' => [
'resources' => [
'Magento_Test1::resource1',
'Magento_Test1::resource2',
],
'secure' => false,
'realMethod' => 'delete',
'parameters' => [],
'input-array-size-limit' => null,
],
'update' => [
'resources' => [
'Magento_Test1::resource1',
'Magento_Test1::resource2',
],
'secure' => false,
'realMethod' => 'update',
'parameters' => [],
'input-array-size-limit' => null,
],
],
],
],
],
'routes' => [
'/V1/testmoduleMSC/:itemId' => [
'GET' => [
'secure' => false,
'service' => [
'class' => \Magento\TestModuleMSC\Api\AllSoapAndRestInterface::class,
'method' => 'item',
],
'resources' => [
'Magento_TestModuleMSC::resource1' => true,
],
'parameters' => [],
'input-array-size-limit' => null,
],
],
'/V1/testmoduleMSC' => [
'POST' => [
'secure' => false,
'service' => [
'class' => \Magento\TestModuleMSC\Api\AllSoapAndRestInterface::class,
'method' => 'create',
],
'resources' => [
'Magento_TestModuleMSC::resource3' => true,
],
'parameters' => [],
'input-array-size-limit' => null,
],
],
'/V1/testmodule1/:id' => [
'GET' => [
'secure' => false,
'service' => [
'class' => \Magento\TestModule1\Service\V1\AllSoapAndRestInterface::class,
'method' => 'item',
],
'resources' => [
'Magento_Test1::resource1' => true,
],
'parameters' => [],
'input-array-size-limit' => null,
],
],
'/V1/testmodule1' => [
'GET' => [
'secure' => false,
'service' => [
'class' => \Magento\TestModule1\Service\V1\AllSoapAndRestInterface::class,
'method' => 'item',
],
'resources' => [
'Magento_Test1::default' => true,
],
'parameters' => [
'id' => [
'force' => true,
'value' => null,
],
],
'input-array-size-limit' => null,
],
'POST' => [
'secure' => false,
'service' => [
'class' => \Magento\TestModule1\Service\V1\AllSoapAndRestInterface::class,
'method' => 'create',
],
'resources' => [
'Magento_Test1::resource1' => true,
],
'parameters' => [
'id' => [
'force' => true,
'value' => null,
],
],
'input-array-size-limit' => null,
],
],
'/V2/testmodule1/:id' => [
'GET' => [
'secure' => false,
'service' => [
'class' => \Magento\TestModule1\Service\V2\AllSoapAndRestInterface::class,
'method' => 'item',
],
'resources' => [
'Magento_Test1::resource1' => true,
'Magento_Test1::resource2' => true,
],
'parameters' => [],
'input-array-size-limit' => null,
],
'DELETE' => [
'secure' => false,
'service' => [
'class' => \Magento\TestModule1\Service\V2\AllSoapAndRestInterface::class,
'method' => 'delete',
],
'resources' => [
'Magento_Test1::resource1' => true,
'Magento_Test1::resource2' => true,
],
'parameters' => [],
'input-array-size-limit' => null,
],
'PUT' => [
'secure' => false,
'service' => [
'class' => \Magento\TestModule1\Service\V2\AllSoapAndRestInterface::class,
'method' => 'update',
],
'resources' => [
'Magento_Test1::resource1' => true,
'Magento_Test1::resource2' => true,
],
'parameters' => [],
'input-array-size-limit' => null,
],
],
'/V2/testmodule1' => [
'POST' => [
'secure' => false,
'service' => [
'class' => \Magento\TestModule1\Service\V2\AllSoapAndRestInterface::class,
'method' => 'create',
],
'resources' => [
'Magento_Test1::resource1' => true,
'Magento_Test1::resource2' => true,
],
'parameters' => [
'id' => [
'force' => true,
'value' => null,
],
],
'input-array-size-limit' => 50,
],
],
'/V2/testmoduleMSC/itemPreconfigured' => [
'GET' => [
'secure' => false,
'service' => [
'class' => \Magento\TestModuleMSC\Api\AllSoapAndRestInterface::class,
'method' => 'getPreconfiguredItem',
],
'resources' => [
'Magento_TestModuleMSC::resource1' => true,
'Magento_TestModuleMSC::resource2' => true,
],
'parameters' => [],
'input-array-size-limit' => null,
]
]
],
];
@@ -0,0 +1,68 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd">
<route url="/V1/testmodule1/:id" method="GET">
<service class="Magento\TestModule1\Service\V1\AllSoapAndRestInterface" method="item"/>
<resources>
<resource ref="Magento_Test1::resource1"/>
</resources>
</route>
<route url="/V1/testmodule1" method="GET" soapOperation="itemDefault">
<service class="Magento\TestModule1\Service\V1\AllSoapAndRestInterface" method="item"/>
<resources>
<resource ref="Magento_Test1::default"/>
</resources>
<data>
<parameter name="id" force="true">null</parameter>
</data>
</route>
<route url="/V2/testmodule1/:id" method="GET">
<service class="Magento\TestModule1\Service\V2\AllSoapAndRestInterface" method="item"/>
<resources>
<resource ref="Magento_Test1::resource1"/>
<resource ref="Magento_Test1::resource2"/>
</resources>
</route>
<route url="/V2/testmodule1" method="POST">
<service class="Magento\TestModule1\Service\V2\AllSoapAndRestInterface" method="create"/>
<resources>
<resource ref="Magento_Test1::resource1"/>
<resource ref="Magento_Test1::resource2"/>
</resources>
<data input-array-size-limit="50">
<parameter name="id" force="true">null</parameter>
</data>
</route>
<route url="/V2/testmodule1/:id" method="DELETE">
<service class="Magento\TestModule1\Service\V2\AllSoapAndRestInterface" method="delete"/>
<resources>
<resource ref="Magento_Test1::resource1"/>
<resource ref="Magento_Test1::resource2"/>
</resources>
</route>
<route method="GET" url="/V1/testmoduleMSC/:itemId">
<service class="Magento\TestModuleMSC\Api\AllSoapAndRestInterface" method="item" />
<resources>
<resource ref="Magento_TestModuleMSC::resource1" />
</resources>
</route>
<route method="POST" url="/V1/testmoduleMSC">
<service class="Magento\TestModuleMSC\Api\AllSoapAndRestInterface" method="create" />
<resources>
<resource ref="Magento_TestModuleMSC::resource3" />
</resources>
</route>
<route method="GET" url="/V2/testmoduleMSC/itemPreconfigured">
<service class="Magento\TestModuleMSC\Api\AllSoapAndRestInterface" method="getPreconfiguredItem" />
<resources>
<resource ref="Magento_TestModuleMSC::resource1" />
<resource ref="Magento_TestModuleMSC::resource2" />
</resources>
</route>
</routes>
@@ -0,0 +1,33 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd">
<route url="/V1/testmodule1" method="POST">
<service class="Magento\TestModule1\Service\V1\AllSoapAndRestInterface" method="create"/>
<resources>
<resource ref="Magento_Test1::resource1"/>
</resources>
<data>
<parameter name="id" force="true">null</parameter>
</data>
</route>
<route url="/V2/testmodule1/:id" method="PUT">
<service class="Magento\TestModule1\Service\V2\AllSoapAndRestInterface" method="update"/>
<resources>
<resource ref="Magento_Test1::resource1"/>
<resource ref="Magento_Test1::resource2"/>
</resources>
</route>
<route url="/V2/testmodule1/:id" method="DELETE">
<service class="Magento\TestModule1\Service\V2\AllSoapAndRestInterface" method="delete"/>
<resources>
<resource ref="Magento_Test1::resource1"/>
<resource ref="Magento_Test1::resource2"/>
</resources>
</route>
</routes>
@@ -0,0 +1,135 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Webapi\Model;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\Customer\Api\AccountManagementInterface;
use Magento\Framework\Exception\LocalizedException;
class ServiceMetadataTest extends \PHPUnit\Framework\TestCase
{
/**
* @var ServiceMetadata
*/
private $serviceMetadata;
protected function setUp(): void
{
$objectManager = Bootstrap::getObjectManager();
$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' => 'CustomerDataCustomerInterface',
'required' => true,
'documentation' => ''
]
],
'throws' => [
'\\' . LocalizedException::class
]
]
]
]
],
'class' => AccountManagementInterface::class,
'description' => 'Interface for managing customers accounts.',
];
$actual = $this->serviceMetadata->getServiceMetadata('customerAccountManagementV1');
$this->assertEquals(array_replace_recursive($actual, $expected), $actual);
}
public function testGetRouteMetadata()
{
$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' => 'CustomerDataCustomerInterface',
'required' => true,
'documentation' => ''
]
],
'throws' => [
'\\' . LocalizedException::class
]
]
]
]
],
'class' => AccountManagementInterface::class,
'description' => 'Interface for managing customers accounts.',
'routes' => [
'/V1/customers/me/activate' => [
'PUT' => [
'method' => 'activateById',
'parameters' => [
'customerId' => [
'force' => true,
'value' => '%customer_id%'
]
]
]
]
]
];
$actual = $this->serviceMetadata->getRouteMetadata('customerAccountManagementV1');
$this->assertEquals(array_replace_recursive($actual, $expected), $actual);
}
}
@@ -0,0 +1,117 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Webapi\Model\Soap;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\Customer\Api\AccountManagementInterface;
use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\Framework\Exception\LocalizedException;
class ConfigTest extends \PHPUnit\Framework\TestCase
{
/**
* @var Config
*/
private $soapConfig;
protected function setUp(): void
{
$objectManager = Bootstrap::getObjectManager();
$this->soapConfig = $objectManager->create(Config::class);
}
public function testGetRequestedSoapServices()
{
$expected = [
'customerAccountManagementV1' => [
'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' => 'CustomerDataCustomerInterface',
'required' => true,
'documentation' => null
]
],
'throws' => [
'\\' . LocalizedException::class
]
]
],
'parameters' => []
]
],
'class' => AccountManagementInterface::class,
'description' => 'Interface for managing customers accounts.',
]
];
$actual = $this->soapConfig->getRequestedSoapServices(
[
'customerAccountManagementV1',
'NonExistentService'
]
);
$this->assertEquals(array_replace_recursive($actual, $expected), $actual);
}
public function testGetServiceMethodInfo()
{
$expected = [
'class' => CustomerRepositoryInterface::class,
'method' => 'getById',
'isSecure' => false,
'resources' => [
'Magento_Customer::customer',
],
'parameters' => [],
'input-array-size-limit' => null,
];
$actual = $this->soapConfig->getServiceMethodInfo(
'customerCustomerRepositoryV1GetById',
[
'customerCustomerRepositoryV1',
'NonExistentService'
]
);
$this->assertEquals($expected, $actual);
}
public function testGetSoapOperation()
{
$expected = 'customerAccountManagementV1Activate';
$actual = $this->soapConfig
->getSoapOperation(
AccountManagementInterface::class,
'activate',
'V1'
);
$this->assertEquals($expected, $actual);
}
}
@@ -0,0 +1,82 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Webapi\Service\Entity;
class TestService
{
/**
* @param int $entityId
* @param string $name
* @return string[]
*/
public function simple($entityId, $name)
{
return [$entityId, $name];
}
/**
* @param \Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\Nested $nested
* @return \Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\Nested
*/
public function nestedData(Nested $nested)
{
return $nested;
}
/**
* @param int[] $ids
* @return int[]
*/
public function simpleArray(array $ids)
{
return $ids;
}
/**
* @param string[] $associativeArray
* @return string[]
*/
public function associativeArray(array $associativeArray)
{
return $associativeArray;
}
/**
* @param \Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\Simple[] $dataObjects
* @return \Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\Simple[]
*/
public function dataArray(array $dataObjects)
{
return $dataObjects;
}
/**
* @param \Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\SimpleArray $arrayData
* @return \Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\SimpleArray
*/
public function nestedSimpleArray(SimpleArray $arrayData)
{
return $arrayData;
}
/**
* @param \Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\AssociativeArray $associativeArrayData
* @return \Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\AssociativeArray
*/
public function nestedAssociativeArray(AssociativeArray $associativeArrayData)
{
return $associativeArrayData;
}
/**
* @param \Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\DataArray $dataObjects
* @return \Magento\Framework\Webapi\Test\Unit\ServiceInputProcessor\DataArray
*/
public function nestedDataArray(DataArray $dataObjects)
{
return $dataObjects;
}
}
@@ -0,0 +1,41 @@
<?php
/**
* Test services for name collisions.
*
* Let we have two service interfaces called Foo\Bar\Service\SomeBazV1Interface and Foo\Bar\Service\Some\BazV1Interface.
* Given current name generation logic both are going to be translated to BarSomeBazV1. This test checks such things
* are not going to happen.
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Webapi;
use Magento\Webapi\Model\Config\Converter;
class ServiceNameCollisionTest extends \PHPUnit\Framework\TestCase
{
/**
* Test there are no collisions between service names.
*
* @see \Magento\Webapi\Model\Soap\Config::getServiceName()
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
*/
public function testServiceNameCollisions()
{
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
/** @var \Magento\Webapi\Model\ServiceMetadata $serviceMetadata */
$serviceMetadata = $objectManager->get(\Magento\Webapi\Model\ServiceMetadata::class);
/** @var \Magento\Webapi\Model\Config $webapiConfig */
$webapiConfig = $objectManager->get(\Magento\Webapi\Model\Config::class);
$serviceNames = [];
foreach ($webapiConfig->getServices()[Converter::KEY_SERVICES] as $serviceClassName => $serviceVersionData) {
foreach ($serviceVersionData as $version => $serviceData) {
$newServiceName = $serviceMetadata->getServiceName($serviceClassName, $version);
$this->assertFalse(in_array($newServiceName, $serviceNames));
$serviceNames[] = $newServiceName;
}
}
}
}
@@ -0,0 +1,34 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/**
* Create an admin user with an assigned role
*/
/** @var $model \Magento\User\Model\User */
$model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\User\Model\User::class);
/** @var Magento\Framework\App\ResourceConnection $connection */
$connection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
->create(Magento\Framework\App\ResourceConnection::class);
$adapter = $connection->getConnection();
$select = $adapter->select()
->from($connection->getTableName('authorization_role'), ['role_id'])
->where('role_name = ?', 'Administrators')
->where('parent_id = ?', 0)
->limit(1);
$roleId = $adapter->fetchOne($select);
$model->setFirstname("Web")
->setLastname("Api")
->setUsername('webapi_user')
->setPassword(\Magento\TestFramework\Bootstrap::ADMIN_PASSWORD)
->setEmail('webapi_user@example.com')
->setRoleType('G')
->setResourceId('Magento_Backend::all')
->setPrivileges("")
->setAssertId(0)
->setRoleId((int) $roleId)
->setPermission('allow');
$model->save();
@@ -0,0 +1,18 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
use Magento\Integration\Model\Oauth\Token\RequestThrottler;
/** @var $model \Magento\User\Model\User */
$model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\User\Model\User::class);
$userName = 'webapi_user';
$model->load($userName, 'username');
$model->delete();
/* Unlock account if it was locked */
/** @var RequestThrottler $throttler */
$throttler = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(RequestThrottler::class);
$throttler->resetAuthenticationFailuresCount($userName, RequestThrottler::USER_TYPE_ADMIN);