Skip to content

Commit 71e57a6

Browse files
author
Oleksii Korshenko
authored
🔃 [EngCom] Public Pull Requests - 2.3-develop
Accepted Public Pull Requests: - #12848: Update functional.suite.dist.yml to handle a custom backend name (by @scribam) - #12007: Fix #2156 Js\Dataprovider uses the RendererInterface. (by @dverkade) - #12806: Update checkout controller json usage (by @dmanners) Fixed GitHub Issues: - #2156: Why does \Magento\Translation\Model\Js\DataProvider use \Magento\Framework\Phrase\Renderer\Translate, not \Magento\Framework\Phrase\Renderer\Composite? (reported by @dmitry-fedyuk) has been fixed in #12007 by @dverkade in 2.3-develop branch Related commits: 1. db0c775
2 parents 2c0a91c + 9a027d5 commit 71e57a6

File tree

5 files changed

+54
-41
lines changed

5 files changed

+54
-41
lines changed

app/code/Magento/Checkout/Controller/Account/Create.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Checkout\Controller\Account;
77

8+
use Magento\Framework\Controller\ResultFactory;
89
use Magento\Framework\Exception\AlreadyExistsException;
910
use Magento\Framework\Exception\NoSuchEntityException;
1011

@@ -55,7 +56,7 @@ public function __construct(
5556
public function execute()
5657
{
5758
/** @var \Magento\Framework\Controller\Result\Json $resultJson */
58-
$resultJson = $this->_objectManager->get(\Magento\Framework\Controller\Result\JsonFactory::class)->create();
59+
$resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);
5960

6061
if ($this->customerSession->isLoggedIn()) {
6162
return $resultJson->setData(
@@ -83,7 +84,7 @@ public function execute()
8384
]
8485
);
8586
} catch (\Exception $e) {
86-
$this->messageManager->addException($e, $e->getMessage());
87+
$this->messageManager->addExceptionMessage($e, $e->getMessage());
8788
throw $e;
8889
}
8990
}

app/code/Magento/Checkout/Test/Unit/Controller/Account/CreateTest.php

Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Checkout\Test\Unit\Controller\Account;
77

8+
use Magento\Framework\Controller\ResultFactory;
9+
810
/**
911
* Shopping cart edit tests
1012
*/
@@ -36,9 +38,14 @@ class CreateTest extends \PHPUnit\Framework\TestCase
3638
protected $orderCustomerService;
3739

3840
/**
39-
* @var \PHPUnit_Framework_MockObject_MockObject
41+
* @var \Magento\Framework\Controller\ResultFactory|\PHPUnit_Framework_MockObject_MockObject
42+
*/
43+
private $resultFactory;
44+
45+
/**
46+
* @var \Magento\Framework\Controller\ResultInterface|\PHPUnit_Framework_MockObject_MockObject
4047
*/
41-
protected $objectManagerMock;
48+
private $resultPage;
4249

4350
protected function setUp()
4451
{
@@ -48,9 +55,19 @@ protected function setUp()
4855
$this->orderCustomerService = $this->createMock(\Magento\Sales\Api\OrderCustomerManagementInterface::class);
4956
$this->messageManager = $this->createMock(\Magento\Framework\Message\ManagerInterface::class);
5057

51-
$this->objectManagerMock = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
52-
$contextMock = $this->createPartialMock(\Magento\Framework\App\Action\Context::class, ['getObjectManager']);
53-
$contextMock->expects($this->once())->method('getObjectManager')->willReturn($this->objectManagerMock);
58+
$contextMock = $this->createPartialMock(
59+
\Magento\Framework\App\Action\Context::class,
60+
['getObjectManager', 'getResultFactory']
61+
);
62+
$this->resultFactory = $this->getMockBuilder(\Magento\Framework\Controller\ResultFactory::class)
63+
->disableOriginalConstructor()
64+
->getMock();
65+
$contextMock->expects($this->once())
66+
->method('getResultFactory')
67+
->willReturn($this->resultFactory);
68+
$this->resultPage = $this->getMockBuilder(\Magento\Framework\Controller\ResultInterface::class)
69+
->setMethods(['setData'])
70+
->getMockForAbstractClass();
5471

5572
$this->action = $objectManagerHelper->getObject(
5673
\Magento\Checkout\Controller\Account\Create::class,
@@ -66,53 +83,48 @@ protected function setUp()
6683

6784
public function testExecuteAddsSessionMessageIfCustomerIsLoggedIn()
6885
{
69-
$jsonFactoryMock = $this->createMock(\Magento\Framework\Controller\Result\JsonFactory::class);
70-
$this->objectManagerMock->expects($this->once())
71-
->method('get')
72-
->with(\Magento\Framework\Controller\Result\JsonFactory::class)
73-
->willReturn($jsonFactoryMock);
74-
$jsonMock = $this->createMock(\Magento\Framework\Controller\Result\Json::class);
75-
$jsonFactoryMock->expects($this->once())->method('create')->willReturn($jsonMock);
76-
77-
$this->customerSession->expects($this->once())->method('isLoggedIn')->will($this->returnValue(true));
78-
79-
$jsonMock->expects($this->once())
86+
$resultJson = '{"errors": "true", "message": "Customer is already registered"}';
87+
$this->customerSession->expects($this->once())
88+
->method('isLoggedIn')
89+
->will($this->returnValue(true));
90+
$this->resultFactory->expects($this->once())
91+
->method('create')
92+
->with(ResultFactory::TYPE_JSON)
93+
->willReturn($this->resultPage);
94+
$this->resultPage->expects($this->once())
8095
->method('setData')
8196
->with(
8297
[
8398
'errors' => true,
8499
'message' => __('Customer is already registered')
85100
]
86-
)->willReturnSelf();
87-
$this->action->execute();
101+
)->willReturn($resultJson);
102+
$this->assertEquals($resultJson, $this->action->execute());
88103
}
89104

90105
public function testExecute()
91106
{
92-
$jsonFactoryMock = $this->createMock(\Magento\Framework\Controller\Result\JsonFactory::class);
93-
$this->objectManagerMock->expects($this->once())
94-
->method('get')
95-
->with(\Magento\Framework\Controller\Result\JsonFactory::class)
96-
->willReturn($jsonFactoryMock);
97-
$jsonMock = $this->createMock(\Magento\Framework\Controller\Result\Json::class);
98-
$jsonFactoryMock->expects($this->once())->method('create')->willReturn($jsonMock);
99-
100107
$this->customerSession->expects($this->once())->method('isLoggedIn')->will($this->returnValue(false));
101108
$this->checkoutSession->expects($this->once())->method('getLastOrderId')->will($this->returnValue(100));
102109
$customer = $this->createMock(\Magento\Customer\Api\Data\CustomerInterface::class);
103-
$this->orderCustomerService->expects($this->once())->method('create')->with(100)->will(
104-
$this->returnValue($customer)
105-
);
106-
107-
$jsonMock->expects($this->once())
110+
$this->orderCustomerService->expects($this->once())
111+
->method('create')
112+
->with(100)
113+
->will($this->returnValue($customer));
114+
115+
$resultJson = '{"errors":"false", "message":"A letter with further instructions will be sent to your email."}';
116+
$this->resultFactory->expects($this->once())
117+
->method('create')
118+
->with(ResultFactory::TYPE_JSON)
119+
->willReturn($this->resultPage);
120+
$this->resultPage->expects($this->once())
108121
->method('setData')
109122
->with(
110123
[
111124
'errors' => false,
112125
'message' => __('A letter with further instructions will be sent to your email.')
113126
]
114-
)->willReturnSelf();
115-
116-
$this->action->execute();
127+
)->willReturn($resultJson);
128+
$this->assertEquals($resultJson, $this->action->execute());
117129
}
118130
}

app/code/Magento/Translation/Model/Js/DataProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ class DataProvider implements DataProviderInterface
4646
/**
4747
* Basic translate renderer
4848
*
49-
* @var \Magento\Framework\Phrase\Renderer\Translate
49+
* @var \Magento\Framework\Phrase\RendererInterface
5050
*/
5151
protected $translate;
5252

5353
/**
5454
* @param \Magento\Framework\App\State $appState
5555
* @param Config $config
5656
* @param \Magento\Framework\Filesystem\File\ReadFactory $fileReadFactory
57-
* @param \Magento\Framework\Phrase\Renderer\Translate $translate
57+
* @param \Magento\Framework\Phrase\RendererInterface $translate
5858
* @param \Magento\Framework\Component\ComponentRegistrar $componentRegistrar
5959
* @param \Magento\Framework\Component\DirSearch $dirSearch
6060
* @param \Magento\Framework\View\Design\Theme\ThemePackageList $themePackageList
@@ -64,7 +64,7 @@ public function __construct(
6464
\Magento\Framework\App\State $appState,
6565
Config $config,
6666
\Magento\Framework\Filesystem\File\ReadFactory $fileReadFactory,
67-
\Magento\Framework\Phrase\Renderer\Translate $translate,
67+
\Magento\Framework\Phrase\RendererInterface $translate,
6868
\Magento\Framework\Component\ComponentRegistrar $componentRegistrar,
6969
\Magento\Framework\Component\DirSearch $dirSearch,
7070
\Magento\Framework\View\Design\Theme\ThemePackageList $themePackageList,

dev/tests/acceptance/tests/functional.suite.dist.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ modules:
2525
config:
2626
\Magento\FunctionalTestingFramework\Module\MagentoWebDriver:
2727
url: "%MAGENTO_BASE_URL%"
28-
backend_name: admin
28+
backend_name: "%MAGENTO_BACKEND_NAME%"
2929
browser: 'chrome'
3030
window_size: maximize
3131
username: "%MAGENTO_ADMIN_USERNAME%"

lib/internal/Magento/Framework/Phrase/Test/Unit/Renderer/InlineTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class InlineTest extends \PHPUnit\Framework\TestCase
1313
protected $translator;
1414

1515
/**
16-
* @var \Magento\Framework\Phrase\Renderer\Translate
16+
* @var \Magento\Framework\Phrase\Renderer\Inline
1717
*/
1818
protected $renderer;
1919

0 commit comments

Comments
 (0)