Skip to content

Commit

Permalink
MAGETWO-32767: [GITHUB] #963
Browse files Browse the repository at this point in the history
- Added default accept if no Accept header passed
- Added api functional tests
  • Loading branch information
anupdugar committed Jan 16, 2015
1 parent d33f01d commit 1c98bd8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/code/Magento/Webapi/Controller/Rest/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class Request extends \Magento\Webapi\Controller\Request
*/
const REQUEST_CHARSET = 'utf-8';

const DEFAULT_ACCEPT = '*/*';

/** @var string */
protected $_serviceName;

Expand Down Expand Up @@ -101,7 +103,7 @@ public function getAcceptTypes()
foreach ($qualityToTypes as $typeList) {
$orderedTypes += $typeList;
}
return array_keys($orderedTypes);
return empty($orderedTypes) ? self::DEFAULT_ACCEPT : array_keys($orderedTypes);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@
<resource ref="Magento_TestModule1::resource2" />
</resources>
</route>
<route method="GET" url="/V1/testmodule1/resource1/:itemId">
<service class="Magento\TestModule1\Service\V1\AllSoapAndRestInterface" method="item" />
<resources>
<resource ref="anonymous" />
</resources>
</route>
<route method="POST" url="/V1/testmodule1/itemAnyType">
<service class="Magento\TestModule1\Service\V1\AllSoapAndRestInterface" method="itemAnyType" />
<resources>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
*/
namespace Magento\Webapi\Routing;


use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\TestCase\Webapi\Adapter\Rest\CurlClient;

class CoreRoutingTest extends \Magento\Webapi\Routing\BaseService
{
public function testBasicRoutingExplicitPath()
Expand Down Expand Up @@ -73,4 +77,15 @@ public function testExceptionSoapInternalError()
$this->setExpectedException('SoapFault', 'Generic service exception');
$this->_webApiCall($serviceInfo);
}

public function testRestNoAcceptHeader()
{
$this->_markTestAsRestOnly();
/** @var $curlClient CurlClient */
$curlClient = Bootstrap::getObjectManager()->get(
'Magento\TestFramework\TestCase\Webapi\Adapter\Rest\CurlClient'
);
$response = $curlClient->get('/V1/testmodule1/resource1/1', [], ['Accept:']);
$this->assertEquals('testProduct1', $response['name'], "Empty Accept header failed to return response.");
}
}

0 comments on commit 1c98bd8

Please sign in to comment.