8
0
daux.io/tests/Format/Template/TranslateTest.php

99 Zeilen
2.6 KiB
PHP

<?php
namespace Todaymade\Daux\Format\Template;
use org\bovigo\vfs\vfsStream;
2020-04-22 22:24:52 +02:00
use PHPUnit\Framework\TestCase;
use Todaymade\Daux\Config;
use Todaymade\Daux\ConfigBuilder;
use Todaymade\Daux\DauxHelper;
use Todaymade\Daux\Format\HTML\Template;
use Todaymade\Daux\Tree\Builder;
use Todaymade\Daux\Tree\Entry;
use Todaymade\Daux\Tree\Root;
/**
2020-04-22 22:24:52 +02:00
* Class TranslateTest.
*/
class TranslateTest extends TestCase
{
protected function getTree(Config $config)
{
$structure = [
'en' => [
'Page.md' => 'some text content',
],
'it' => [
'Page.md' => 'another page',
],
];
$root = vfsStream::setup('root', null, $structure);
$config = ConfigBuilder::withMode()
->withDocumentationDirectory($root->url())
->withValidContentExtensions(['md'])
->build();
$tree = new Root($config);
Builder::build($tree, []);
return $tree;
}
public function translateDataProvider()
{
return [
['Previous', 'en'],
['Pagina precedente', 'it'],
];
}
/**
* @dataProvider translateDataProvider
*
* @param $expectedTranslation
* @param $language
*/
public function testTranslate($expectedTranslation, $language)
{
$current = $language . '/Page.html';
$entry = $this->prophesize(Entry::class);
$config = new Config();
$config->setTree($this->getTree($config));
$config->merge([
'title' => '',
'index' => $entry->reveal(),
'language' => $language,
'base_url' => '',
'templates' => '',
'page' => [
'language' => $language,
],
'html' => [
2020-04-22 22:24:52 +02:00
'search' => '',
'toggle_code' => false,
'piwik_analytics' => '',
'google_analytics' => '',
],
'theme' => [
2020-04-22 22:24:52 +02:00
'js' => [''],
'css' => [''],
'fonts' => [''],
'favicon' => '',
'templates' => 'name',
],
'strings' => [
2020-04-22 22:24:52 +02:00
'en' => ['Link_previous' => 'Previous'],
'it' => ['Link_previous' => 'Pagina precedente'],
],
]);
$config->setCurrentPage(DauxHelper::getFile($config->getTree(), $current));
$template = new Template($config);
$value = $template->getEngine($config)->getFunction('translate')->call(null, ['Link_previous']);
$this->assertEquals($expectedTranslation, $value);
}
}