parent
262b5e6156
commit
25bbcfddc3
@ -0,0 +1,63 @@ |
||||
<?php |
||||
|
||||
declare(strict_types=1); |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\Tests\CourseBundle\Repository; |
||||
|
||||
use Chamilo\CourseBundle\Entity\CStudentPublication; |
||||
use Chamilo\CourseBundle\Entity\CStudentPublicationAssignment; |
||||
use Chamilo\CourseBundle\Repository\CStudentPublicationAssignmentRepository; |
||||
use Chamilo\CourseBundle\Repository\CStudentPublicationRepository; |
||||
use Chamilo\Tests\AbstractApiTest; |
||||
use Chamilo\Tests\ChamiloTestTrait; |
||||
use DateTime; |
||||
|
||||
class CStudentPublicationAssignmentRepositoryTest extends AbstractApiTest |
||||
{ |
||||
use ChamiloTestTrait; |
||||
|
||||
public function testCreate(): void |
||||
{ |
||||
$em = $this->getEntityManager(); |
||||
$publicationRepo = self::getContainer()->get(CStudentPublicationRepository::class); |
||||
$assignmentRepo = self::getContainer()->get(CStudentPublicationAssignmentRepository::class); |
||||
|
||||
$course = $this->createCourse('new'); |
||||
$teacher = $this->createUser('teacher'); |
||||
|
||||
$publication = (new CStudentPublication()) |
||||
->setTitle('publi') |
||||
->setDescription('desc') |
||||
->setParent($course) |
||||
->setFiletype('folder') |
||||
->setWeight(100) |
||||
->setCreator($teacher) |
||||
; |
||||
$em->persist($publication); |
||||
|
||||
$assignment = (new CStudentPublicationAssignment()) |
||||
->setAddToCalendar(0) |
||||
->setEnableQualification(true) |
||||
->setEndsOn(new DateTime()) |
||||
->setExpiresOn(new DateTime()) |
||||
->setPublication($publication) |
||||
; |
||||
$em->persist($assignment); |
||||
$em->flush(); |
||||
$em->clear(); |
||||
|
||||
/** @var CStudentPublication $publication */ |
||||
$publication = $publicationRepo->find($publication->getIid()); |
||||
|
||||
$this->assertNotNull($publication->getAssignment()); |
||||
$this->assertSame(1, $assignmentRepo->count([])); |
||||
|
||||
$em->remove($publication); |
||||
$em->flush(); |
||||
|
||||
$this->assertSame(0, $assignmentRepo->count([])); |
||||
$this->assertSame(0, $publicationRepo->count([])); |
||||
} |
||||
} |
||||
@ -0,0 +1,64 @@ |
||||
<?php |
||||
|
||||
declare(strict_types=1); |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\Tests\CourseBundle\Repository; |
||||
|
||||
use Chamilo\CourseBundle\Entity\CStudentPublication; |
||||
use Chamilo\CourseBundle\Entity\CStudentPublicationComment; |
||||
use Chamilo\CourseBundle\Repository\CStudentPublicationCommentRepository; |
||||
use Chamilo\CourseBundle\Repository\CStudentPublicationRepository; |
||||
use Chamilo\Tests\AbstractApiTest; |
||||
use Chamilo\Tests\ChamiloTestTrait; |
||||
|
||||
class CStudentPublicationCommentRepositoryTest extends AbstractApiTest |
||||
{ |
||||
use ChamiloTestTrait; |
||||
|
||||
public function testCreate(): void |
||||
{ |
||||
$em = $this->getEntityManager(); |
||||
$publicationRepo = self::getContainer()->get(CStudentPublicationRepository::class); |
||||
$commentRepo = self::getContainer()->get(CStudentPublicationCommentRepository::class); |
||||
|
||||
$course = $this->createCourse('new'); |
||||
$teacher = $this->createUser('teacher'); |
||||
|
||||
$publication = (new CStudentPublication()) |
||||
->setTitle('publi') |
||||
->setDescription('desc') |
||||
->setParent($course) |
||||
->setFiletype('folder') |
||||
->setWeight(100) |
||||
->setCreator($teacher) |
||||
; |
||||
$em->persist($publication); |
||||
|
||||
$comment = (new CStudentPublicationComment()) |
||||
->setComment('comment') |
||||
->setUser($teacher) |
||||
->setPublication($publication) |
||||
->setParent($publication) |
||||
->setCreator($teacher) |
||||
->addCourseLink($course) |
||||
; |
||||
$em->persist($comment); |
||||
$em->flush(); |
||||
$em->clear(); |
||||
|
||||
/** @var CStudentPublication $publication */ |
||||
$publication = $publicationRepo->find($publication->getIid()); |
||||
|
||||
$this->assertSame(1, $publication->getComments()->count()); |
||||
$this->assertSame(1, $publicationRepo->count([])); |
||||
$this->assertSame(1, $commentRepo->count([])); |
||||
|
||||
$em->remove($publication); |
||||
$em->flush(); |
||||
|
||||
$this->assertSame(0, $publicationRepo->count([])); |
||||
$this->assertSame(0, $commentRepo->count([])); |
||||
} |
||||
} |
||||
@ -0,0 +1,66 @@ |
||||
<?php |
||||
|
||||
declare(strict_types=1); |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\Tests\CourseBundle\Repository; |
||||
|
||||
use Chamilo\CourseBundle\Entity\CStudentPublication; |
||||
use Chamilo\CourseBundle\Entity\CStudentPublicationCorrection; |
||||
use Chamilo\CourseBundle\Repository\CStudentPublicationCorrectionRepository; |
||||
use Chamilo\CourseBundle\Repository\CStudentPublicationRepository; |
||||
use Chamilo\Tests\AbstractApiTest; |
||||
use Chamilo\Tests\ChamiloTestTrait; |
||||
|
||||
class CStudentPublicationCorrectionRepositoryTest extends AbstractApiTest |
||||
{ |
||||
use ChamiloTestTrait; |
||||
|
||||
public function testCreate(): void |
||||
{ |
||||
$em = $this->getEntityManager(); |
||||
$publicationRepo = self::getContainer()->get(CStudentPublicationRepository::class); |
||||
$correctionRepo = self::getContainer()->get(CStudentPublicationCorrectionRepository::class); |
||||
|
||||
$course = $this->createCourse('new'); |
||||
$teacher = $this->createUser('teacher'); |
||||
|
||||
$publication = (new CStudentPublication()) |
||||
->setTitle('publi') |
||||
->setDescription('desc') |
||||
->setParent($course) |
||||
->setFiletype('folder') |
||||
->setWeight(100) |
||||
->setCreator($teacher) |
||||
; |
||||
$em->persist($publication); |
||||
|
||||
$file = $this->getUploadedFile(); |
||||
|
||||
$correction = (new CStudentPublicationCorrection()) |
||||
->setParent($publication) |
||||
->setCreator($teacher) |
||||
->setTitle($file->getClientOriginalName()) |
||||
; |
||||
$correctionRepo->create($correction); |
||||
$correctionRepo->addFile($correction, $file); |
||||
$correctionRepo->update($correction); |
||||
|
||||
$em->flush(); |
||||
$em->clear(); |
||||
|
||||
/** @var CStudentPublication $publication */ |
||||
$publication = $publicationRepo->find($publication->getIid()); |
||||
|
||||
$this->assertNotNull($publication->getCorrection()); |
||||
$this->assertSame(1, $publicationRepo->count([])); |
||||
$this->assertSame(1, $correctionRepo->count([])); |
||||
|
||||
$em->remove($publication); |
||||
$em->flush(); |
||||
|
||||
$this->assertSame(0, $publicationRepo->count([])); |
||||
$this->assertSame(0, $correctionRepo->count([])); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue