Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
fprochazka committed May 15, 2017
1 parent 619dfc9 commit 56732f9
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions tests/KdybyTests/Translation/TranslateMacros.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,34 @@ class ControlMock extends Nette\Application\UI\Control
class TranslateMacrosTest extends TestCase
{

/** @var Kdyby\Translation\Translator */
private $translator;

/** @var \Nette\Bridges\ApplicationLatte\Template */
private $template;



protected function setUp()
{
parent::setUp();

$container = $this->createContainer();

/** @var Kdyby\Translation\Translator $translator */
$this->translator = $container->getByType('Nette\Localization\ITranslator');
$this->translator->setFallbackLocales(['cs_CZ', 'cs']);
$this->translator->setLocale('cs');

$this->template = $container->getByType('Nette\Application\UI\ITemplateFactory')
->createTemplate(new ControlMock());
}



public function testRender_translate()
{
$template = $this->buildTemplate();
$this->template->setFile(__DIR__ . '/files/Homepage.default.latte');

Assert::same('Ahoj %name%
Ahoj Peter
Expand All @@ -53,14 +78,14 @@ Hello Peter|Helloes Peter
front.missingKey.namedHelloCounting
front.missingKey.namedHelloCounting
front.missingKey.namedHelloCounting' . "\n", (string) $template->setFile(__DIR__ . '/files/Homepage.default.latte'));
front.missingKey.namedHelloCounting' . "\n", $this->template->__toString());
}



public function testRender_translate_noescape()
{
$template = $this->buildTemplate();
$this->template->setFile(__DIR__ . '/files/Article.noescape.latte');

Assert::same('Ahoj <b>%name%</b>
Ahoj <b>Peter</b>
Expand Down Expand Up @@ -102,14 +127,14 @@ Hello <i>Peter</i>|Helloes <i>Peter</i>
front.missingKey.namedHelloCounting
front.missingKey.namedHelloCounting
front.missingKey.namedHelloCounting' . "\n", (string) $template->setFile(__DIR__ . '/files/Article.noescape.latte'));
front.missingKey.namedHelloCounting' . "\n", $this->template->__toString());
}



public function testRender_translate_prefixed()
{
$template = $this->buildTemplate();
$this->template->setFile(__DIR__ . '/files/Order.default.latte');

Assert::match('
Ahoj %name%
Expand All @@ -133,24 +158,7 @@ Hello Peter|Helloes Peter
%A?%
front.missingKey.namedHelloCounting
front.missingKey.namedHelloCounting
front.missingKey.namedHelloCounting' . "\n", (string) $template->setFile(__DIR__ . '/files/Order.default.latte'));
}



/**
* @return \Nette\Bridges\ApplicationLatte\Template
*/
private function buildTemplate()
{
$container = $this->createContainer();

/** @var Kdyby\Translation\Translator $translator */
$translator = $container->getByType('Nette\Localization\ITranslator');
$translator->setFallbackLocales(['cs_CZ', 'cs']);
$translator->setLocale('cs');

return $container->getByType('Nette\Application\UI\ITemplateFactory')->createTemplate(new ControlMock());
front.missingKey.namedHelloCounting' . "\n", $this->template->__toString());
}

}
Expand Down

0 comments on commit 56732f9

Please sign in to comment.