Skip to content

Commit 23bbc42

Browse files
authored
Test local translations (#139)
1 parent dc4fb16 commit 23bbc42

File tree

4 files changed

+101
-0
lines changed

4 files changed

+101
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
/*
4+
* Symfony DataTables Bundle
5+
* (c) Omines Internetbureau B.V. - https://omines.nl/
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
declare(strict_types=1);
12+
13+
namespace Tests\Fixtures\AppBundle\Controller;
14+
15+
use Omines\DataTablesBundle\Adapter\ArrayAdapter;
16+
use Omines\DataTablesBundle\Column\TextColumn;
17+
use Omines\DataTablesBundle\DataTableFactory;
18+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
19+
use Symfony\Component\HttpFoundation\Request;
20+
21+
/**
22+
* TranslationController.
23+
*/
24+
class TranslationController extends AbstractController
25+
{
26+
public function tableAction(Request $request, DataTableFactory $dataTableFactory)
27+
{
28+
$datatable = $dataTableFactory->create();
29+
$datatable
30+
->setName('noCDN')
31+
->setMethod(Request::METHOD_GET)
32+
->setLanguageFromCDN(false)
33+
->add('col3', TextColumn::class, ['label' => 'foo', 'field' => 'bar'])
34+
->add('col4', TextColumn::class, ['label' => 'bar', 'field' => 'foo'])
35+
->createAdapter(ArrayAdapter::class)
36+
;
37+
38+
if ($datatable->handleRequest($request)->isCallback()) {
39+
return $datatable->getResponse();
40+
}
41+
42+
return $this->render('@App/table.html.twig', [
43+
'datatable' => $datatable,
44+
]);
45+
}
46+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<title>Testpage</title>
5+
</head>
6+
<body>
7+
<h2>Table</h2>
8+
<div id="table"></div>
9+
10+
<script src="bundles/datatables/js/datatables.js"></script>
11+
<script>
12+
$(function() {
13+
$('#table').initDataTables({{ datatable_settings(datatable) }}, {
14+
searching: true,
15+
dom:'<"html5buttons"B>lTfgitp',
16+
buttons: [
17+
'copy',
18+
'csv',
19+
{ extend: 'excel', title: 'domains'},
20+
{ extend: 'pdf', title: 'domains'},
21+
{ extend: 'print' }
22+
]
23+
});
24+
});
25+
</script>
26+
</body>
27+
</html>

tests/Fixtures/routing.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ grouped2:
2929
employee.edit:
3030
path: /employee/{id}
3131

32+
translation:
33+
path: /{_locale}/translation
34+
controller: Tests\Fixtures\AppBundle\Controller\TranslationController::tableAction
35+
3236
orm_adapter_events.pre_query:
3337
path: /orm-adapter-events/pre-query
3438
controller: Tests\Fixtures\AppBundle\Controller\ORMAdapterEventsController::preQueryAction

tests/Functional/FunctionalTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,30 @@ public function testGrouped2DataTable()
123123
$this->assertStringStartsWith('Company ', $json->data[0]->company);
124124
}
125125

126+
/**
127+
* @dataProvider translationProvider
128+
*/
129+
public function testTranslation(string $locale, string $languageProcessing, string $languageInfoFiltered)
130+
{
131+
$this->client->enableProfiler();
132+
$crawler = $this->client->request('GET', sprintf('/%s/translation', $locale));
133+
$this->assertSuccessful($response = $this->client->getResponse());
134+
135+
$content = $response->getContent();
136+
$this->assertNotContains('"options":{"language":{"url"', $content);
137+
$this->assertContains(sprintf('"processing":"%s"', $languageProcessing), $content);
138+
$this->assertContains(sprintf('"infoFiltered":"%s"', $languageInfoFiltered), $content);
139+
}
140+
141+
public function translationProvider(): array
142+
{
143+
return [
144+
['en', 'Processing...', '(filtered from _MAX_ total entries)'],
145+
['de', 'Bitte warten...', ' (gefiltert von _MAX_ Eintr\u00e4gen)'],
146+
['fr', 'Traitement en cours...', '(filtr&eacute; de _MAX_ &eacute;l&eacute;ments au total)'],
147+
];
148+
}
149+
126150
private function callDataTableUrl(string $url)
127151
{
128152
$this->client->enableProfiler();

0 commit comments

Comments
 (0)