-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMappedSuperclassInheritanceTest.php
More file actions
84 lines (66 loc) · 3.36 KB
/
MappedSuperclassInheritanceTest.php
File metadata and controls
84 lines (66 loc) · 3.36 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
<?php
namespace Webfactory\Bundle\PolyglotBundle\Tests\Functional;
use Webfactory\Bundle\PolyglotBundle\Tests\Fixtures\Entity\EntityInheritance\EntityInheritance_MappedSuperclass;
use Webfactory\Bundle\PolyglotBundle\Tests\Fixtures\Entity\EntityInheritance\EntityInheritance_MappedSuperclassEntity;
use Webfactory\Bundle\PolyglotBundle\Tests\Fixtures\Entity\EntityInheritance\EntityInheritance_MappedSuperclassEntityTranslation;
use Webfactory\Bundle\PolyglotBundle\Translatable;
/**
* This tests that a property inherited from a MappedSuperclass can be declared
* as translatable via the class-level #[TranslatedProperty] attribute on the
* concrete entity. This makes it possible to define base classes (mapped superclasses)
* that leave it to extending Entity subclasses whether to use Polyglot or not.
*/
class MappedSuperclassInheritanceTest extends DatabaseFunctionalTestCase
{
protected function setUp(): void
{
parent::setUp();
self::setupSchema([
EntityInheritance_MappedSuperclass::class,
EntityInheritance_MappedSuperclassEntity::class,
EntityInheritance_MappedSuperclassEntityTranslation::class,
]);
}
public function testPersistAndReloadEntity(): void
{
$entity = new EntityInheritance_MappedSuperclassEntity();
$t = new Translatable('base text');
$t->setTranslation('Basistext', 'de_DE');
$entity->setText($t);
self::import([$entity]);
$loaded = $this->entityManager->find(EntityInheritance_MappedSuperclassEntity::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_MappedSuperclassEntity();
$entity->setText(new Translatable('base text'));
self::import([$entity]);
$loaded = $entityManager->find(EntityInheritance_MappedSuperclassEntity::class, $entity->getId());
$loaded->getText()->setTranslation('Basistext', 'de_DE');
$entityManager->flush();
$entityManager->clear();
$reloaded = $entityManager->find(EntityInheritance_MappedSuperclassEntity::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_MappedSuperclassEntity();
$t = new Translatable('old text');
$t->setTranslation('alter Text', 'de_DE');
$entity->setText($t);
self::import([$entity]);
$loaded = $entityManager->find(EntityInheritance_MappedSuperclassEntity::class, $entity->getId());
$loaded->getText()->setTranslation('new text');
$loaded->getText()->setTranslation('neuer Text', 'de_DE');
$entityManager->flush();
$entityManager->clear();
$reloaded = $entityManager->find(EntityInheritance_MappedSuperclassEntity::class, $entity->getId());
self::assertSame('new text', $reloaded->getText()->translate('en_GB'));
self::assertSame('neuer Text', $reloaded->getText()->translate('de_DE'));
}
}