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
·68 lines (50 loc) · 2.83 KB
/
TranslationTranslatorTest.php
File metadata and controls
executable file
·68 lines (50 loc) · 2.83 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
<?php
use Mockery as m;
use Illuminate\Translation\Translator;
class TranslationTranslatorTest extends PHPUnit_Framework_TestCase {
public function tearDown()
{
m::close();
}
public function testHasMethodReturnsFalseWhenReturnedTranslationIsNull()
{
$t = $this->getMock('Illuminate\Translation\Translator', array('get'), array($this->getLoader(), 'en'));
$t->expects($this->once())->method('get')->with($this->equalTo('foo'), $this->equalTo(array()), $this->equalTo('bar'))->will($this->returnValue('foo'));
$this->assertFalse($t->has('foo', 'bar'));
$t = $this->getMock('Illuminate\Translation\Translator', array('get'), array($this->getLoader(), 'en', 'sp'));
$t->expects($this->once())->method('get')->with($this->equalTo('foo'), $this->equalTo(array()), $this->equalTo('bar'))->will($this->returnValue('bar'));
$this->assertTrue($t->has('foo', 'bar'));
}
public function testGetMethodProperlyLoadsAndRetrievesItem()
{
$t = $this->getMock('Illuminate\Translation\Translator', null, array($this->getLoader(), 'en'));
$t->getLoader()->shouldReceive('load')->once()->with('en', 'bar', 'foo')->andReturn(array('foo' => 'foo', 'baz' => 'breeze :foo'));
$this->assertEquals('breeze bar', $t->get('foo::bar.baz', array('foo' => 'bar'), 'en'));
$this->assertEquals('foo', $t->get('foo::bar.foo'));
}
public function testGetMethodProperlyLoadsAndRetrievesItemWithLongestReplacementsFirst()
{
$t = $this->getMock('Illuminate\Translation\Translator', null, array($this->getLoader(), 'en'));
$t->getLoader()->shouldReceive('load')->once()->with('en', 'bar', 'foo')->andReturn(array('foo' => 'foo', 'baz' => 'breeze :foo :foobar'));
$this->assertEquals('breeze bar taylor', $t->get('foo::bar.baz', array('foo' => 'bar', 'foobar' => 'taylor'), 'en'));
$this->assertEquals('foo', $t->get('foo::bar.foo'));
}
public function testGetMethodProperlyLoadsAndRetrievesItemForGlobalNamespace()
{
$t = $this->getMock('Illuminate\Translation\Translator', null, array($this->getLoader(), 'en'));
$t->getLoader()->shouldReceive('load')->once()->with('en', 'foo', '*')->andReturn(array('bar' => 'breeze :foo'));
$this->assertEquals('breeze bar', $t->get('foo.bar', array('foo' => 'bar')));
}
public function testChoiceMethodProperlyLoadsAndRetrievesItem()
{
$t = $this->getMock('Illuminate\Translation\Translator', array('get'), array($this->getLoader(), 'en'));
$t->expects($this->once())->method('get')->with($this->equalTo('foo'), $this->equalTo(array('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, array('replace'));
}
protected function getLoader()
{
return m::mock('Illuminate\Translation\LoaderInterface');
}
}