-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from imponeer/tests-and-some-updated-dependencies
Added tests & imponeer/smarty-extensions-contracts updated to 3.0
- Loading branch information
Showing
7 changed files
with
297 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/vendor/ | ||
/composer.lock | ||
.idea/ | ||
.idea/ | ||
/.phpunit.result.cache |
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,8 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<phpunit bootstrap="./vendor/autoload.php"> | ||
<testsuites> | ||
<testsuite name="Main tests"> | ||
<directory>./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
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,134 @@ | ||
<?php | ||
|
||
use Imponeer\Smarty\Extensions\Translate\TransBlock; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Translation\Loader\ArrayLoader; | ||
use Symfony\Component\Translation\Translator; | ||
class TransBlockTest extends TestCase | ||
{ | ||
|
||
/** | ||
* @var Translator | ||
*/ | ||
private $translator; | ||
/** | ||
* @var TransBlock | ||
*/ | ||
private $plugin; | ||
/** | ||
* @var Smarty | ||
*/ | ||
private $smarty; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->translator = new Translator('en'); | ||
$this->translator->addLoader( | ||
"array", | ||
new ArrayLoader() | ||
); | ||
$this->translator->addResource('array', [ | ||
'test' => 'TEST', | ||
], 'en', 'default'); | ||
$this->translator->addResource('array', [ | ||
'test2' => 'TEST2', | ||
], 'en'); | ||
$this->translator->addResource('array', [ | ||
'test3' => 'TEST3 {value}', | ||
], 'en'); | ||
$this->translator->addResource('array', [ | ||
'test4' => 'TEST4 {value}', | ||
], 'en', 'default'); | ||
$this->translator->addResource('array', [ | ||
'test4' => 'TEST4[X] {value}', | ||
], 'lt', 'default'); | ||
|
||
|
||
$this->plugin = new TransBlock($this->translator); | ||
|
||
$this->smarty = new Smarty(); | ||
$this->smarty->caching = Smarty::CACHING_OFF; | ||
$this->smarty->registerPlugin( | ||
'block', | ||
$this->plugin->getName(), | ||
[$this->plugin, 'execute'] | ||
); | ||
|
||
parent::setUp(); | ||
} | ||
|
||
public function testGetName() { | ||
$this->assertSame('trans', $this->plugin->getName()); | ||
} | ||
|
||
public function testInvokeWithCorrectDomain() { | ||
$src = urlencode('{trans domain="default"}test{/trans}'); | ||
$ret = $this->smarty->fetch('eval:urlencode:'.$src); | ||
$this->assertSame( | ||
$this->translator->trans('test', [], 'default'), | ||
$ret | ||
); | ||
} | ||
|
||
public function testInvokeWithoutDomain() { | ||
$src = urlencode('{trans}test2{/trans}'); | ||
$ret = $this->smarty->fetch('eval:urlencode:'.$src); | ||
$this->assertSame( | ||
$this->translator->trans('test2'), | ||
$ret | ||
); | ||
} | ||
|
||
public function testInvokeWithCorrectParameters() { | ||
$src = urlencode('{trans parameters=["value" => "xx"]}test3{/trans}'); | ||
$ret = $this->smarty->fetch('eval:urlencode:'.$src); | ||
$this->assertSame( | ||
$this->translator->trans('test3', ['value' => 'xx']), | ||
$ret | ||
); | ||
} | ||
|
||
public function testInvokeWithDomainAndCorrectParameters() { | ||
$src = urlencode('{trans domain="default" parameters=["value" => "xx"]}test4{/trans}'); | ||
$ret = $this->smarty->fetch('eval:urlencode:'.$src); | ||
$this->assertSame( | ||
$this->translator->trans('test4', ['value' => 'xx'], 'default'), | ||
$ret | ||
); | ||
} | ||
|
||
public function testInvokeWithDomainLocaleAndCorrectParameters() { | ||
$src = urlencode('{trans locale="lt" domain="default" parameters=["value" => "xx"]}test4{/trans}'); | ||
$ret = $this->smarty->fetch('eval:urlencode:'.$src); | ||
$this->assertSame( | ||
$this->translator->trans('test4', ['value' => 'xx'], 'default', 'lt'), | ||
$ret | ||
); | ||
} | ||
|
||
public function testInvokeWithNotCorrectDomain() { | ||
$src = urlencode('{trans domain="default2" parameters=["value" => "xx"]}test4{/trans}'); | ||
$ret = $this->smarty->fetch('eval:urlencode:'.$src); | ||
$this->assertSame("test4", $ret); | ||
$this->assertSame( | ||
$this->translator->trans('test4', ['value' => 'xx'], 'default2'), | ||
$ret | ||
); | ||
} | ||
|
||
public function testInvokeWithNotCorrectParameters() { | ||
$src = urlencode('{trans domain="default" parameters=["valueX" => "xx"]}test4{/trans}'); | ||
$ret = $this->smarty->fetch('eval:urlencode:'.$src); | ||
$this->assertSame( | ||
$this->translator->trans('test4', ['valueX' => 'xx'], 'default'), | ||
$ret | ||
); | ||
} | ||
|
||
public function testInvokeWithNotCorrectLocale() { | ||
$src = urlencode('{trans domain="default" locale="be" parameters=["valueX" => "xx"]}test4{/trans}'); | ||
$ret = $this->smarty->fetch('eval:urlencode:'.$src); | ||
$this->assertSame("test4", $ret); | ||
} | ||
|
||
} |
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,138 @@ | ||
<?php | ||
|
||
use Imponeer\Smarty\Extensions\Translate\TransVarModifier; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Translation\Loader\ArrayLoader; | ||
use Symfony\Component\Translation\Translator; | ||
|
||
class TransVarModifierTest extends TestCase | ||
{ | ||
|
||
/** | ||
* @var Translator | ||
*/ | ||
private $translator; | ||
/** | ||
* @var TransVarModifier | ||
*/ | ||
private $plugin; | ||
/** | ||
* @var Smarty | ||
*/ | ||
private $smarty; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->translator = new Translator('en'); | ||
$this->translator->addLoader( | ||
"array", | ||
new ArrayLoader() | ||
); | ||
$this->translator->addResource('array', [ | ||
'test' => 'TEST', | ||
], 'en', 'default'); | ||
$this->translator->addResource('array', [ | ||
'test2' => 'TEST2', | ||
], 'en'); | ||
$this->translator->addResource('array', [ | ||
'test3' => 'TEST3 {value}', | ||
], 'en'); | ||
$this->translator->addResource('array', [ | ||
'test4' => 'TEST4 {value}', | ||
], 'en', 'default'); | ||
$this->translator->addResource('array', [ | ||
'test4' => 'TEST4[X] {value}', | ||
], 'lt', 'default'); | ||
|
||
|
||
$this->plugin = new TransVarModifier($this->translator); | ||
|
||
$this->smarty = new Smarty(); | ||
$this->smarty->caching = Smarty::CACHING_OFF; | ||
$this->smarty->registerPlugin( | ||
'modifier', | ||
$this->plugin->getName(), | ||
[$this->plugin, 'execute'] | ||
); | ||
|
||
parent::setUp(); | ||
} | ||
|
||
public function testGetName() { | ||
$this->assertSame('trans', $this->plugin->getName()); | ||
} | ||
|
||
public function testInvokeWithCorrectDomain() { | ||
$src = urlencode('{"test"|trans:[]:"default"}'); | ||
$ret = $this->smarty->fetch('eval:urlencode:'.$src); | ||
$this->assertSame( | ||
$this->translator->trans('test', [], 'default'), | ||
$ret | ||
); | ||
} | ||
|
||
public function testInvokeWithoutDomain() { | ||
$src = urlencode('{"test2"|trans}'); | ||
$ret = $this->smarty->fetch('eval:urlencode:'.$src); | ||
$this->assertSame( | ||
$this->translator->trans('test2'), | ||
$ret | ||
); | ||
} | ||
|
||
public function testInvokeWithCorrectParameters() { | ||
$src = urlencode('{"test3"|trans:["value" => "xx"]}'); | ||
$ret = $this->smarty->fetch('eval:urlencode:'.$src); | ||
$this->assertSame( | ||
$this->translator->trans('test3', ['value' => 'xx']), | ||
$ret | ||
); | ||
} | ||
|
||
public function testInvokeWithDomainAndCorrectParameters() { | ||
$src = urlencode('{"test4"|trans:["value" => "xx"]:"default"}'); | ||
$ret = $this->smarty->fetch('eval:urlencode:'.$src); | ||
$this->assertSame( | ||
$this->translator->trans('test4', ['value' => 'xx'], 'default'), | ||
$ret | ||
); | ||
} | ||
|
||
public function testInvokeWithDomainLocaleAndCorrectParameters() { | ||
$src = urlencode('{"test4"|trans:["value" => "xx"]:"default":"lt"}'); | ||
$ret = $this->smarty->fetch('eval:urlencode:'.$src); | ||
$this->assertSame( | ||
$this->translator->trans('test4', ['value' => 'xx'], 'default', 'lt'), | ||
$ret | ||
); | ||
} | ||
|
||
public function testInvokeWithNotCorrectDomain() { | ||
$src = urlencode('{"test4"|trans:["value" => "xx"]:"default2"}'); | ||
$ret = $this->smarty->fetch('eval:urlencode:'.$src); | ||
$this->assertSame("test4", $ret); | ||
$this->assertSame( | ||
$this->translator->trans('test4', ['value' => 'xx'], 'default2'), | ||
$ret | ||
); | ||
} | ||
|
||
public function testInvokeWithNotCorrectParameters() { | ||
$src = urlencode('{"test4"|trans:["valueX" => "xx"]:"default"}'); | ||
$ret = $this->smarty->fetch('eval:urlencode:'.$src); | ||
$this->assertSame( | ||
$this->translator->trans('test4', ['valueX' => 'xx'], 'default'), | ||
$ret | ||
); | ||
} | ||
|
||
public function testInvokeWithNotCorrectLocale() { | ||
$src = urlencode('{"test4"|trans:["valueX" => "xx"]:"default":"be"}'); | ||
$ret = $this->smarty->fetch('eval:urlencode:'.$src); | ||
$this->assertSame( | ||
$this->translator->trans('test4', ['value' => 'xx'], 'default', 'be'), | ||
$ret | ||
); | ||
} | ||
|
||
} |