Thematic: Fix thematic entities + add tests.

pull/4037/head
Julio 4 years ago
parent 4f0115ca9b
commit 0901e4df28
  1. 4
      src/CoreBundle/Migrations/Schema/V200/Version20170625143000.php
  2. 2
      src/CourseBundle/Entity/CThematicAdvance.php
  3. 2
      src/CourseBundle/Entity/CThematicPlan.php
  4. 171
      tests/CourseBundle/Repository/CThematicAdvanceRepositoryTest.php
  5. 109
      tests/CourseBundle/Repository/CThematicPlanRepositoryTest.php
  6. 14
      tests/CourseBundle/Repository/CThematicRepositoryTest.php

@ -74,7 +74,7 @@ class Version20170625143000 extends AbstractMigrationChamilo
}
if (false === $table->hasForeignKey('FK_62798E97163DDA15')) {
$this->addSql(
'ALTER TABLE c_thematic_advance ADD CONSTRAINT FK_62798E97163DDA15 FOREIGN KEY (attendance_id) REFERENCES c_attendance (iid)'
'ALTER TABLE c_thematic_advance ADD CONSTRAINT FK_62798E97163DDA15 FOREIGN KEY (attendance_id) REFERENCES c_attendance (iid) ON DELETE CASCADE'
);
}
if (false === $table->hasIndex('IDX_62798E97163DDA15')) {
@ -101,7 +101,7 @@ class Version20170625143000 extends AbstractMigrationChamilo
}
if (false === $table->hasForeignKey('FK_1197487C2395FCED')) {
$this->addSql(
'ALTER TABLE c_thematic_plan ADD CONSTRAINT FK_1197487C2395FCED FOREIGN KEY (thematic_id) REFERENCES c_thematic (iid)'
'ALTER TABLE c_thematic_plan ADD CONSTRAINT FK_1197487C2395FCED FOREIGN KEY (thematic_id) REFERENCES c_thematic (iid) ON DELETE CASCADE'
);
}

@ -37,7 +37,7 @@ class CThematicAdvance //extends AbstractResource implements ResourceInterface
/**
* @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CAttendance")
* @ORM\JoinColumn(name="attendance_id", referencedColumnName="iid")
* @ORM\JoinColumn(name="attendance_id", referencedColumnName="iid", onDelete="CASCADE")
*/
protected CAttendance $attendance;

@ -37,7 +37,7 @@ class CThematicPlan //extends AbstractResource implements ResourceInterface
/**
* @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CThematic", inversedBy="plans")
* @ORM\JoinColumn(name="thematic_id", referencedColumnName="iid")
* @ORM\JoinColumn(name="thematic_id", referencedColumnName="iid", onDelete="CASCADE")
*/
protected CThematic $thematic;

@ -0,0 +1,171 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\Tests\CourseBundle\Repository;
use Chamilo\CoreBundle\Entity\Room;
use Chamilo\CoreBundle\Repository\Node\CourseRepository;
use Chamilo\CourseBundle\Entity\CAttendance;
use Chamilo\CourseBundle\Entity\CThematic;
use Chamilo\CourseBundle\Entity\CThematicAdvance;
use Chamilo\CourseBundle\Repository\CAttendanceRepository;
use Chamilo\CourseBundle\Repository\CThematicAdvanceRepository;
use Chamilo\CourseBundle\Repository\CThematicRepository;
use Chamilo\Tests\AbstractApiTest;
use Chamilo\Tests\ChamiloTestTrait;
use DateTime;
class CThematicAdvanceRepositoryTest extends AbstractApiTest
{
use ChamiloTestTrait;
public function testCreate(): void
{
$em = $this->getEntityManager();
$courseRepo = self::getContainer()->get(CourseRepository::class);
$thematicRepo = self::getContainer()->get(CThematicRepository::class);
$advanceRepo = self::getContainer()->get(CThematicAdvanceRepository::class);
$attendanceRepo = self::getContainer()->get(CAttendanceRepository::class);
$course = $this->createCourse('new');
$teacher = $this->createUser('teacher');
$attendance = (new CAttendance())
->setName('item')
->setAttendanceWeight(100)
->setParent($course)
->setCreator($teacher)
;
$em->persist($attendance);
$thematic = (new CThematic())
->setTitle('thematic')
->setParent($course)
->setCreator($teacher)
->addCourseLink($course)
;
$em->persist($thematic);
$room = (new Room())
->setTitle('title')
->setDescription('desc')
->setGeolocation('')
->setIp('127.0.0.1')
->setIpMask('24')
;
$em->persist($room);
$advance = (new CThematicAdvance())
->setStartDate(new DateTime())
->setContent('content')
->setAttendance($attendance)
->setDoneAdvance(true)
->setDuration(1)
->setThematic($thematic)
->setRoom($room)
;
$this->assertHasNoEntityViolations($advance);
$em->persist($advance);
$em->flush();
$em->clear();
/** @var CThematic $thematic */
$thematic = $thematicRepo->find($thematic->getIid());
$this->assertNotNull($advance->getRoom());
$this->assertNotNull($advance->getThematic());
$this->assertSame(1, $thematic->getAdvances()->count());
$this->assertSame(0, $thematic->getPlans()->count());
$this->assertSame(1, $thematicRepo->count([]));
$this->assertSame(1, $attendanceRepo->count([]));
$this->assertSame(1, $advanceRepo->count([]));
$advance = $advanceRepo->find($advance->getIid());
$advanceRepo->delete($advance);
$this->assertSame(1, $courseRepo->count([]));
$this->assertSame(1, $thematicRepo->count([]));
$this->assertSame(1, $attendanceRepo->count([]));
$this->assertSame(0, $advanceRepo->count([]));
}
public function testCreateDeleteCourse(): void
{
$em = $this->getEntityManager();
$courseRepo = self::getContainer()->get(CourseRepository::class);
$thematicRepo = self::getContainer()->get(CThematicRepository::class);
$advanceRepo = self::getContainer()->get(CThematicAdvanceRepository::class);
$attendanceRepo = self::getContainer()->get(CAttendanceRepository::class);
$course = $this->createCourse('new');
$teacher = $this->createUser('teacher');
$attendance = (new CAttendance())
->setName('item')
->setAttendanceWeight(100)
->setParent($course)
->setCreator($teacher)
;
$em->persist($attendance);
$thematic = (new CThematic())
->setTitle('thematic')
->setParent($course)
->setCreator($teacher)
->addCourseLink($course)
;
$em->persist($thematic);
$room = (new Room())
->setTitle('title')
->setDescription('desc')
->setGeolocation('')
->setIp('127.0.0.1')
->setIpMask('24')
;
$em->persist($room);
$advance = (new CThematicAdvance())
->setStartDate(new DateTime())
->setContent('content')
->setAttendance($attendance)
->setDoneAdvance(true)
->setDuration(1)
->setThematic($thematic)
->setRoom($room)
;
$this->assertHasNoEntityViolations($advance);
$em->persist($advance);
$em->flush();
$em->clear();
/** @var CThematic $thematic */
$thematic = $thematicRepo->find($thematic->getIid());
$this->assertNotNull($advance->getRoom());
$this->assertNotNull($advance->getThematic());
$this->assertSame(1, $thematic->getAdvances()->count());
$this->assertSame(0, $thematic->getPlans()->count());
$this->assertSame(1, $courseRepo->count([]));
$this->assertSame(1, $thematicRepo->count([]));
$this->assertSame(1, $attendanceRepo->count([]));
$this->assertSame(1, $advanceRepo->count([]));
$course = $courseRepo->find($course->getId());
$courseRepo->delete($course);
$this->assertSame(0, $courseRepo->count([]));
$this->assertSame(0, $thematicRepo->count([]));
$this->assertSame(0, $attendanceRepo->count([]));
$this->assertSame(0, $advanceRepo->count([]));
}
}

@ -0,0 +1,109 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\Tests\CourseBundle\Repository;
use Chamilo\CoreBundle\Repository\Node\CourseRepository;
use Chamilo\CourseBundle\Entity\CThematic;
use Chamilo\CourseBundle\Entity\CThematicPlan;
use Chamilo\CourseBundle\Repository\CThematicPlanRepository;
use Chamilo\CourseBundle\Repository\CThematicRepository;
use Chamilo\Tests\AbstractApiTest;
use Chamilo\Tests\ChamiloTestTrait;
class CThematicPlanRepositoryTest extends AbstractApiTest
{
use ChamiloTestTrait;
public function testCreate(): void
{
$em = $this->getEntityManager();
$courseRepo = self::getContainer()->get(CourseRepository::class);
$thematicRepo = self::getContainer()->get(CThematicRepository::class);
$planRepo = self::getContainer()->get(CThematicPlanRepository::class);
$course = $this->createCourse('new');
$teacher = $this->createUser('teacher');
$thematic = (new CThematic())
->setTitle('thematic')
->setParent($course)
->setCreator($teacher)
->addCourseLink($course)
;
$em->persist($thematic);
$plan = (new CThematicPlan())
->setTitle('title')
->setDescription('desc')
->setThematic($thematic)
->setDescriptionType(1)
;
$em->persist($plan);
$em->flush();
$em->clear();
/** @var CThematic $thematic */
$thematic = $thematicRepo->find($thematic->getIid());
$this->assertSame(1, $thematic->getPlans()->count());
$this->assertSame(1, $thematicRepo->count([]));
$this->assertSame(1, $planRepo->count([]));
$this->assertSame(1, $courseRepo->count([]));
$plan = $planRepo->find($plan->getIid());
$em->remove($plan);
$em->flush();
$this->assertSame(1, $thematicRepo->count([]));
$this->assertSame(1, $courseRepo->count([]));
$this->assertSame(0, $planRepo->count([]));
}
public function testCreateDeleteCourse(): void
{
$em = $this->getEntityManager();
$courseRepo = self::getContainer()->get(CourseRepository::class);
$thematicRepo = self::getContainer()->get(CThematicRepository::class);
$planRepo = self::getContainer()->get(CThematicPlanRepository::class);
$course = $this->createCourse('new');
$teacher = $this->createUser('teacher');
$thematic = (new CThematic())
->setTitle('thematic')
->setParent($course)
->setCreator($teacher)
->addCourseLink($course)
;
$em->persist($thematic);
$plan = (new CThematicPlan())
->setTitle('title')
->setDescription('desc')
->setThematic($thematic)
->setDescriptionType(1)
;
$em->persist($plan);
$em->flush();
$em->clear();
/** @var CThematic $thematic */
$thematic = $thematicRepo->find($thematic->getIid());
$this->assertSame(1, $thematic->getPlans()->count());
$this->assertSame(1, $thematicRepo->count([]));
$this->assertSame(1, $planRepo->count([]));
$this->assertSame(1, $courseRepo->count([]));
$course = $courseRepo->find($course->getId());
$courseRepo->delete($course);
$this->assertSame(0, $thematicRepo->count([]));
$this->assertSame(0, $planRepo->count([]));
$this->assertSame(0, $courseRepo->count([]));
}
}

@ -6,6 +6,7 @@ declare(strict_types=1);
namespace Chamilo\Tests\CourseBundle\Repository;
use Chamilo\CoreBundle\Repository\Node\CourseRepository;
use Chamilo\CourseBundle\Entity\CThematic;
use Chamilo\CourseBundle\Repository\CThematicRepository;
use Chamilo\Tests\AbstractApiTest;
@ -18,22 +19,27 @@ class CThematicRepositoryTest extends AbstractApiTest
public function testCreate(): void
{
$em = $this->getEntityManager();
$courseRepo = self::getContainer()->get(CourseRepository::class);
$repo = self::getContainer()->get(CThematicRepository::class);
$course = $this->createCourse('new');
$teacher = $this->createUser('teacher');
$item = (new CThematic())
$thematic = (new CThematic())
->setTitle('thematic')
->setParent($course)
->setCreator($teacher)
->addCourseLink($course)
;
$this->assertHasNoEntityViolations($item);
$em->persist($item);
$this->assertHasNoEntityViolations($thematic);
$em->persist($thematic);
$em->flush();
$this->assertSame('thematic', (string) $item);
$this->assertSame('thematic', (string) $thematic);
$this->assertSame(1, $repo->count([]));
$courseRepo->delete($course);
$this->assertSame(0, $repo->count([]));
$this->assertSame(0, $courseRepo->count([]));
}
}

Loading…
Cancel
Save