Tests: Add phpunit tests

pull/3984/head
Julio 3 years ago
parent 50b401e85f
commit b116f4cd27
  1. 10
      src/CoreBundle/Entity/GradebookCategory.php
  2. 26
      src/CoreBundle/Entity/GradebookCertificate.php
  3. 36
      src/CoreBundle/Entity/GradebookComment.php
  4. 2
      src/CoreBundle/Entity/GradebookLinkevalLog.php
  5. 8
      src/CoreBundle/Entity/GradebookResult.php
  6. 2
      src/CoreBundle/Entity/GradebookResultAttempt.php
  7. 46
      tests/CoreBundle/Repository/GradeBookCategoryRepositoryTest.php

@ -116,6 +116,7 @@ class GradebookCategory
/**
* @ORM\Column(name="visible", type="boolean", nullable=false)
*/
#[Assert\NotBlank]
protected bool $visible;
/**
@ -131,6 +132,7 @@ class GradebookCategory
/**
* @ORM\Column(name="locked", type="integer", nullable=false)
*/
#[Assert\NotBlank]
protected ?int $locked;
/**
@ -141,6 +143,7 @@ class GradebookCategory
/**
* @ORM\Column(name="generate_certificates", type="boolean", nullable=false)
*/
#[Assert\NotBlank]
protected bool $generateCertificates;
/**
@ -199,12 +202,7 @@ class GradebookCategory
return $this;
}
/**
* Get name.
*
* @return string
*/
public function getName()
public function getName(): string
{
return $this->name;
}

@ -9,6 +9,7 @@ namespace Chamilo\CoreBundle\Entity;
use Chamilo\CoreBundle\Traits\UserTrait;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Table(
@ -48,6 +49,7 @@ class GradebookCertificate
protected float $scoreCertificate;
/**
* @Gedmo\Timestampable(on="create")
* @ORM\Column(name="created_at", type="datetime", nullable=false)
*/
protected DateTime $createdAt;
@ -134,4 +136,28 @@ class GradebookCertificate
return $this;
}
public function getCategory(): GradebookCategory
{
return $this->category;
}
public function setCategory(GradebookCategory $category): self
{
$this->category = $category;
return $this;
}
public function getUser(): User
{
return $this->user;
}
public function setUser(User $user): self
{
$this->user = $user;
return $this;
}
}

@ -50,4 +50,40 @@ class GradebookComment
{
$this->comment = '';
}
public function getUser(): User
{
return $this->user;
}
public function setUser(User $user): self
{
$this->user = $user;
return $this;
}
public function getGradeBook(): GradebookCategory
{
return $this->gradeBook;
}
public function setGradeBook(GradebookCategory $gradeBook): self
{
$this->gradeBook = $gradeBook;
return $this;
}
public function getComment(): ?string
{
return $this->comment;
}
public function setComment(?string $comment): self
{
$this->comment = $comment;
return $this;
}
}

@ -12,8 +12,6 @@ use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* GradebookLinkevalLog.
*
* @ORM\Table(name="gradebook_linkeval_log")
* @ORM\Entity
*/

@ -12,14 +12,12 @@ use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* GradebookResult.
*
* @ORM\Table(name="gradebook_result",
* indexes={
* @ORM\Index(name="idx_gb_uid_eid", columns={"user_id", "evaluation_id"}),
* })
*
* @ORM\Entity
* }
* )
* @ORM\Entity
*/
class GradebookResult
{

@ -10,8 +10,6 @@ use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
/**
* GradebookResultAttempt.
*
* @ORM\Table(name="gradebook_result_attempt")
* @ORM\Entity
*/

@ -7,8 +7,12 @@ declare(strict_types=1);
namespace Chamilo\Tests\CoreBundle\Repository;
use Chamilo\CoreBundle\Entity\GradebookCategory;
use Chamilo\CoreBundle\Entity\GradebookCertificate;
use Chamilo\CoreBundle\Entity\GradebookComment;
use Chamilo\CoreBundle\Entity\GradebookEvaluation;
use Chamilo\CoreBundle\Entity\GradebookLink;
use Chamilo\CoreBundle\Entity\GradebookResult;
use Chamilo\CoreBundle\Entity\GradebookResultAttempt;
use Chamilo\CoreBundle\Repository\GradeBookCategoryRepository;
use Chamilo\Tests\AbstractApiTest;
use Chamilo\Tests\ChamiloTestTrait;
@ -31,6 +35,7 @@ class GradeBookCategoryRepositoryTest extends AbstractApiTest
->setCourse($course)
->setWeight(100.00)
->setVisible(true)
->setGenerateCertificates(true)
;
$this->assertHasNoEntityViolations($category);
@ -65,7 +70,46 @@ class GradeBookCategoryRepositoryTest extends AbstractApiTest
$em->flush();
$this->assertSame(1, $category->getEvaluations()->count());
$this->assertSame(1, $category->getEvaluations()->count());
$this->assertSame(1, $category->getLinks()->count());
$this->assertSame(1, $repo->count([]));
$user = $this->createUser('test');
$certificate = (new GradebookCertificate())
->setUser($user)
->setScoreCertificate(100.00)
->setCategory($category)
;
$em->persist($certificate);
$em->flush();
$comment = (new GradebookComment())
->setUser($user)
->setGradeBook($category)
->setComment('comment')
;
$em->persist($comment);
$em->flush();
$result = (new GradebookResult())
->setUser($user)
->setEvaluation($evaluation)
->setScore(100.00)
;
$em->persist($result);
$em->flush();
$resultAttempt = (new GradebookResultAttempt())
->setResult($result)
->setComment('comment')
->setScore(100.00)
;
$em->persist($resultAttempt);
$em->flush();
$em->remove($category);
$em->flush();
$this->assertSame(0, $repo->count([]));
}
}

Loading…
Cancel
Save