forked from laravel/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTranslationTranslatorTest.php
More file actions
executable file
·79 lines (65 loc) · 4.67 KB
/
TranslationTranslatorTest.php
File metadata and controls
executable file
·79 lines (65 loc) · 4.67 KB
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
<?php
use Mockery as m;
class TranslationTranslatorTest extends PHPUnit_Framework_TestCase
{
public function tearDown()
{
m::close();
}
public function testHasMethodReturnsFalseWhenReturnedTranslationIsNull()
{
$t = $this->getMock('Illuminate\Translation\Translator', ['get'], [$this->getLoader(), 'en']);
$t->expects($this->once())->method('get')->with($this->equalTo('foo'), $this->equalTo([]), $this->equalTo('bar'))->will($this->returnValue('foo'));
$this->assertFalse($t->has('foo', 'bar'));
$t = $this->getMock('Illuminate\Translation\Translator', ['get'], [$this->getLoader(), 'en', 'sp']);
$t->expects($this->once())->method('get')->with($this->equalTo('foo'), $this->equalTo([]), $this->equalTo('bar'))->will($this->returnValue('bar'));
$this->assertTrue($t->has('foo', 'bar'));
$t = $this->getMock('Illuminate\Translation\Translator', ['get'], [$this->getLoader(), 'en']);
$t->expects($this->once())->method('get')->with($this->equalTo('foo'), $this->equalTo([]), $this->equalTo('bar'), false)->will($this->returnValue('bar'));
$this->assertTrue($t->hasForLocale('foo', 'bar'));
$t = $this->getMock('Illuminate\Translation\Translator', ['get'], [$this->getLoader(), 'en']);
$t->expects($this->once())->method('get')->with($this->equalTo('foo'), $this->equalTo([]), $this->equalTo('bar'), false)->will($this->returnValue('foo'));
$this->assertFalse($t->hasForLocale('foo', 'bar'));
$t = $this->getMock('Illuminate\Translation\Translator', ['load', 'getLine'], [$this->getLoader(), 'en']);
$t->expects($this->once())->method('load')->with($this->equalTo('*'), $this->equalTo('foo'), $this->equalTo('en'))->will($this->returnValue(null));
$t->expects($this->once())->method('getLine')->with($this->equalTo('*'), $this->equalTo('foo'), $this->equalTo('en'), null, $this->equalTo([]))->will($this->returnValue('bar'));
$this->assertTrue($t->hasForLocale('foo'));
$t = $this->getMock('Illuminate\Translation\Translator', ['load', 'getLine'], [$this->getLoader(), 'en']);
$t->expects($this->once())->method('load')->with($this->equalTo('*'), $this->equalTo('foo'), $this->equalTo('en'))->will($this->returnValue(null));
$t->expects($this->once())->method('getLine')->with($this->equalTo('*'), $this->equalTo('foo'), $this->equalTo('en'), null, $this->equalTo([]))->will($this->returnValue('foo'));
$this->assertFalse($t->hasForLocale('foo'));
}
public function testGetMethodProperlyLoadsAndRetrievesItem()
{
$t = $this->getMock('Illuminate\Translation\Translator', null, [$this->getLoader(), 'en']);
$t->getLoader()->shouldReceive('load')->once()->with('en', 'bar', 'foo')->andReturn(['foo' => 'foo', 'baz' => 'breeze :foo']);
$this->assertEquals('breeze bar', $t->get('foo::bar.baz', ['foo' => 'bar'], 'en'));
$this->assertEquals('foo', $t->get('foo::bar.foo'));
}
public function testGetMethodProperlyLoadsAndRetrievesItemWithLongestReplacementsFirst()
{
$t = $this->getMock('Illuminate\Translation\Translator', null, [$this->getLoader(), 'en']);
$t->getLoader()->shouldReceive('load')->once()->with('en', 'bar', 'foo')->andReturn(['foo' => 'foo', 'baz' => 'breeze :foo :foobar']);
$this->assertEquals('breeze bar taylor', $t->get('foo::bar.baz', ['foo' => 'bar', 'foobar' => 'taylor'], 'en'));
$this->assertEquals('breeze foo bar baz taylor', $t->get('foo::bar.baz', ['foo' => 'foo bar baz', 'foobar' => 'taylor'], 'en'));
$this->assertEquals('foo', $t->get('foo::bar.foo'));
}
public function testGetMethodProperlyLoadsAndRetrievesItemForGlobalNamespace()
{
$t = $this->getMock('Illuminate\Translation\Translator', null, [$this->getLoader(), 'en']);
$t->getLoader()->shouldReceive('load')->once()->with('en', 'foo', '*')->andReturn(['bar' => 'breeze :foo']);
$this->assertEquals('breeze bar', $t->get('foo.bar', ['foo' => 'bar']));
}
public function testChoiceMethodProperlyLoadsAndRetrievesItem()
{
$t = $this->getMock('Illuminate\Translation\Translator', ['get'], [$this->getLoader(), 'en']);
$t->expects($this->once())->method('get')->with($this->equalTo('foo'), $this->equalTo(['replace']), $this->equalTo('en'))->will($this->returnValue('line'));
$t->setSelector($selector = m::mock('Symfony\Component\Translation\MessageSelector'));
$selector->shouldReceive('choose')->once()->with('line', 10, 'en')->andReturn('choiced');
$t->choice('foo', 10, ['replace']);
}
protected function getLoader()
{
return m::mock('Illuminate\Translation\LoaderInterface');
}
}