|
5 | 5 | */
|
6 | 6 | namespace Magento\Framework\View\Test\Unit\Element\Html;
|
7 | 7 |
|
| 8 | +use Magento\Framework\Locale\ResolverInterface; |
| 9 | +use Magento\Framework\Stdlib\DateTime\TimezoneInterface; |
| 10 | +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
| 11 | +use Magento\Framework\View\Element\Html\Calendar; |
| 12 | +use Magento\Framework\View\Element\Template\Context; |
| 13 | +use PHPUnit_Framework_MockObject_MockObject as MockObject; |
| 14 | + |
| 15 | +/** |
| 16 | + * @see Calendar |
| 17 | + */ |
8 | 18 | class CalendarTest extends \PHPUnit_Framework_TestCase
|
9 | 19 | {
|
10 | 20 | /**
|
11 |
| - * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager |
| 21 | + * @see MAGETWO-60828 |
| 22 | + * @see Calendar::_toHtml |
| 23 | + * |
| 24 | + * @param string $locale |
| 25 | + * @dataProvider localesDataProvider |
12 | 26 | */
|
13 |
| - protected $objectManagerHelper; |
14 |
| - |
15 |
| - /** @var \Magento\Framework\View\Element\Html\Calendar */ |
16 |
| - protected $block; |
17 |
| - |
18 |
| - /** @var \Magento\Framework\View\Element\Template\Context */ |
19 |
| - protected $context; |
| 27 | + public function testToHtmlWithDifferentLocales($locale) |
| 28 | + { |
| 29 | + $calendarBlock = (new ObjectManager($this))->getObject( |
| 30 | + Calendar::class, |
| 31 | + [ |
| 32 | + 'localeResolver' => $this->getLocalResolver($locale) |
| 33 | + ] |
| 34 | + ); |
20 | 35 |
|
21 |
| - /** @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface|\PHPUnit_Framework_MockObject_MockObject */ |
22 |
| - protected $localeDate; |
| 36 | + $calendarBlock->toHtml(); |
| 37 | + } |
23 | 38 |
|
24 |
| - protected function setUp() |
| 39 | + /** |
| 40 | + * @return array |
| 41 | + */ |
| 42 | + public function localesDataProvider() |
25 | 43 | {
|
26 |
| - $this->objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); |
27 |
| - $this->localeDate = $this->getMockBuilder(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::class) |
28 |
| - ->getMock(); |
| 44 | + return [ |
| 45 | + ['en_US'], |
| 46 | + ['ja_JP'], |
| 47 | + ['ko_KR'], |
| 48 | + ]; |
| 49 | + } |
29 | 50 |
|
30 |
| - /** @var \Magento\Framework\View\Element\Template\Context $context */ |
31 |
| - $this->context = $this->objectManagerHelper->getObject( |
32 |
| - \Magento\Framework\View\Element\Template\Context::class, |
| 51 | + /** |
| 52 | + * @see Calendar::getYearRange |
| 53 | + */ |
| 54 | + public function testGetYearRange() |
| 55 | + { |
| 56 | + $calendarBlock = (new ObjectManager($this))->getObject( |
| 57 | + Calendar::class, |
33 | 58 | [
|
34 |
| - 'localeDate' => $this->localeDate, |
| 59 | + 'context' => $this->getContext() |
35 | 60 | ]
|
36 | 61 | );
|
37 | 62 |
|
38 |
| - /** @var \Magento\Framework\View\Element\Html\Links $block */ |
39 |
| - $this->block = $this->objectManagerHelper->getObject( |
40 |
| - \Magento\Framework\View\Element\Html\Calendar::class, |
41 |
| - ['context' => $this->context] |
| 63 | + $testCurrentYear = (new \DateTime())->format('Y'); |
| 64 | + $this->assertEquals( |
| 65 | + (int) $testCurrentYear - 100 . ':' . ($testCurrentYear + 100), |
| 66 | + $calendarBlock->getYearRange() |
42 | 67 | );
|
43 | 68 | }
|
44 | 69 |
|
45 | 70 | /**
|
46 |
| - * @test |
| 71 | + * @param string $locale |
| 72 | + * @return ResolverInterface|MockObject |
47 | 73 | */
|
48 |
| - public function testGetYearRange() |
| 74 | + private function getLocalResolver($locale) |
49 | 75 | {
|
50 |
| - $testCurrentYear = (new \DateTime())->format('Y'); |
51 |
| - $this->assertEquals((int)$testCurrentYear - 100 . ':' . ($testCurrentYear + 100), $this->block->getYearRange()); |
| 76 | + $localResolver = $this->getMockBuilder(ResolverInterface::class) |
| 77 | + ->getMockForAbstractClass(); |
| 78 | + $localResolver->method('getLocale')->willReturn($locale); |
| 79 | + |
| 80 | + return $localResolver; |
| 81 | + } |
| 82 | + |
| 83 | + /** |
| 84 | + * @return Context|Object |
| 85 | + */ |
| 86 | + private function getContext() |
| 87 | + { |
| 88 | + $localeDate = $this->getMockBuilder(TimezoneInterface::class) |
| 89 | + ->getMockForAbstractClass(); |
| 90 | + |
| 91 | + return (new ObjectManager($this))->getObject( |
| 92 | + Context::class, |
| 93 | + ['localeDate' => $localeDate] |
| 94 | + ); |
52 | 95 | }
|
53 | 96 | }
|
0 commit comments