|
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\Traits; |
|
13
|
|
|
|
|
14
|
|
|
use Doctrine\Common\EventManager; |
|
15
|
|
|
use Gedmo\Translatable\TranslatableListener; |
|
16
|
|
|
use Sonata\TranslationBundle\Test\DoctrineOrmTestCase; |
|
17
|
|
|
use Sonata\TranslationBundle\Tests\Fixtures\Traits\ORM\ArticlePersonalTranslatable; |
|
18
|
|
|
use Sonata\TranslationBundle\Tests\Fixtures\Traits\ORM\ArticlePersonalTranslation; |
|
19
|
|
|
|
|
20
|
|
|
class GedmoOrmTest extends DoctrineOrmTestCase |
|
21
|
|
|
{ |
|
22
|
|
|
const ARTICLE = 'Sonata\TranslationBundle\Tests\Fixtures\Traits\ORM\ArticlePersonalTranslatable'; |
|
23
|
|
|
const TRANSLATION = 'Sonata\TranslationBundle\Tests\Fixtures\Traits\ORM\ArticlePersonalTranslation'; |
|
24
|
|
|
|
|
25
|
|
|
/** @var TranslatableListener */ |
|
26
|
|
|
private $translatableListener; |
|
27
|
|
|
|
|
28
|
|
|
protected function setUp() |
|
29
|
|
|
{ |
|
30
|
|
|
parent::setUp(); |
|
31
|
|
|
|
|
32
|
|
|
if (!class_exists('Doctrine\\ORM\\Version')) { |
|
33
|
|
|
$this->markTestSkipped('Doctrine ORM is not available.'); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
$evm = new EventManager(); |
|
37
|
|
|
$this->translatableListener = new TranslatableListener(); |
|
38
|
|
|
$this->translatableListener->setTranslatableLocale('en'); |
|
39
|
|
|
$this->translatableListener->setDefaultLocale('en'); |
|
40
|
|
|
$evm->addEventSubscriber($this->translatableListener); |
|
41
|
|
|
|
|
42
|
|
|
$this->getMockSqliteEntityManager($evm); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function testPersonalTranslatableEntity() |
|
46
|
|
|
{ |
|
47
|
|
|
$article = new ArticlePersonalTranslatable(); |
|
48
|
|
|
$article->setTitle('en'); |
|
49
|
|
|
|
|
50
|
|
|
$this->em->persist($article); |
|
51
|
|
|
$this->em->flush(); |
|
52
|
|
|
|
|
53
|
|
|
$this->translatableListener->setTranslatableLocale('de'); |
|
54
|
|
|
$article->setTitle('de'); |
|
55
|
|
|
|
|
56
|
|
|
$ltTranslation = new ArticlePersonalTranslation(); |
|
57
|
|
|
$ltTranslation |
|
58
|
|
|
->setField('title') |
|
59
|
|
|
->setContent('lt') |
|
60
|
|
|
->setObject($article) |
|
|
|
|
|
|
61
|
|
|
->setLocale('lt') |
|
62
|
|
|
; |
|
63
|
|
|
$this->em->persist($ltTranslation); |
|
64
|
|
|
$this->em->persist($article); |
|
65
|
|
|
$this->em->flush(); |
|
66
|
|
|
|
|
67
|
|
|
// Tests if Gedmo\Locale annotation exists |
|
68
|
|
|
$article->setLocale('pl'); |
|
69
|
|
|
$article->setTitle('pl'); |
|
70
|
|
|
$this->em->persist($article); |
|
71
|
|
|
$this->em->flush(); |
|
72
|
|
|
|
|
73
|
|
|
$this->em->clear(); |
|
74
|
|
|
|
|
75
|
|
|
$article = $this->em->find(self::ARTICLE, array('id' => 1)); |
|
76
|
|
|
$translations = $article->getTranslations(); |
|
77
|
|
|
$this->assertCount(3, $translations); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
protected function getUsedEntityFixtures() |
|
81
|
|
|
{ |
|
82
|
|
|
return array( |
|
83
|
|
|
self::ARTICLE, |
|
84
|
|
|
self::TRANSLATION, |
|
85
|
|
|
); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: