Skip to content

Commit 7c81c1d

Browse files
author
Oleksii Korshenko
authored
Merge pull request #830 from magento-engcom/develop-prs
[EngCom] Public Pull Requests Public Pull Requests #8356 #8474 #8487 #8217 #8413
2 parents 5eb49dc + 4f7ab1a commit 7c81c1d

File tree

14 files changed

+344
-103
lines changed

14 files changed

+344
-103
lines changed

app/code/Magento/Captcha/Model/DefaultModel.php

Lines changed: 97 additions & 87 deletions
Large diffs are not rendered by default.

app/code/Magento/Captcha/Test/Unit/Helper/DataTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ protected function setUp()
5353
*/
5454
public function testGetCaptcha()
5555
{
56+
if (!function_exists("imageftbbox")) {
57+
$this->markTestSkipped('imageftbbox is not available on the test environment');
58+
}
59+
5660
$this->configMock->expects(
5761
$this->once()
5862
)->method(

app/code/Magento/Captcha/Test/Unit/Model/DefaultTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ class DefaultTest extends \PHPUnit_Framework_TestCase
8888
*/
8989
protected function setUp()
9090
{
91+
if (!function_exists("imageftbbox")) {
92+
$this->markTestSkipped('imageftbbox is not available on the test environment');
93+
}
9194
$this->session = $this->_getSessionStub();
9295

9396
$this->_storeManager = $this->getMock(

app/code/Magento/Captcha/composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
"magento/module-checkout": "100.2.*",
99
"magento/module-backend": "100.2.*",
1010
"magento/framework": "100.2.*",
11-
"zendframework/zend-db": "~2.4.6"
11+
"zendframework/zend-db": "~2.4.6",
12+
"zendframework/zend-captcha": "~2.4.6",
13+
"zendframework/zend-session": "~2.4.6"
1214
},
1315
"type": "magento2-module",
1416
"version": "100.2.0-dev",

app/code/Magento/Quote/Model/Quote/Validator/MinimumOrderAmount/ValidationMessage.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ public function __construct(
3838
}
3939

4040
/**
41-
* @return \Magento\Framework\Phrase|mixed
41+
* Get validation message.
42+
*
43+
* @return \Magento\Framework\Phrase
4244
* @throws \Zend_Currency_Exception
4345
*/
4446
public function getMessage()
@@ -56,6 +58,9 @@ public function getMessage()
5658
)
5759
);
5860
$message = __('Minimum order amount is %1', $minimumAmount);
61+
} else {
62+
//Added in order to address the issue: https://github.com/magento/magento2/issues/8287
63+
$message = __($message);
5964
}
6065

6166
return $message;

app/code/Magento/Quote/Test/Unit/Model/Quote/Validator/MinimumOrderAmount/ValidationMessageTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Quote\Test\Unit\Model\Quote\Validator\MinimumOrderAmount;
77

8+
use Magento\Framework\Phrase;
9+
810
class ValidationMessageTest extends \PHPUnit_Framework_TestCase
911
{
1012
/**
@@ -60,7 +62,6 @@ public function testGetMessage()
6062
$storeMock->expects($this->once())->method('getCurrentCurrencyCode')->willReturn($currencyCode);
6163
$this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($storeMock);
6264

63-
6465
$currencyMock = $this->getMock(\Magento\Framework\Currency::class, [], [], '', false);
6566
$this->currencyMock->expects($this->once())
6667
->method('getCurrency')
@@ -86,6 +87,9 @@ public function testGetConfigMessage()
8687
->with('sales/minimum_order/description', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)
8788
->willReturn($configMessage);
8889

89-
$this->assertEquals($configMessage, $this->model->getMessage());
90+
$message = $this->model->getMessage();
91+
92+
$this->assertEquals(Phrase::class, get_class($message));
93+
$this->assertEquals($configMessage, $message->__toString());
9094
}
9195
}

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@
66

77
namespace Magento\Translation\Model\Js;
88

9+
use Magento\Framework\Exception\LocalizedException;
10+
911
/**
1012
* DataProvider for js translation
13+
*
14+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1115
*/
1216
class DataProvider implements DataProviderInterface
1317
{
@@ -103,9 +107,15 @@ public function getData($themePath)
103107
$read = $this->fileReadFactory->create($filePath[0], \Magento\Framework\Filesystem\DriverPool::FILE);
104108
$content = $read->readAll();
105109
foreach ($this->getPhrases($content) as $phrase) {
106-
$translatedPhrase = $this->translate->render([$phrase], []);
107-
if ($phrase != $translatedPhrase) {
108-
$dictionary[$phrase] = $translatedPhrase;
110+
try {
111+
$translatedPhrase = $this->translate->render([$phrase], []);
112+
if ($phrase != $translatedPhrase) {
113+
$dictionary[$phrase] = $translatedPhrase;
114+
}
115+
} catch (\Exception $e) {
116+
throw new LocalizedException(
117+
sprintf(__('Error while translating phrase "%s" in file %s.'), $phrase, $filePath[0])
118+
);
109119
}
110120
}
111121
}
@@ -118,7 +128,7 @@ public function getData($themePath)
118128
*
119129
* @param string $content
120130
* @return string[]
121-
* @throws \Exception
131+
* @throws \Magento\Framework\Exception\LocalizedException
122132
*/
123133
protected function getPhrases($content)
124134
{
@@ -134,8 +144,8 @@ protected function getPhrases($content)
134144
}
135145
}
136146
if (false === $result) {
137-
throw new \Exception(
138-
sprintf('Error while generating js translation dictionary: "%s"', error_get_last())
147+
throw new LocalizedException(
148+
sprintf(__('Error while generating js translation dictionary: "%s"'), error_get_last())
139149
);
140150
}
141151
}

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
"zendframework/zend-log": "~2.4.6",
3333
"zendframework/zend-http": "~2.4.6",
3434
"zendframework/zend-db": "~2.4.6",
35+
"zendframework/zend-captcha": "~2.4.6",
36+
"zendframework/zend-session": "~2.4.6",
3537
"magento/zendframework1": "~1.12.16",
3638
"colinmollenhour/credis": "1.6",
3739
"colinmollenhour/php-redis-session-abstract": "1.2",

composer.lock

Lines changed: 121 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/tests/integration/etc/di/preferences/ce.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@
2323
\Magento\TestFramework\Db\ConnectionAdapter::class,
2424
\Magento\Framework\Filesystem\DriverInterface::class => \Magento\Framework\Filesystem\Driver\File::class,
2525
\Magento\Framework\App\Config\ScopeConfigInterface::class => \Magento\TestFramework\App\Config::class,
26+
\Magento\Captcha\Model\DefaultModel::class => \Magento\TestFramework\Captcha\DefaultModel::class,
2627
];
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\TestFramework\Captcha;
7+
8+
/**
9+
* Implementation of \Zend\Captcha\Image for integration test environment.
10+
*
11+
* With introducing "zendframework/zend-captcha": "~2.4.6" (see https://github.com/magento/magento2/pull/8356)
12+
* validation happens in \Zend\Captcha\Image class constructor that blocks testing on Travis CI, even for cases
13+
* when this functionality is not needed.
14+
* For test environment that supports freetype functional behaviour should not be changed.
15+
*/
16+
class DefaultModel extends \Magento\Captcha\Model\DefaultModel
17+
{
18+
/**
19+
* Do not pass onto the parent constructor as imageftbbox is not initialized on travis
20+
*
21+
* @param \Magento\Framework\Session\SessionManagerInterface $session
22+
* @param \Magento\Captcha\Helper\Data $captchaData
23+
* @param \Magento\Captcha\Model\ResourceModel\LogFactory $resLogFactory
24+
* @param string $formId
25+
*/
26+
public function __construct(
27+
\Magento\Framework\Session\SessionManagerInterface $session,
28+
\Magento\Captcha\Helper\Data $captchaData,
29+
\Magento\Captcha\Model\ResourceModel\LogFactory $resLogFactory,
30+
$formId
31+
) {
32+
/**
33+
* Workaround for test environments that do not support freetype.
34+
*/
35+
if (function_exists("imageftbbox")) {
36+
parent::__construct($session, $captchaData, $resLogFactory, $formId);
37+
} else {
38+
$this->session = $session;
39+
$this->captchaData = $captchaData;
40+
$this->resLogFactory = $resLogFactory;
41+
$this->formId = $formId;
42+
}
43+
}
44+
}

lib/internal/Magento/Framework/App/Cron.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
namespace Magento\Framework\App;
99

1010
use Magento\Framework\App;
11-
use Magento\Framework\App\Area;
1211
use Magento\Framework\ObjectManagerInterface;
1312

13+
/**
14+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
15+
*/
1416
class Cron implements \Magento\Framework\AppInterface
1517
{
1618
/**
@@ -35,6 +37,11 @@ class Cron implements \Magento\Framework\AppInterface
3537
*/
3638
private $objectManager;
3739

40+
/**
41+
* @var \Magento\Framework\App\AreaList
42+
*/
43+
private $areaList;
44+
3845
/**
3946
* Inject dependencies
4047
*
@@ -43,19 +50,22 @@ class Cron implements \Magento\Framework\AppInterface
4350
* @param Console\Response $response
4451
* @param ObjectManagerInterface $objectManager
4552
* @param array $parameters
53+
* @param AreaList|null $areaList
4654
*/
4755
public function __construct(
4856
State $state,
4957
Console\Request $request,
5058
Console\Response $response,
5159
ObjectManagerInterface $objectManager,
52-
array $parameters = []
60+
array $parameters = [],
61+
\Magento\Framework\App\AreaList $areaList = null
5362
) {
5463
$this->_state = $state;
5564
$this->_request = $request;
5665
$this->_request->setParams($parameters);
5766
$this->_response = $response;
5867
$this->objectManager = $objectManager;
68+
$this->areaList = $areaList ? $areaList : $this->objectManager->get(\Magento\Framework\App\AreaList::class);
5969
}
6070

6171
/**
@@ -69,6 +79,8 @@ public function launch()
6979
$configLoader = $this->objectManager->get(\Magento\Framework\ObjectManager\ConfigLoaderInterface::class);
7080
$this->objectManager->configure($configLoader->load(Area::AREA_CRONTAB));
7181

82+
$this->areaList->getArea(Area::AREA_CRONTAB)->load(Area::PART_TRANSLATE);
83+
7284
/** @var \Magento\Framework\Event\ManagerInterface $eventManager */
7385
$eventManager = $this->objectManager->get(\Magento\Framework\Event\ManagerInterface::class);
7486
$eventManager->dispatch('default');

0 commit comments

Comments
 (0)