|
|
|
@ -11,7 +11,6 @@ use Chamilo\CoreBundle\Entity\ExtraFieldSavedSearch; |
|
|
|
|
use Chamilo\CoreBundle\Repository\ExtraFieldRepository; |
|
|
|
|
use Chamilo\Tests\AbstractApiTest; |
|
|
|
|
use Chamilo\Tests\ChamiloTestTrait; |
|
|
|
|
use Gedmo\Translatable\Entity\Translation; |
|
|
|
|
|
|
|
|
|
class ExtraFieldRepositoryTest extends AbstractApiTest |
|
|
|
|
{ |
|
|
|
@ -57,75 +56,6 @@ class ExtraFieldRepositoryTest extends AbstractApiTest |
|
|
|
|
$this->assertSame($defaultCount + 1, $repo->count([])); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function testCreateWithTranslation(): void |
|
|
|
|
{ |
|
|
|
|
$em = $this->getEntityManager(); |
|
|
|
|
// $extraFieldRepo = static::getContainer()->get(ExtraFieldRepository::class); |
|
|
|
|
$extraFieldRepo = $em->getRepository(ExtraField::class); |
|
|
|
|
$translator = static::getContainer()->get('translator'); |
|
|
|
|
|
|
|
|
|
$defaultLocale = $translator->getLocale(); |
|
|
|
|
$this->assertSame('en_US', $defaultLocale); |
|
|
|
|
|
|
|
|
|
$defaultCount = $extraFieldRepo->count([]); |
|
|
|
|
|
|
|
|
|
$extraField = (new ExtraField()) |
|
|
|
|
->setDisplayText('test in ENGLISH') |
|
|
|
|
->setVariable('test in en') |
|
|
|
|
->setItemType(ExtraField::USER_FIELD_TYPE) |
|
|
|
|
->setValueType(\ExtraField::FIELD_TYPE_TEXT) |
|
|
|
|
; |
|
|
|
|
$this->assertHasNoEntityViolations($extraField); |
|
|
|
|
$em->persist($extraField); |
|
|
|
|
$em->flush(); |
|
|
|
|
|
|
|
|
|
$this->assertSame($defaultCount + 1, $extraFieldRepo->count([])); |
|
|
|
|
|
|
|
|
|
/** @var ExtraField $extraField */ |
|
|
|
|
$extraField = $extraFieldRepo->find($extraField->getId()); |
|
|
|
|
|
|
|
|
|
$extraField |
|
|
|
|
->setTranslatableLocale('fr_FR') |
|
|
|
|
->setDisplayText('test in FRENCH') |
|
|
|
|
; |
|
|
|
|
$em->persist($extraField); |
|
|
|
|
$em->flush(); |
|
|
|
|
|
|
|
|
|
/** @var ExtraField $extraField */ |
|
|
|
|
$extraField = $extraFieldRepo->find($extraField->getId()); |
|
|
|
|
|
|
|
|
|
$extraField |
|
|
|
|
->setTranslatableLocale('it') |
|
|
|
|
->setDisplayText('test in ITALIAN') |
|
|
|
|
; |
|
|
|
|
$em->persist($extraField); |
|
|
|
|
$em->flush(); |
|
|
|
|
$em->clear(); |
|
|
|
|
|
|
|
|
|
$this->assertSame($defaultCount + 1, $extraFieldRepo->count([])); |
|
|
|
|
|
|
|
|
|
/** @var ExtraField $extraField */ |
|
|
|
|
$extraField = $extraFieldRepo->find($extraField->getId()); |
|
|
|
|
$repository = $em->getRepository(Translation::class); |
|
|
|
|
|
|
|
|
|
$translations = $repository->findTranslations($extraField); |
|
|
|
|
|
|
|
|
|
$this->assertCount(2, $translations); |
|
|
|
|
$expected = [ |
|
|
|
|
'fr_FR' => [ |
|
|
|
|
'displayText' => 'test in FRENCH', |
|
|
|
|
], |
|
|
|
|
'it' => [ |
|
|
|
|
'displayText' => 'test in ITALIAN', |
|
|
|
|
], |
|
|
|
|
]; |
|
|
|
|
$this->assertSame($expected, $translations); |
|
|
|
|
|
|
|
|
|
/** @var ExtraField $extraField */ |
|
|
|
|
$extraField = $extraFieldRepo->find($extraField->getId()); |
|
|
|
|
$this->assertSame('test in ENGLISH', $extraField->getDisplayText()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function testGetExtraFields(): void |
|
|
|
|
{ |
|
|
|
|
$repo = static::getContainer()->get(ExtraFieldRepository::class); |
|
|
|
|