Tests: Add phpunit tests

pull/3959/head
Julio 4 years ago
parent 81d4c28bec
commit 6d015e52ec
  1. 3
      public/main/inc/lib/AnnouncementManager.php
  2. 4
      src/CourseBundle/Entity/CAnnouncement.php
  3. 5
      src/CourseBundle/Entity/CAnnouncementAttachment.php
  4. 3
      src/CourseBundle/Entity/CAttendance.php
  5. 57
      tests/CourseBundle/Repository/CAnnouncementAttachmentRepositoryTest.php
  6. 40
      tests/CourseBundle/Repository/CAnnouncementRepositoryTest.php
  7. 41
      tests/CourseBundle/Repository/CAttendanceRepositoryTest.php
  8. 40
      tests/CourseBundle/Repository/CLpCategoryRepositoryTest.php
  9. 3
      tests/CourseBundle/Repository/CLpRepositoryTest.php

@ -1191,8 +1191,7 @@ class AnnouncementManager
);
} else {
$repo = Container::getAnnouncementAttachmentRepository();
$attachment = new CAnnouncementAttachment();
$attachment
$attachment = (new CAnnouncementAttachment())
->setFilename($file_name)
->setPath(uniqid('announce_', true))
->setComment($file_comment)

@ -30,10 +30,9 @@ class CAnnouncement extends AbstractResource implements ResourceInterface
protected int $iid;
/**
* @Assert\NotBlank()
*
* @ORM\Column(name="title", type="text", nullable=false)
*/
#[Assert\NotBlank]
protected string $title;
/**
@ -69,6 +68,7 @@ class CAnnouncement extends AbstractResource implements ResourceInterface
public function __construct()
{
$this->content = '';
$this->displayOrder = 1;
$this->attachments = new ArrayCollection();
}

@ -51,6 +51,11 @@ class CAnnouncementAttachment extends AbstractResource implements ResourceInterf
*/
protected string $filename;
public function __construct()
{
$this->comment = '';
}
public function __toString(): string
{
return $this->getFilename();

@ -62,6 +62,7 @@ class CAttendance extends AbstractResource implements ResourceInterface
/**
* @ORM\Column(name="attendance_weight", type="float", precision=6, scale=2, nullable=false)
*/
#[Assert\NotNull]
protected float $attendanceWeight;
/**
@ -95,7 +96,7 @@ class CAttendance extends AbstractResource implements ResourceInterface
public function __toString(): string
{
return (string) $this->getIid();
return $this->getName();
}
public function setName(string $name): self

@ -0,0 +1,57 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\Tests\CourseBundle\Repository;
use Chamilo\CourseBundle\Entity\CAnnouncement;
use Chamilo\CourseBundle\Entity\CAnnouncementAttachment;
use Chamilo\CourseBundle\Repository\CAnnouncementAttachmentRepository;
use Chamilo\CourseBundle\Repository\CAnnouncementRepository;
use Chamilo\Tests\AbstractApiTest;
use Chamilo\Tests\ChamiloTestTrait;
class CAnnouncementAttachmentRepositoryTest extends AbstractApiTest
{
use ChamiloTestTrait;
public function testCreate(): void
{
self::bootKernel();
$em = self::getContainer()->get('doctrine')->getManager();
$repo = self::getContainer()->get(CAnnouncementRepository::class);
$repoAttachment = self::getContainer()->get(CAnnouncementAttachmentRepository::class);
$course = $this->createCourse('new');
$teacher = $this->createUser('teacher');
$announcement = (new CAnnouncement())
->setTitle('item')
->setParent($course)
->setCreator($teacher)
;
$this->assertHasNoEntityViolations($announcement);
$em->persist($announcement);
$attachment = (new CAnnouncementAttachment())
->setFilename('image')
->setPath(uniqid('announce_', true))
->setAnnouncement($announcement)
->setSize(1)
->setCreator($teacher)
->setParent($announcement)
->addCourseLink($course)
;
$this->assertHasNoEntityViolations($attachment);
$em->persist($attachment);
$em->flush();
$this->assertSame(1, $repo->count([]));
$this->assertSame(1, $repoAttachment->count([]));
}
}

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

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

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

@ -26,7 +26,7 @@ class CLpRepositoryTest extends AbstractApiTest
$teacher = $this->createUser('teacher');
$item = (new CLp())
->setName('Group')
->setName('lp')
->setParent($course)
->setCreator($teacher)
->setLpType(CLp::LP_TYPE)
@ -35,6 +35,7 @@ class CLpRepositoryTest extends AbstractApiTest
$em->persist($item);
$em->flush();
$this->assertSame('lp', (string) $item);
$this->assertSame(1, $repo->count([]));
}
}

Loading…
Cancel
Save