Skip to content

Commit

Permalink
Merge pull request #269 from magento-api/develop
Browse files Browse the repository at this point in the history
[API] Sprint 47 – Part 2
  • Loading branch information
vpelipenko committed May 6, 2015
2 parents cd7d717 + 4da4cd4 commit 635ce44
Show file tree
Hide file tree
Showing 58 changed files with 1,558 additions and 444 deletions.
40 changes: 25 additions & 15 deletions app/code/Magento/Backend/Block/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ protected function _addSubMenu($menuItem, $level, $limit, $id = null)
* @param array $colBrakes
* @return string HTML
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function renderNavigation($menu, $level = 0, $limit = 0, $colBrakes = [])
{
Expand All @@ -454,21 +455,30 @@ public function renderNavigation($menu, $level = 0, $limit = 0, $colBrakes = [])
}

$id = $this->getJsId($menuItem->getId());
$output .= '<li ' . $this->getUiId(
$menuItem->getId()
) . ' class="item-' . $itemClass . ' ' . $this->_renderItemCssClass(
$menuItem,
$level
) . ($level == 0 ? '" id="' . $id . '" aria-haspopup="true' : '')
. '" role="menu-item">' . $this->_renderAnchor(
$menuItem,
$level
) . $this->_addSubMenu(
$menuItem,
$level,
$limit,
$id
) . '</li>';
if (count($menu) > 1 || $level != 1) {
$output .= '<li ' . $this->getUiId(
$menuItem->getId()
) . ' class="item-' . $itemClass . ' ' . $this->_renderItemCssClass(
$menuItem,
$level
) . ($level == 0 ? '" id="' . $id . '" aria-haspopup="true' : '')
. '" role="menu-item">' . $this->_renderAnchor(
$menuItem,
$level
) . $this->_addSubMenu(
$menuItem,
$level,
$limit,
$id
) . '</li>';
} else {
$output .= $this->_addSubMenu(
$menuItem,
$level,
$limit,
$id);
}

$itemPosition++;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Api/etc/data_object.xsd">
<custom_attributes for="Magento\Catalog\Api\Data\ProductInterface">
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Api/etc/service_data_attributes.xsd">
<extension_attributes for="Magento\Catalog\Api\Data\ProductInterface">
<attribute code="bundle_product_options" type="Magento\Bundle\Api\Data\OptionInterface[]" />
</custom_attributes>
</extension_attributes>
</config>
20 changes: 20 additions & 0 deletions app/code/Magento/CatalogInventory/etc/service_data_attributes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Api/etc/service_data_attributes.xsd">
<extension_attributes for="Magento\Catalog\Api\Data\ProductInterface">
<!--
Once this is merged with the branch with the CatalogInventory integration, need to make sure the permission
below is actually used.
<attribute code="stock_item" type="Magento\CatalogInventory\Api\Data\StockItemInterface">
<resources>
<resource ref="Magento_CatalogInventory::cataloginventory"/>
</resources>
</attribute>
-->
</extension_attributes>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Api/etc/data_object.xsd">
<custom_attributes for="Magento\Sales\Api\Data\OrderInterface">
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Api/etc/service_data_attributes.xsd">
<extension_attributes for="Magento\Sales\Api\Data\OrderInterface">
<attribute code="gift_message" type="Magento\GiftMessage\Api\Data\MessageInterface" />
</custom_attributes>
<custom_attributes for="Magento\Sales\Api\Data\OrderItemInterface">
</extension_attributes>
<extension_attributes for="Magento\Sales\Api\Data\OrderItemInterface">
<attribute code="gift_message" type="Magento\GiftMessage\Api\Data\MessageInterface" />
</custom_attributes>
</extension_attributes>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Api/etc/data_object.xsd">
<custom_attributes for="Magento\Catalog\Api\Data\ProductLinkInterface">
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Api/etc/service_data_attributes.xsd">
<extension_attributes for="Magento\Catalog\Api\Data\ProductLinkInterface">
<attribute code="qty" type="float" />
</custom_attributes>
</extension_attributes>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Api/etc/data_object.xsd">
<custom_attributes for="Magento\Sales\Api\Data\OrderInterface">
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Api/etc/service_data_attributes.xsd">
<extension_attributes for="Magento\Sales\Api\Data\OrderInterface">
<attribute code="applied_taxes" type="Magento\Tax\Api\Data\OrderTaxDetailsAppliedTaxInterface[]" />
<attribute code="item_applied_taxes" type="Magento\Tax\Api\Data\OrderTaxDetailsItemInterface[]" />
<attribute code="converting_from_quote" type="boolean" />
</custom_attributes>
</extension_attributes>
</config>
11 changes: 2 additions & 9 deletions app/code/Magento/Webapi/Controller/Rest/Router/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected function getRouteParts()
$this->variables[$key] = substr($value, 1);
$value = null;
}
$result[$key] = strtolower($value);
$result[$key] = $value;
}
return $result;
}
Expand All @@ -92,19 +92,12 @@ protected function isVariable($value)
/**
* Retrieve unified requested path
*
* Lowercase all path chunks, except variables names.
* E.g. the path '/V1/Categories/:categoryId' will be converted to '/v1/categories/:categoryId'.
*
* @param string $path
* @return array
*/
protected function getPathParts($path)
{
$result = explode('/', trim($path, '/'));
array_walk($result, function (&$item) {
$item = substr($item, 0, 1) === ":" ? $item : strtolower($item);
});
return $result;
return explode('/', trim($path, '/'));
}

/**
Expand Down
11 changes: 9 additions & 2 deletions app/code/Magento/Webapi/Controller/Soap/Request/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Magento\Webapi\Controller\Soap\Request as SoapRequest;
use Magento\Framework\Webapi\Exception as WebapiException;
use Magento\Webapi\Model\Soap\Config as SoapConfig;
use Magento\Framework\Reflection\MethodsMap;

/**
* Handler of requests to SOAP server.
Expand Down Expand Up @@ -48,6 +49,9 @@ class Handler
/** @var DataObjectProcessor */
protected $_dataObjectProcessor;

/** @var MethodsMap */
protected $methodsMapProcessor;

/**
* Initialize dependencies.
*
Expand All @@ -58,6 +62,7 @@ class Handler
* @param SimpleDataObjectConverter $dataObjectConverter
* @param ServiceInputProcessor $serviceInputProcessor
* @param DataObjectProcessor $dataObjectProcessor
* @param MethodsMap $methodsMapProcessor
*/
public function __construct(
SoapRequest $request,
Expand All @@ -66,7 +71,8 @@ public function __construct(
AuthorizationInterface $authorization,
SimpleDataObjectConverter $dataObjectConverter,
ServiceInputProcessor $serviceInputProcessor,
DataObjectProcessor $dataObjectProcessor
DataObjectProcessor $dataObjectProcessor,
MethodsMap $methodsMapProcessor
) {
$this->_request = $request;
$this->_objectManager = $objectManager;
Expand All @@ -75,6 +81,7 @@ public function __construct(
$this->_dataObjectConverter = $dataObjectConverter;
$this->serviceInputProcessor = $serviceInputProcessor;
$this->_dataObjectProcessor = $dataObjectProcessor;
$this->methodsMapProcessor = $methodsMapProcessor;
}

/**
Expand Down Expand Up @@ -149,7 +156,7 @@ protected function _prepareRequestData($serviceClass, $serviceMethod, $arguments
protected function _prepareResponseData($data, $serviceClassName, $serviceMethodName)
{
/** @var string $dataType */
$dataType = $this->_dataObjectProcessor->getMethodReturnType($serviceClassName, $serviceMethodName);
$dataType = $this->methodsMapProcessor->getMethodReturnType($serviceClassName, $serviceMethodName);
$result = null;
if (is_object($data)) {
$result = $this->_dataObjectConverter
Expand Down
18 changes: 1 addition & 17 deletions app/code/Magento/Webapi/Model/Rest/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected function _createRoute($routeData)
/** @var $route \Magento\Webapi\Controller\Rest\Router\Route */
$route = $this->_routeFactory->createRoute(
'Magento\Webapi\Controller\Rest\Router\Route',
$this->_formatRoutePath($routeData[self::KEY_ROUTE_PATH])
$routeData[self::KEY_ROUTE_PATH]
);

$route->setServiceClass($routeData[self::KEY_CLASS])
Expand All @@ -78,22 +78,6 @@ protected function _createRoute($routeData)
return $route;
}

/**
* Lowercase all parts of the given route path except for the path parameters.
*
* @param string $routePath The route path (e.g. '/V1/Categories/:categoryId')
* @return string The modified route path (e.g. '/v1/categories/:categoryId')
*/
protected function _formatRoutePath($routePath)
{
$routePathParts = explode('/', $routePath);
$pathParts = [];
foreach ($routePathParts as $pathPart) {
$pathParts[] = substr($pathPart, 0, 1) === ":" ? $pathPart : strtolower($pathPart);
}
return implode('/', $pathParts);
}

/**
* Get service base URL
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,7 @@ public function dataProviderRoutes()
['/V1/one/two/:threeValue/four/:fiveValue', '/V1/one/two/3/four/5', ['threeValue' => 3, 'fiveValue' => 5]],

['/v1/One', '/v1/One', []],
['/v1/oNe', '/V1/one', []],
['/v1/onE', '/V1/oNe', []],

['/v1/One/:twoValue', '/V1/one/2', ['twoValue' => 2]],
['/v1/oNe/:TwoValue', '/v1/oNe/2', ['TwoValue' => 2]],
['/v1/onE/:twovalue', '/v1/onE/2', ['twovalue' => 2]],

Expand All @@ -108,6 +105,9 @@ public function dataProviderRoutes()
['/V1/one-one/:two_value', '/V1/one-one/2', ['two_value' => 2]],

// Error
['/v1/oNe', '/V1/one', false],
['/v1/onE', '/V1/oNe', false],
['/v1/One/:twoValue', '/V1/one/2', false],
['/V1/one', '/V1/two', false],
['/V1/one/:twoValue', '/V1/one', false],
['/V1/one/two', '/V1/one', false],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class HandlerTest extends \PHPUnit_Framework_TestCase
/** @var \Magento\Framework\Reflection\DataObjectProcessor|\PHPUnit_Framework_MockObject_MockObject */
protected $_dataObjectProcessorMock;

/** @var \Magento\Framework\Reflection\MethodsMap|\PHPUnit_Framework_MockObject_MockObject */
protected $_methodsMapProcessorMock;

/** @var array */
protected $_arguments;

Expand Down Expand Up @@ -67,7 +70,13 @@ protected function setUp()
);
$this->_dataObjectProcessorMock = $this->getMock(
'Magento\Framework\Reflection\DataObjectProcessor',
['getMethodReturnType'],
[],
[],
'',
false);
$this->_methodsMapProcessorMock = $this->getMock(
'Magento\Framework\Reflection\MethodsMap',
[],
[],
'',
false);
Expand All @@ -80,7 +89,8 @@ protected function setUp()
$this->_authorizationMock,
$this->_dataObjectConverter,
$this->_serviceInputProcessorMock,
$this->_dataObjectProcessorMock
$this->_dataObjectProcessorMock,
$this->_methodsMapProcessorMock
);
parent::setUp();
}
Expand Down Expand Up @@ -128,10 +138,6 @@ public function testCall()
->method('process')
->will($this->returnArgument(2));

$this->_dataObjectProcessorMock->expects($this->any())->method('getMethodReturnType')
->with($className, $methodName)
->will($this->returnValue('string'));

/** Execute SUT. */
$this->assertEquals(
['result' => $serviceResponse],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,21 @@ class DataObjectProcessorTest extends \PHPUnit_Framework_TestCase
protected function setup()
{
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->dataObjectProcessor = $objectManager->getObject('Magento\Framework\Reflection\DataObjectProcessor');
$methodsMapProcessor = $objectManager->getObject(
'Magento\Framework\Reflection\MethodsMap',
[
'fieldNamer' => $objectManager->getObject('Magento\Framework\Reflection\FieldNamer'),
'typeProcessor' => $objectManager->getObject('Magento\Framework\Reflection\TypeProcessor'),
]
);
$this->dataObjectProcessor = $objectManager->getObject(
'Magento\Framework\Reflection\DataObjectProcessor',
[
'methodsMapProcessor' => $methodsMapProcessor,
'typeCaster' => $objectManager->getObject('Magento\Framework\Reflection\TypeCaster'),
'fieldNamer' => $objectManager->getObject('Magento\Framework\Reflection\FieldNamer'),
]
);
parent::setUp();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,23 @@

interface TestDataInterface
{
/**
* @return string
*/
public function getId();

/**
* @return string
*/
public function getAddress();

/**
* @return string
*/
public function isDefaultShipping();

/**
* @return string
*/
public function isRequiredBilling();
}
8 changes: 7 additions & 1 deletion app/code/Magento/Webapi/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@
<type name="Magento\Framework\Xml\Parser" shared="false" />
<type name="Magento\Framework\Code\Scanner\DirectoryScanner" shared="false" />
<type name="Magento\Server\Reflection" shared="false" />
<type name="Magento\Framework\Reflection\DataObjectProcessor">
<type name="Magento\Framework\Reflection\MethodsMap">
<arguments>
<argument name="cache" xsi:type="object">Magento\Framework\App\Cache\Type\Webapi</argument>
</arguments>
</type>
<type name="Magento\Framework\Reflection\DataObjectProcessor">
<arguments>
<argument name="extensionAttributesProcessor" xsi:type="object">Magento\Framework\Reflection\ExtensionAttributesProcessor\Proxy</argument>
<argument name="customAttributesProcessor" xsi:type="object">Magento\Framework\Reflection\CustomAttributesProcessor\Proxy</argument>
</arguments>
</type>
<type name="Magento\Integration\Model\ConfigBasedIntegrationManager">
<plugin name="webapiSetup" type="Magento\Webapi\Model\Plugin\Manager" />
</type>
Expand Down
Loading

0 comments on commit 635ce44

Please sign in to comment.