Skip to content

Load translations for area, fixes #8412 #8413

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions lib/internal/Magento/Framework/App/Cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
namespace Magento\Framework\App;

use Magento\Framework\App;
use Magento\Framework\App\Area;
use Magento\Framework\ObjectManagerInterface;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class Cron implements \Magento\Framework\AppInterface
{
/**
Expand All @@ -35,6 +37,11 @@ class Cron implements \Magento\Framework\AppInterface
*/
private $objectManager;

/**
* @var \Magento\Framework\App\AreaList
*/
private $areaList;

/**
* Inject dependencies
*
Expand All @@ -43,19 +50,22 @@ class Cron implements \Magento\Framework\AppInterface
* @param Console\Response $response
* @param ObjectManagerInterface $objectManager
* @param array $parameters
* @param AreaList|null $areaList
*/
public function __construct(
State $state,
Console\Request $request,
Console\Response $response,
ObjectManagerInterface $objectManager,
array $parameters = []
array $parameters = [],
\Magento\Framework\App\AreaList $areaList = null
) {
$this->_state = $state;
$this->_request = $request;
$this->_request->setParams($parameters);
$this->_response = $response;
$this->objectManager = $objectManager;
$this->areaList = $areaList ? $areaList : $this->objectManager->get(\Magento\Framework\App\AreaList::class);
}

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

$this->areaList->getArea(Area::AREA_CRONTAB)->load(Area::PART_TRANSLATE);

/** @var \Magento\Framework\Event\ManagerInterface $eventManager */
$eventManager = $this->objectManager->get(\Magento\Framework\Event\ManagerInterface::class);
$eventManager->dispatch('default');
Expand Down
28 changes: 26 additions & 2 deletions lib/internal/Magento/Framework/App/Test/Unit/CronTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,42 @@ protected function setUp()
$this->_request = $this->getMock(\Magento\Framework\App\Console\Request::class, [], [], '', false);
$this->_responseMock = $this->getMock(\Magento\Framework\App\Console\Response::class, [], [], '', false);
$this->objectManager = $this->getMockForAbstractClass(\Magento\Framework\ObjectManagerInterface::class);
$this->_model = new Cron($this->_stateMock, $this->_request, $this->_responseMock, $this->objectManager);
$this->_model = new Cron(
$this->_stateMock,
$this->_request,
$this->_responseMock,
$this->objectManager,
[],
$this->prepareAreaListMock()
);
}

protected function prepareAreaListMock()
{
$areaMock = $this->getMock(\Magento\Framework\App\Area::class, [], [], '', false);
$areaMock->expects($this->once())
->method('load')
->with(Area::PART_TRANSLATE);

$areaListMock = $this->getMock(\Magento\Framework\App\AreaList::class, [], [], '', false);
$areaListMock->expects($this->any())
->method('getArea')
->with(Area::AREA_CRONTAB)
->willReturn($areaMock);

return $areaListMock;
}

public function testLaunchDispatchesCronEvent()
{
$configLoader = $this->getMockForAbstractClass(\Magento\Framework\ObjectManager\ConfigLoaderInterface::class);
$eventManagerMock = $this->getMock(\Magento\Framework\Event\ManagerInterface::class);

$this->objectManager->expects($this->any())
->method('get')
->will($this->returnValueMap([
[\Magento\Framework\ObjectManager\ConfigLoaderInterface::class, $configLoader],
[\Magento\Framework\Event\ManagerInterface::class, $eventManagerMock],
[\Magento\Framework\Event\ManagerInterface::class, $eventManagerMock]
]));
$crontabConfig = ['config'];
$configLoader->expects($this->once())
Expand Down