Fix CToolIntro delete

pull/4032/head
Julio 4 years ago
parent 9a267dce3c
commit f88ad517fc
  1. 2
      src/CoreBundle/Migrations/Schema/V200/Version20211008133540.php
  2. 2
      src/CourseBundle/Entity/CToolIntro.php
  3. 46
      tests/CourseBundle/Repository/CToolIntroRepositoryTest.php

@ -21,7 +21,7 @@ final class Version20211008133540 extends AbstractMigrationChamilo
if ($table->hasColumn('c_tool_id')) {
if (!$table->hasForeignKey('FK_D705267B1DF6B517')) {
$this->addSql(
'ALTER TABLE c_tool_intro ADD CONSTRAINT FK_D705267B1DF6B517 FOREIGN KEY (c_tool_id) REFERENCES c_tool (iid);'
'ALTER TABLE c_tool_intro ADD CONSTRAINT FK_D705267B1DF6B517 FOREIGN KEY (c_tool_id) REFERENCES c_tool (iid) ON DELETE CASCADE'
);
}
if (!$table->hasIndex('IDX_D705267B1DF6B517')) {

@ -78,7 +78,7 @@ class CToolIntro extends AbstractResource implements ResourceInterface, Resource
/**
* @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CTool")
* @ORM\JoinColumn(name="c_tool_id", referencedColumnName="iid", nullable=false)
* @ORM\JoinColumn(name="c_tool_id", referencedColumnName="iid", nullable=false, onDelete="CASCADE")
*/
#[Assert\NotNull]
#[Groups(['c_tool_intro:read', 'c_tool_intro:write'])]

@ -7,6 +7,7 @@ declare(strict_types=1);
namespace Chamilo\Tests\CourseBundle\Repository;
use Chamilo\CoreBundle\Entity\ResourceLink;
use Chamilo\CoreBundle\Repository\Node\CourseRepository;
use Chamilo\CourseBundle\Entity\CTool;
use Chamilo\CourseBundle\Entity\CToolIntro;
use Chamilo\CourseBundle\Repository\CToolIntroRepository;
@ -19,9 +20,9 @@ class CToolIntroRepositoryTest extends AbstractApiTest
public function testCreate(): void
{
self::bootKernel();
$em = $this->getEntityManager();
$courseRepo = self::getContainer()->get(CourseRepository::class);
$repo = self::getContainer()->get(CToolIntroRepository::class);
$this->assertSame(0, $repo->count([]));
@ -46,16 +47,49 @@ class CToolIntroRepositoryTest extends AbstractApiTest
$this->assertNotEmpty($intro->getIntroText());
$this->assertNotNull($intro->getIid());
$this->assertNotEmpty($intro->getResourceName());
$this->assertSame(1, $repo->count([]));
// Delete intro.
$repo->delete($intro);
$this->assertSame(0, $repo->count([]));
$this->assertSame(1, $courseRepo->count([]));
}
public function testCreateInSession(): void
public function testCreateAndDeleteCourse(): void
{
self::bootKernel();
$em = $this->getEntityManager();
$courseRepo = self::getContainer()->get(CourseRepository::class);
$repo = self::getContainer()->get(CToolIntroRepository::class);
$course = $this->createCourse('new');
$teacher = $this->createUser('teacher');
/** @var CTool $courseTool */
$courseTool = $course->getTools()->first();
$intro = (new CToolIntro())
->setIntroText('test')
->setCourseTool($courseTool)
->setParent($course)
->setCreator($teacher)
->addCourseLink($course)
;
$this->assertHasNoEntityViolations($intro);
$em->persist($intro);
$em->flush();
$this->assertSame(1, $courseRepo->count([]));
$this->assertSame(1, $repo->count([]));
// Delete course.
$courseRepo->delete($course);
$this->assertSame(0, $repo->count([]));
$this->assertSame(0, $courseRepo->count([]));
}
public function testCreateInSession(): void
{
$em = $this->getEntityManager();
$repo = self::getContainer()->get(CToolIntroRepository::class);
@ -84,7 +118,6 @@ class CToolIntroRepositoryTest extends AbstractApiTest
$this->assertSame(1, $repo->count([]));
// Create intro in session.
$intro2 = (new CToolIntro())
->setIntroText('test in session')
->setCourseTool($courseTool)
@ -218,7 +251,6 @@ class CToolIntroRepositoryTest extends AbstractApiTest
public function testUpdateIntroApi(): void
{
$course = $this->createCourse('new');
$token = $this->getUserToken();
$resourceNodeId = $course->getResourceNode()->getId();

Loading…
Cancel
Save