Skip to content

Commit

Permalink
[2.3-develop] Forwardport of #13408
Browse files Browse the repository at this point in the history
  • Loading branch information
magento-engcom-team committed Feb 6, 2018
1 parent e075ca7 commit a6c2bc2
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Magento\Backend\Block\Template\Context;
use Magento\Framework\Data\Form;
use Magento\Framework\Data\Form\Element\AbstractElement;
use Magento\Framework\Locale\ResolverInterface;
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;

Expand All @@ -34,6 +35,11 @@ class CollectionTimeLabelTest extends \PHPUnit\Framework\TestCase
*/
private $abstractElementMock;

/**
* @var ResolverInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $localeResolver;

protected function setUp()
{
$this->abstractElementMock = $this->getMockBuilder(AbstractElement::class)
Expand All @@ -53,12 +59,17 @@ protected function setUp()
$this->contextMock->expects($this->any())
->method('getLocaleDate')
->willReturn($this->timeZoneMock);
$this->localeResolver = $this->getMockBuilder(ResolverInterface::class)
->disableOriginalConstructor()
->setMethods(['getLocale'])
->getMockForAbstractClass();

$objectManager = new ObjectManager($this);
$this->collectionTimeLabel = $objectManager->getObject(
CollectionTimeLabel::class,
[
'context' => $this->contextMock
'context' => $this->contextMock,
'localeResolver' => $this->localeResolver
]
);
}
Expand All @@ -73,6 +84,9 @@ public function testRender()
$this->abstractElementMock->expects($this->any())
->method('getComment')
->willReturn('Eastern Standard Time (America/New_York)');
$this->localeResolver->expects($this->once())
->method('getLocale')
->willReturn('en_US');
$this->assertRegexp(
"/Eastern Standard Time \(America\/New_York\)/",
$this->collectionTimeLabel->render($this->abstractElementMock)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Analytics\Block\Adminhtml\System\Config;

use Magento\Framework\Data\FormFactory;
use Magento\Framework\Data\Form\Element\TimeFactory;
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\TestCase;

/**
* Provide tests for CollectionTimeLabel block.
*/
class CollectionTimeLabelTest extends TestCase
{
/**
* Test render will add comment considering config locale(default en_US).
*
* @magentoAppIsolation enabled
*/
public function testRenderWithDefaultLocale()
{
$result = $this->render();
$this->assertRegExp('/<span>Pacific Standard Time/', $result);
}

/**
* Test render will add comment considering config locale(non-default de_DE).
*
* @magentoConfigFixture default_store general/locale/code de_DE
* @magentoAppIsolation enabled
*/
public function testRenderWithNonDefaultLocale()
{
$result = $this->render();
$this->assertRegExp('/<span>Nordamerikanische Westküsten-Normalzeit/', $result);
}

/**
* Render 'time' element.
*
* @return string
*/
private function render()
{
$collectionTimeLabel = Bootstrap::getObjectManager()->get(CollectionTimeLabelFactory::class)->create();
$form = Bootstrap::getObjectManager()->get(FormFactory::class)->create();
$element = Bootstrap::getObjectManager()->get(TimeFactory::class)->create();
$element->setForm($form);

return $collectionTimeLabel->render($element);
}

}

0 comments on commit a6c2bc2

Please sign in to comment.