-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMappedSuperclassWithTranslationsTest.php
More file actions
89 lines (69 loc) · 3.8 KB
/
MappedSuperclassWithTranslationsTest.php
File metadata and controls
89 lines (69 loc) · 3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
namespace Webfactory\Bundle\PolyglotBundle\Tests\Functional;
use Doctrine\ORM\Tools\ResolveTargetEntityListener;
use Webfactory\Bundle\PolyglotBundle\Tests\Fixtures\Entity\EntityInheritance\EntityInheritance_MappedSuperclassTranslation;
use Webfactory\Bundle\PolyglotBundle\Tests\Fixtures\Entity\EntityInheritance\EntityInheritance_MappedSuperclassWithTranslations;
use Webfactory\Bundle\PolyglotBundle\Tests\Fixtures\Entity\EntityInheritance\EntityInheritance_MappedSuperclassWithTranslations_Entity;
use Webfactory\Bundle\PolyglotBundle\Tests\Fixtures\Entity\EntityInheritance\EntityInheritance_MappedSuperclassWithTranslationsInterface;
use Webfactory\Bundle\PolyglotBundle\Translatable;
class MappedSuperclassWithTranslationsTest extends DatabaseFunctionalTestCase
{
protected function setUp(): void
{
parent::setUp();
$resolveTargetEntity = new ResolveTargetEntityListener();
$resolveTargetEntity->addResolveTargetEntity(
EntityInheritance_MappedSuperclassWithTranslationsInterface::class,
EntityInheritance_MappedSuperclassWithTranslations_Entity::class,
[]
);
$this->entityManager->getEventManager()->addEventSubscriber($resolveTargetEntity);
self::setupSchema([
EntityInheritance_MappedSuperclassWithTranslations::class,
EntityInheritance_MappedSuperclassWithTranslations_Entity::class,
EntityInheritance_MappedSuperclassTranslation::class,
]);
}
public function testPersistAndReloadEntity(): void
{
$entity = new EntityInheritance_MappedSuperclassWithTranslations_Entity();
$t = new Translatable('base text');
$t->setTranslation('Basistext', 'de_DE');
$entity->setText($t);
self::import([$entity]);
$loaded = $this->entityManager->find(EntityInheritance_MappedSuperclassWithTranslations_Entity::class, $entity->getId());
self::assertSame('base text', $loaded->getText()->translate('en_GB'));
self::assertSame('Basistext', $loaded->getText()->translate('de_DE'));
}
public function testAddTranslation(): void
{
$entityManager = $this->entityManager;
$entity = new EntityInheritance_MappedSuperclassWithTranslations_Entity();
$entity->setText(new Translatable('base text'));
self::import([$entity]);
$loaded = $entityManager->find(EntityInheritance_MappedSuperclassWithTranslations_Entity::class, $entity->getId());
$loaded->getText()->setTranslation('Basistext', 'de_DE');
$entityManager->flush();
$entityManager->clear();
$reloaded = $entityManager->find(EntityInheritance_MappedSuperclassWithTranslations_Entity::class, $entity->getId());
self::assertSame('base text', $reloaded->getText()->translate('en_GB'));
self::assertSame('Basistext', $reloaded->getText()->translate('de_DE'));
}
public function testUpdateTranslations(): void
{
$entityManager = $this->entityManager;
$entity = new EntityInheritance_MappedSuperclassWithTranslations_Entity();
$t = new Translatable('old text');
$t->setTranslation('alter Text', 'de_DE');
$entity->setText($t);
self::import([$entity]);
$loaded = $entityManager->find(EntityInheritance_MappedSuperclassWithTranslations_Entity::class, $entity->getId());
$loaded->getText()->setTranslation('new text');
$loaded->getText()->setTranslation('neuer Text', 'de_DE');
$entityManager->flush();
$entityManager->clear();
$reloaded = $entityManager->find(EntityInheritance_MappedSuperclassWithTranslations_Entity::class, $entity->getId());
self::assertSame('new text', $reloaded->getText()->translate('en_GB'));
self::assertSame('neuer Text', $reloaded->getText()->translate('de_DE'));
}
}