1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Sonata Project package. |
7
|
|
|
* |
8
|
|
|
* (c) Thomas Rabaix <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Sonata\TranslationBundle\Tests\Model; |
15
|
|
|
|
16
|
|
|
use PHPUnit\Framework\TestCase; |
17
|
|
|
use Sonata\TranslationBundle\Model\Gedmo\TranslatableInterface; |
18
|
|
|
use Sonata\TranslationBundle\Tests\Fixtures\Model\ModelPersonalTranslatable; |
19
|
|
|
use Sonata\TranslationBundle\Tests\Fixtures\Model\ModelPersonalTranslation; |
20
|
|
|
use Sonata\TranslationBundle\Tests\Fixtures\Model\ModelTranslatable; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @author Nicolas Bastien <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
final class GedmoTest extends TestCase |
26
|
|
|
{ |
27
|
|
|
public function testTranslatableModel(): void |
28
|
|
|
{ |
29
|
|
|
$model = new ModelTranslatable(); |
30
|
|
|
$model->setLocale('fr'); |
31
|
|
|
|
32
|
|
|
$this->assertSame('fr', $model->getLocale()); |
33
|
|
|
$this->assertInstanceOf(TranslatableInterface::class, $model); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testPersonalTranslatableModel(): void |
37
|
|
|
{ |
38
|
|
|
$model = new ModelPersonalTranslatable(); |
39
|
|
|
$model->setLocale('fr'); |
40
|
|
|
|
41
|
|
|
$this->assertSame('fr', $model->getLocale()); |
42
|
|
|
$this->assertInstanceOf(TranslatableInterface::class, $model); |
43
|
|
|
|
44
|
|
|
$model->addTranslation(new ModelPersonalTranslation('en', 'title', 'Title en')); |
45
|
|
|
$model->addTranslation(new ModelPersonalTranslation('it', 'title', 'Title it')); |
46
|
|
|
$model->addTranslation(new ModelPersonalTranslation('es', 'title', 'Title es')); |
47
|
|
|
|
48
|
|
|
$this->assertSame('Title en', $model->getTranslation('title', 'en')); |
49
|
|
|
$this->assertSame('Title it', $model->getTranslation('title', 'it')); |
50
|
|
|
$this->assertSame('Title es', $model->getTranslation('title', 'es')); |
51
|
|
|
|
52
|
|
|
$this->assertCount(3, $model->getTranslations()); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|