/var/www/hkosl.com/b2b2c/webadmin/libraies/symfony/translation/Tests/IdentityTranslatorTest.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Translation\Tests;

use 
Symfony\Component\Intl\Util\IntlTestHelper;
use 
Symfony\Component\Translation\IdentityTranslator;

class 
IdentityTranslatorTest extends \PHPUnit_Framework_TestCase
{
    
/**
     * @dataProvider getTransTests
     */
    
public function testTrans($expected$id$parameters)
    {
        
$translator = new IdentityTranslator();

        
$this->assertEquals($expected$translator->trans($id$parameters));
    }

    
/**
     * @dataProvider getTransChoiceTests
     */
    
public function testTransChoiceWithExplicitLocale($expected$id$number$parameters)
    {
        
$translator = new IdentityTranslator();
        
$translator->setLocale('en');

        
$this->assertEquals($expected$translator->transChoice($id$number$parameters));
    }

    
/**
     * @dataProvider getTransChoiceTests
     */
    
public function testTransChoiceWithDefaultLocale($expected$id$number$parameters)
    {
        \
Locale::setDefault('en');

        
$translator = new IdentityTranslator();

        
$this->assertEquals($expected$translator->transChoice($id$number$parameters));
    }

    public function 
testGetSetLocale()
    {
        
$translator = new IdentityTranslator();
        
$translator->setLocale('en');

        
$this->assertEquals('en'$translator->getLocale());
    }

    public function 
testGetLocaleReturnsDefaultLocaleIfNotSet()
    {
        
// in order to test with "pt_BR"
        
IntlTestHelper::requireFullIntl($thisfalse);

        
$translator = new IdentityTranslator();

        \
Locale::setDefault('en');
        
$this->assertEquals('en'$translator->getLocale());

        \
Locale::setDefault('pt_BR');
        
$this->assertEquals('pt_BR'$translator->getLocale());
    }

    public function 
getTransTests()
    {
        return array(
            array(
'Symfony is great!''Symfony is great!', array()),
            array(
'Symfony is awesome!''Symfony is %what%!', array('%what%' => 'awesome')),
        );
    }

    public function 
getTransChoiceTests()
    {
        return array(
            array(
'There are no apples''{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples'0, array('%count%' => 0)),
            array(
'There is one apple''{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples'1, array('%count%' => 1)),
            array(
'There are 10 apples''{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples'10, array('%count%' => 10)),
            array(
'There are 0 apples''There is 1 apple|There are %count% apples'0, array('%count%' => 0)),
            array(
'There is 1 apple''There is 1 apple|There are %count% apples'1, array('%count%' => 1)),
            array(
'There are 10 apples''There is 1 apple|There are %count% apples'10, array('%count%' => 10)),
            
// custom validation messages may be coded with a fixed value
            
array('There are 2 apples''There are 2 apples'2, array('%count%' => 2)),
        );
    }
}