Groups: Set constants into entity + add test

pull/3959/head
Julio 4 years ago
parent cfd5371c7e
commit 139f7943b0
  1. 17
      public/main/inc/lib/groupmanager.lib.php
  2. 23
      src/CourseBundle/Entity/CGroup.php
  3. 40
      tests/CourseBundle/Repository/CGroupRepositoryTest.php

@ -226,13 +226,13 @@ class GroupManager
$places = (int) $places;
// Default values
$docState = self::TOOL_PRIVATE;
$calendarState = self::TOOL_PRIVATE;
$workState = self::TOOL_PRIVATE;
$anonuncementState = self::TOOL_PRIVATE;
$forumState = self::TOOL_PRIVATE;
$wikiState = self::TOOL_PRIVATE;
$chatState = self::TOOL_PRIVATE;
$docState = CGroup::TOOL_PRIVATE;
$calendarState = CGroup::TOOL_PRIVATE;
$workState = CGroup::TOOL_PRIVATE;
$anonuncementState = CGroup::TOOL_PRIVATE;
$forumState = CGroup::TOOL_PRIVATE;
$wikiState = CGroup::TOOL_PRIVATE;
$chatState = CGroup::TOOL_PRIVATE;
$selfRegAllowed = 0;
$selfUnregAllwoed = 0;
$documentAccess = 0;
@ -266,8 +266,7 @@ class GroupManager
$category = Container::getGroupCategoryRepository()->find($category_id);
}
$group = new CGroup();
$group
$group = (new CGroup())
->setName($name)
->setCategory($category)
->setMaxStudent($places)

@ -31,10 +31,15 @@ use Symfony\Component\Validator\Constraints as Assert;
* }
* )
*
* @ORM\Entity
* @ORM\Entity(repositoryClass="Chamilo\CourseBundle\Repository\CGroupRepository")
*/
class CGroup extends AbstractResource implements ResourceInterface
{
public const TOOL_NOT_AVAILABLE = 0;
public const TOOL_PUBLIC = 1;
public const TOOL_PRIVATE = 2;
public const TOOL_PRIVATE_BETWEEN_USERS = 3;
/**
* @ORM\Column(name="iid", type="integer")
* @ORM\Id
@ -70,6 +75,7 @@ class CGroup extends AbstractResource implements ResourceInterface
/**
* @ORM\Column(name="max_student", type="integer")
*/
#[Assert\NotBlank]
protected int $maxStudent;
/**
@ -141,6 +147,21 @@ class CGroup extends AbstractResource implements ResourceInterface
$this->status = true;
$this->members = new ArrayCollection();
$this->tutors = new ArrayCollection();
// Default values
$defaultVisibility = self::TOOL_PRIVATE;
$this->docState = $defaultVisibility;
$this->calendarState = $defaultVisibility;
$this->workState = $defaultVisibility;
$this->announcementsState = $defaultVisibility;
$this->forumState = $defaultVisibility;
$this->wikiState = $defaultVisibility;
$this->chatState = $defaultVisibility;
$this->documentAccess = $defaultVisibility;
$this->selfRegistrationAllowed = false;
$this->selfUnregistrationAllowed = false;
}
public function __toString(): string

@ -0,0 +1,40 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\Tests\CourseBundle\Repository;
use Chamilo\CourseBundle\Entity\CGroup;
use Chamilo\CourseBundle\Repository\CGroupRepository;
use Chamilo\Tests\AbstractApiTest;
use Chamilo\Tests\ChamiloTestTrait;
class CGroupRepositoryTest extends AbstractApiTest
{
use ChamiloTestTrait;
public function testCreate(): void
{
self::bootKernel();
$em = self::getContainer()->get('doctrine')->getManager();
$repo = self::getContainer()->get(CGroupRepository::class);
$course = $this->createCourse('new');
$teacher = $this->createUser('teacher');
$item = (new CGroup())
->setName('Group')
->setParent($course)
->setCreator($teacher)
->setMaxStudent(100)
;
$this->assertHasNoEntityViolations($item);
$em->persist($item);
$em->flush();
$this->assertSame(1, $repo->count([]));
}
}
Loading…
Cancel
Save