This repository has been archived by the owner on Jan 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'fix/i18n-view-helper-translate-text-domain' of https://…
- Loading branch information
55 parents
2187ae2
+
6437ec0
+
e9b8476
+
95e54a0
+
7ea3aed
+
df6a706
+
a82fc82
+
7c2a059
+
4fefb53
+
599ee3a
+
ea3fc65
+
f6c04c2
+
6591e3d
+
a4f76e3
+
33c7531
+
2d59782
+
8152327
+
e56ce9b
+
db9b18f
+
b88635a
+
a262823
+
b79aef6
+
c2284e4
+
70193eb
+
96acf77
+
9675426
+
5f02411
+
0dafea7
+
15dc674
+
4a2447d
+
e6eb7f3
+
e9499c5
+
272b15f
+
11c7758
+
6f0e918
+
5f4980a
+
ecca95a
+
88b5971
+
ecb8d13
+
9de1c08
+
44aad17
+
13269e9
+
654cdb6
+
dc708db
+
380ffba
+
ff67e7f
+
fe2e025
+
95f0efa
+
68cc4b3
+
bf13b96
+
8870381
+
56480f4
+
1fa90d7
+
5c7fe1f
+
e803235
commit ef20fa1
Showing
4 changed files
with
206 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
* @package Zend_I18n | ||
*/ | ||
|
||
namespace ZendTest\I18n\View\Helper; | ||
|
||
use Zend\I18n\View\Helper\TranslatePlural as TranslatePluralHelper; | ||
|
||
/** | ||
* @category Zend | ||
* @package Zend_View | ||
* @subpackage UnitTests | ||
* @group Zend_View | ||
* @group Zend_View_Helper | ||
*/ | ||
class TranslatePluralTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var TranslatePluralHelper | ||
*/ | ||
public $helper; | ||
|
||
/** | ||
* Sets up the fixture, for example, open a network connection. | ||
* This method is called before a test is executed. | ||
* | ||
* @return void | ||
*/ | ||
public function setUp() | ||
{ | ||
$this->helper = new TranslatePluralHelper(); | ||
} | ||
|
||
/** | ||
* Tears down the fixture, for example, close a network connection. | ||
* This method is called after a test is executed. | ||
* | ||
* @return void | ||
*/ | ||
public function tearDown() | ||
{ | ||
unset($this->helper); | ||
} | ||
|
||
public function testInvokingWithoutTranslatorWillRaiseException() | ||
{ | ||
$this->setExpectedException('Zend\I18n\Exception\RuntimeException'); | ||
$this->helper->__invoke('singular', 'plural', 1); | ||
} | ||
|
||
public function testDefaultInvokeArguments() | ||
{ | ||
$singularInput = 'singular'; | ||
$pluralInput = 'plural'; | ||
$numberInput = 1; | ||
$expected = 'translated'; | ||
|
||
$translatorMock = $this->getMock('Zend\I18n\Translator\Translator'); | ||
$translatorMock->expects($this->once()) | ||
->method('translatePlural') | ||
->with( | ||
$this->equalTo($singularInput), | ||
$this->equalTo($pluralInput), | ||
$this->equalTo($numberInput), | ||
$this->equalTo('default'), | ||
$this->equalTo(null) | ||
) | ||
->will($this->returnValue($expected)); | ||
|
||
$this->helper->setTranslator($translatorMock); | ||
|
||
$this->assertEquals($expected, $this->helper->__invoke($singularInput, $pluralInput, $numberInput)); | ||
} | ||
|
||
public function testCustomInvokeArguments() | ||
{ | ||
$singularInput = 'singular'; | ||
$pluralInput = 'plural'; | ||
$numberInput = 1; | ||
$expected = 'translated'; | ||
$textDomain = 'textDomain'; | ||
$locale = 'en_US'; | ||
|
||
$translatorMock = $this->getMock('Zend\I18n\Translator\Translator'); | ||
$translatorMock->expects($this->once()) | ||
->method('translatePlural') | ||
->with( | ||
$this->equalTo($singularInput), | ||
$this->equalTo($pluralInput), | ||
$this->equalTo($numberInput), | ||
$this->equalTo($textDomain), | ||
$this->equalTo($locale) | ||
) | ||
->will($this->returnValue($expected)); | ||
|
||
$this->helper->setTranslator($translatorMock); | ||
|
||
$this->assertEquals($expected, $this->helper->__invoke( | ||
$singularInput, $pluralInput, $numberInput, $textDomain, $locale | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
* @package Zend_I18n | ||
*/ | ||
|
||
namespace ZendTest\I18n\View\Helper; | ||
|
||
use Zend\I18n\View\Helper\Translate as TranslateHelper; | ||
|
||
/** | ||
* @category Zend | ||
* @package Zend_View | ||
* @subpackage UnitTests | ||
* @group Zend_View | ||
* @group Zend_View_Helper | ||
*/ | ||
class TranslateTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var TranslateHelper | ||
*/ | ||
public $helper; | ||
|
||
/** | ||
* Sets up the fixture, for example, open a network connection. | ||
* This method is called before a test is executed. | ||
* | ||
* @return void | ||
*/ | ||
public function setUp() | ||
{ | ||
$this->helper = new TranslateHelper(); | ||
} | ||
|
||
/** | ||
* Tears down the fixture, for example, close a network connection. | ||
* This method is called after a test is executed. | ||
* | ||
* @return void | ||
*/ | ||
public function tearDown() | ||
{ | ||
unset($this->helper); | ||
} | ||
|
||
public function testInvokingWithoutTranslatorWillRaiseException() | ||
{ | ||
$this->setExpectedException('Zend\I18n\Exception\RuntimeException'); | ||
$this->helper->__invoke('message'); | ||
} | ||
|
||
public function testDefaultInvokeArguments() | ||
{ | ||
$input = 'input'; | ||
$expected = 'translated'; | ||
|
||
$translatorMock = $this->getMock('Zend\I18n\Translator\Translator'); | ||
$translatorMock->expects($this->once()) | ||
->method('translate') | ||
->with($this->equalTo($input), $this->equalTo('default'), $this->equalTo(null)) | ||
->will($this->returnValue($expected)); | ||
|
||
$this->helper->setTranslator($translatorMock); | ||
|
||
$this->assertEquals($expected, $this->helper->__invoke($input)); | ||
} | ||
|
||
public function testCustomInvokeArguments() | ||
{ | ||
$input = 'input'; | ||
$expected = 'translated'; | ||
$textDomain = 'textDomain'; | ||
$locale = 'en_US'; | ||
|
||
$translatorMock = $this->getMock('Zend\I18n\Translator\Translator'); | ||
$translatorMock->expects($this->once()) | ||
->method('translate') | ||
->with($this->equalTo($input), $this->equalTo($textDomain), $this->equalTo($locale)) | ||
->will($this->returnValue($expected)); | ||
|
||
$this->helper->setTranslator($translatorMock); | ||
|
||
$this->assertEquals($expected, $this->helper->__invoke($input, $textDomain, $locale)); | ||
} | ||
} |