FormatConverterTest.php 1.4 KB
Newer Older
1 2
<?php

3
namespace yiiunit\framework\helpers;
4 5 6

use Yii;
use yii\helpers\FormatConverter;
7
use yii\i18n\Formatter;
8
use yiiunit\framework\i18n\IntlTestHelper;
9 10 11 12 13 14 15 16 17 18 19
use yiiunit\TestCase;

/**
 * @group helpers
 */
class FormatConverterTest extends TestCase
{
    protected function setUp()
    {
        parent::setUp();

20
        IntlTestHelper::setIntlStatus($this);
21 22 23 24 25 26 27 28 29 30

        $this->mockApplication([
            'timeZone' => 'UTC',
            'language' => 'ru-RU',
        ]);
    }

    protected function tearDown()
    {
        parent::tearDown();
31
        IntlTestHelper::resetIntlStatus();
32 33 34 35
    }

    public function testIntlIcuToPhpShortForm()
    {
36
        $this->assertEquals('n/j/y', FormatConverter::convertDateIcuToPhp('short', 'date', 'en-US'));
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
        $this->assertEquals('d.m.y', FormatConverter::convertDateIcuToPhp('short', 'date', 'de-DE'));
    }

    public function testIntlOneDigitIcu()
    {
        $formatter = new Formatter(['locale' => 'en-US']);
        $this->assertEquals('24.8.2014', $formatter->asDate('2014-8-24', 'php:d.n.Y'));
        $this->assertEquals('24.8.2014', $formatter->asDate('2014-8-24', 'd.M.yyyy'));
    }

    public function testOneDigitIcu()
    {
        $formatter = new Formatter(['locale' => 'en-US']);
        $this->assertEquals('24.8.2014', $formatter->asDate('2014-8-24', 'php:d.n.Y'));
        $this->assertEquals('24.8.2014', $formatter->asDate('2014-8-24', 'd.M.yyyy'));
    }
}