1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sonata Project package. |
5
|
|
|
* |
6
|
|
|
* (c) Thomas Rabaix <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sonata\TranslationBundle\Tests\Model; |
13
|
|
|
|
14
|
|
|
use Sonata\TranslationBundle\Model\Gedmo\AbstractPersonalTranslatable; |
15
|
|
|
use Sonata\TranslationBundle\Model\Gedmo\AbstractPersonalTranslation; |
16
|
|
|
use Sonata\TranslationBundle\Model\Gedmo\AbstractTranslatable; |
17
|
|
|
use Sonata\TranslationBundle\Model\Gedmo\TranslatableInterface; |
18
|
|
|
|
19
|
|
|
class ModelTranslatable extends AbstractTranslatable implements TranslatableInterface |
20
|
|
|
{ |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
class ModelPersonalTranslatable extends AbstractPersonalTranslatable implements TranslatableInterface |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
class ModelPersonalTranslation extends AbstractPersonalTranslation |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @author Nicolas Bastien <[email protected]> |
33
|
|
|
*/ |
34
|
|
View Code Duplication |
class GedmoTest extends \PHPUnit_Framework_TestCase |
|
|
|
|
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* @test AbstractTranslatable |
38
|
|
|
*/ |
39
|
|
|
public function testTranslatableModel() |
40
|
|
|
{ |
41
|
|
|
$model = new ModelTranslatable(); |
42
|
|
|
$model->setLocale('fr'); |
43
|
|
|
|
44
|
|
|
$this->assertSame('fr', $model->getLocale()); |
45
|
|
|
$this->assertTrue($model instanceof \Sonata\TranslationBundle\Model\TranslatableInterface); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @test AbstractPersonalTranslatable and AbstractPersonalTranslation |
50
|
|
|
*/ |
51
|
|
|
public function testPersonalTranslatableModel() |
52
|
|
|
{ |
53
|
|
|
$model = new ModelPersonalTranslatable(); |
54
|
|
|
$model->setLocale('fr'); |
55
|
|
|
|
56
|
|
|
$this->assertSame('fr', $model->getLocale()); |
57
|
|
|
$this->assertTrue($model instanceof \Sonata\TranslationBundle\Model\TranslatableInterface); |
58
|
|
|
|
59
|
|
|
$model->addTranslation(new ModelPersonalTranslation('en', 'title', 'Title en')); |
60
|
|
|
$model->addTranslation(new ModelPersonalTranslation('it', 'title', 'Title it')); |
61
|
|
|
$model->addTranslation(new ModelPersonalTranslation('es', 'title', 'Title es')); |
62
|
|
|
|
63
|
|
|
$this->assertSame('Title en', $model->getTranslation('title', 'en')); |
64
|
|
|
$this->assertSame('Title it', $model->getTranslation('title', 'it')); |
65
|
|
|
$this->assertSame('Title es', $model->getTranslation('title', 'es')); |
66
|
|
|
|
67
|
|
|
$this->assertSame(3, count($model->getTranslations())); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.