Tests: Add phpunit tests, fix entities

pull/3984/head
Julio 5 years ago
parent e10d83af94
commit ea1fc68336
  1. 39
      src/CoreBundle/Entity/Promotion.php
  2. 2
      src/CoreBundle/Entity/Session.php
  3. 2
      src/CoreBundle/Entity/SysAnnouncement.php
  4. 9
      tests/CoreBundle/Repository/PromotionRepositoryTest.php
  5. 3
      tests/CoreBundle/Repository/SessionRepositoryTest.php
  6. 25
      tests/CoreBundle/Repository/SysAnnouncementRepositoryTest.php

@ -6,6 +6,7 @@ declare(strict_types=1);
namespace Chamilo\CoreBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
@ -51,12 +52,17 @@ class Promotion
/**
* @var Collection|Session[]
*
* @ORM\OneToMany(
* targetEntity="Chamilo\CoreBundle\Entity\Session", mappedBy="promotion", cascade={"persist"}
* )
* @ORM\OneToMany(targetEntity="Session", mappedBy="promotion", cascade={"persist"})
*/
protected Collection $sessions;
/**
* @var Collection|SysAnnouncement[]
*
* @ORM\OneToMany(targetEntity="SysAnnouncement", mappedBy="promotion", cascade={"persist"})
*/
protected Collection $announcements;
/**
* @ORM\Column(name="status", type="integer", nullable=false)
*/
@ -65,6 +71,8 @@ class Promotion
public function __construct()
{
$this->status = self::PROMOTION_STATUS_ACTIVE;
$this->announcements = new ArrayCollection();
$this->sessions = new ArrayCollection();
}
/**
@ -84,12 +92,7 @@ class Promotion
return $this;
}
/**
* Get name.
*
* @return string
*/
public function getName()
public function getName(): string
{
return $this->name;
}
@ -154,4 +157,22 @@ class Promotion
return $this;
}
/**
* @return SysAnnouncement[]|Collection
*/
public function getAnnouncements()
{
return $this->announcements;
}
/**
* @param SysAnnouncement[]|Collection $announcements
*/
public function setAnnouncements($announcements): self
{
$this->announcements = $announcements;
return $this;
}
}

@ -312,7 +312,7 @@ class Session implements ResourceWithAccessUrlInterface
return $this->getName();
}
public function getDuration(): int
public function getDuration(): ?int
{
return $this->duration;
}

@ -74,7 +74,7 @@ class SysAnnouncement
protected ?Career $career = null;
/**
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Promotion")
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Promotion", inversedBy="announcements")
* @ORM\JoinColumn(name="promotion_id", referencedColumnName="id", onDelete="CASCADE")
*/
protected ?Promotion $promotion = null;

@ -30,16 +30,19 @@ class PromotionRepositoryTest extends AbstractApiTest
$em->persist($career);
$em->flush();
$item = (new Promotion())
$promotion = (new Promotion())
->setName('2000')
->setDescription('Promotion of 2000')
->setCareer($career)
->setStatus(1)
;
$this->assertHasNoEntityViolations($item);
$em->persist($item);
$this->assertHasNoEntityViolations($promotion);
$em->persist($promotion);
$em->flush();
$this->assertSame(0, $promotion->getAnnouncements()->count());
$this->assertSame(0, $promotion->getSessions()->count());
$this->assertSame($defaultCount + 1, $repo->count([]));
}
}

@ -44,8 +44,9 @@ class SessionRepositoryTest extends AbstractApiTest
$this->assertSame(1, $repo->count([]));
$this->assertSame('session 1', (string) $session);
$this->assertSame(0, \count($session->getAllUsersFromCourse(0)));
$this->assertSame(100, $session->getDuration());
$this->assertTrue($session->isActiveForStudent());
$this->assertTrue($session->isActiveForCoach());

@ -47,7 +47,28 @@ class SysAnnouncementRepositoryTest extends WebTestCase
;
$em->persist($sysAnnouncement);
$em->flush();
$count = $repo->count([]);
$this->assertSame(2, $count);
$repo->update($sysAnnouncement);
$this->assertSame(2, $repo->count([]));
$repo->delete($sysAnnouncement->getId());
$this->assertSame(1, $repo->count([]));
}
public function testGetVisibilityList(): void
{
self::bootKernel();
$repo = self::getContainer()->get(SysAnnouncementRepository::class);
$this->assertIsArray($repo->getVisibilityList());
}
public function testGetAnnouncements(): void
{
self::bootKernel();
$repo = self::getContainer()->get(SysAnnouncementRepository::class);
$user = $this->getUser('admin');
$items = $repo->getAnnouncements($user, $this->getAccessUrl(), 'en');
$this->assertSame(1, count($items));
}
}

Loading…
Cancel
Save