You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.1 KiB
78 lines
2.1 KiB
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/* For licensing terms, see /license.txt */
|
|
|
|
namespace Chamilo\Tests\CoreBundle\Repository;
|
|
|
|
use Chamilo\CoreBundle\Entity\Group;
|
|
use Chamilo\CoreBundle\Repository\GroupRepository;
|
|
use Chamilo\Tests\AbstractApiTest;
|
|
use Chamilo\Tests\ChamiloTestTrait;
|
|
|
|
class GroupRepositoryTest extends AbstractApiTest
|
|
{
|
|
use ChamiloTestTrait;
|
|
|
|
public function testCreate(): void
|
|
{
|
|
$em = $this->getEntityManager();
|
|
$repo = self::getContainer()->get(GroupRepository::class);
|
|
$defaultGroups = $repo->count([]);
|
|
|
|
$roles = [
|
|
'ROLE_TEST',
|
|
'ROLE_TEST2',
|
|
];
|
|
|
|
$group = (new Group('new_group'))
|
|
->setCode('new_group')
|
|
->setRoles($roles)
|
|
->addRole('ROLE_TEST3')
|
|
;
|
|
$this->assertHasNoEntityViolations($group);
|
|
$em->persist($group);
|
|
$em->flush();
|
|
|
|
$this->assertSame('new_group', (string) $group);
|
|
$this->assertSame('new_group', $group->getCode());
|
|
$this->assertNotNull($group->getId());
|
|
|
|
$this->assertCount(3, $group->getRoles());
|
|
|
|
$this->assertSame($defaultGroups + 1, $repo->count([]));
|
|
|
|
$group->removeRole('role');
|
|
$this->assertCount(3, $group->getRoles());
|
|
|
|
$group->removeRole('ROLE_TEST3');
|
|
$this->assertCount(2, $group->getRoles());
|
|
}
|
|
|
|
public function testGetAdmins(): void
|
|
{
|
|
/** @var GroupRepository $repo */
|
|
$repo = self::getContainer()->get(GroupRepository::class);
|
|
$admins = $repo->getAdmins();
|
|
$this->assertCount(0, $admins);
|
|
}
|
|
|
|
public function testCreateDefaultGroups(): void
|
|
{
|
|
$repo = self::getContainer()->get(GroupRepository::class);
|
|
$groups = $repo->findAll();
|
|
$defaultCount = $repo->count([]);
|
|
$repo->createDefaultGroups();
|
|
$count = $repo->count([]);
|
|
$this->assertSame($defaultCount, $count);
|
|
|
|
foreach ($groups as $group) {
|
|
$repo->delete($group);
|
|
}
|
|
|
|
$repo->createDefaultGroups();
|
|
$count = $repo->count([]);
|
|
$this->assertSame($defaultCount, $count);
|
|
}
|
|
}
|
|
|