-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1469 from magento-engcom/develop-prs
[EngCom] Public Pull Requests - MAGETWO-72390: Remove the usage of the DataObject for response management #10808 - MAGETWO-71545: Added 'application/json' Content-Type to Ajax responses in the Magento_UI module. #10521 - MAGETWO-72388: Fix spelling mistake in AddressTest.php #10806 - MAGETWO-72283: Code generate: support variadic parameter #10771
- Loading branch information
Showing
15 changed files
with
295 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Ui\Model; | ||
|
||
use Magento\Framework\View\Element\UiComponent\ContextInterface as UiComponentContext; | ||
|
||
/** | ||
* Provides correct Content-Type header value for the Ui Component renderer based on the Accept Type of | ||
* the Component Context. Additional types may be added to the type map via di.xml configuration for this resolver. | ||
* | ||
* This is a workaround for the lacking Content-Type processing in | ||
* \Magento\Framework\View\Element\UiComponent\ContentType\ContentTypeInterface | ||
*/ | ||
class UiComponentTypeResolver | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
const DEFAULT_CONTENT_TYPE = 'text/html'; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $uiComponentTypeMap = []; | ||
|
||
/** | ||
* @param array $uiComponentTypeMap | ||
*/ | ||
public function __construct(array $uiComponentTypeMap) | ||
{ | ||
$this->uiComponentTypeMap = $uiComponentTypeMap; | ||
} | ||
|
||
/** | ||
* @param UiComponentContext $componentContext | ||
* @return string | ||
*/ | ||
public function resolve(UiComponentContext $componentContext): string | ||
{ | ||
$acceptType = $componentContext->getAcceptType(); | ||
return $this->uiComponentTypeMap[$acceptType] ?? static::DEFAULT_CONTENT_TYPE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
app/code/Magento/Ui/Test/Unit/Model/UiComponentTypeResolverTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Ui\Test\Unit\Model; | ||
|
||
use Magento\Ui\Model\UiComponentTypeResolver; | ||
use Magento\Framework\View\Element\UiComponent\ContextInterface; | ||
|
||
class UiComponentTypeResolverTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
/** | ||
* @var UiComponentTypeResolver | ||
*/ | ||
private $model; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $contentTypeMap = []; | ||
|
||
protected function setUp() | ||
{ | ||
$this->contentTypeMap = [ | ||
'xml' => 'application/xml', | ||
'json' => 'application/json', | ||
'html' => 'text/html' | ||
]; | ||
$this->model = new UiComponentTypeResolver($this->contentTypeMap); | ||
} | ||
|
||
/** | ||
* @param string $acceptType | ||
* @param string $contentType | ||
* @dataProvider resolveDataProvider | ||
*/ | ||
public function testResolve(string $acceptType, string $contentType) | ||
{ | ||
$uiComponentContextMock = $this->createMock(ContextInterface::class); | ||
$uiComponentContextMock->expects($this->atLeastOnce())->method('getAcceptType')->willReturn($acceptType); | ||
|
||
$this->assertEquals($contentType, $this->model->resolve($uiComponentContextMock)); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function resolveDataProvider(): array | ||
{ | ||
return [ | ||
['json', 'application/json'], | ||
['xml', 'application/xml'], | ||
['html', 'text/html'], | ||
['undefined', UiComponentTypeResolver::DEFAULT_CONTENT_TYPE] | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.