CStudentPublication: Add tests

pull/4037/head
Julio 4 years ago
parent 262b5e6156
commit 25bbcfddc3
  1. 6
      public/main/work/view.php
  2. 6
      public/main/work/work.lib.php
  3. 1
      src/CourseBundle/Repository/CShortcutRepository.php
  4. 63
      tests/CourseBundle/Repository/CStudentPublicationAssignmentRepositoryTest.php
  5. 64
      tests/CourseBundle/Repository/CStudentPublicationCommentRepositoryTest.php
  6. 66
      tests/CourseBundle/Repository/CStudentPublicationCorrectionRepositoryTest.php
  7. 46
      tests/CourseBundle/Repository/CStudentPublicationRepositoryTest.php
  8. 56
      tests/CourseBundle/Repository/CSurveyRepositoryTest.php

@ -160,10 +160,10 @@ if (($isDrhOfCourse || $allowEdition || $isDrhOfSession || user_is_author($id))
if (null !== $file) {
$em = Database::getManager();
$correction = new CStudentPublicationCorrection();
$correction
$correction = (new CStudentPublicationCorrection())
->setParent($work)
->setTitle($file->getClientOriginalName());
->setTitle($file->getClientOriginalName())
;
// @todo improve file upload.
$correctionRepo = Container::getStudentPublicationCorrectionRepository();
$correctionRepo->create($correction);

@ -4150,8 +4150,7 @@ function addWorkComment($courseInfo, $userId, $parentWork, CStudentPublication $
}
$em = Database::getManager();
$comment = new CStudentPublicationComment();
$comment
$comment = (new CStudentPublicationComment())
->setComment($data['comment'])
->setUser(api_get_user_entity($userId))
->setPublication($studentPublication)
@ -4160,7 +4159,8 @@ function addWorkComment($courseInfo, $userId, $parentWork, CStudentPublication $
$courseEntity,
api_get_session_entity(),
api_get_group_entity()
);
)
;
$repo = Container::getStudentPublicationCommentRepository();
$repo->create($comment);

@ -6,7 +6,6 @@ declare(strict_types=1);
namespace Chamilo\CourseBundle\Repository;
use Chamilo\CoreBundle\Entity\AbstractResource;
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\ResourceInterface;
use Chamilo\CoreBundle\Entity\Session;

@ -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([]));
}
}

@ -10,6 +10,7 @@ use Chamilo\CourseBundle\Entity\CStudentPublication;
use Chamilo\CourseBundle\Repository\CStudentPublicationRepository;
use Chamilo\Tests\AbstractApiTest;
use Chamilo\Tests\ChamiloTestTrait;
use DateTime;
class CStudentPublicationRepositoryTest extends AbstractApiTest
{
@ -25,6 +26,21 @@ class CStudentPublicationRepositoryTest extends AbstractApiTest
$item = (new CStudentPublication())
->setTitle('publi')
->setDescription('desc')
->setAuthor('author')
->setAccepted(false)
->setPostGroupId(0)
->setSentDate(new DateTime())
->setHasProperties(0)
->setViewProperties(false)
->setQualification(0)
->setDateOfQualification(new DateTime())
->setQualificatorId(0)
->setAllowTextAssignment(0)
->setContainsFile(0)
->setDocumentId(0)
->setFileSize(0)
->setAssignment(null)
->setParent($course)
->setFiletype('folder')
->setWeight(100)
@ -38,6 +54,28 @@ class CStudentPublicationRepositoryTest extends AbstractApiTest
$this->assertSame(1, $repo->count([]));
}
public function testCreateWithAssignment(): void
{
$em = $this->getEntityManager();
$repo = self::getContainer()->get(CStudentPublicationRepository::class);
$course = $this->createCourse('new');
$teacher = $this->createUser('teacher');
$item = (new CStudentPublication())
->setTitle('publi')
->setDescription('desc')
->setParent($course)
->setFiletype('folder')
->setWeight(100)
->setCreator($teacher)
;
$em->persist($item);
$em->flush();
$this->assertSame(1, $repo->count([]));
}
public function testFindAllByCourse(): void
{
$em = $this->getEntityManager();
@ -46,7 +84,7 @@ class CStudentPublicationRepositoryTest extends AbstractApiTest
$course = $this->createCourse('new');
$qb = $repo->findAllByCourse($course);
$this->assertSame(0, \count($qb->getQuery()->getResult()));
$this->assertCount(0, $qb->getQuery()->getResult());
$teacher = $this->createUser('teacher');
@ -62,7 +100,7 @@ class CStudentPublicationRepositoryTest extends AbstractApiTest
$em->flush();
$qb = $repo->findAllByCourse($course);
$this->assertSame(1, \count($qb->getQuery()->getResult()));
$this->assertCount(1, $qb->getQuery()->getResult());
}
public function testGetStudentAssignments(): void
@ -86,7 +124,7 @@ class CStudentPublicationRepositoryTest extends AbstractApiTest
$em->flush();
$qb = $repo->getStudentAssignments($item, $course);
$this->assertSame(0, \count($qb->getQuery()->getResult()));
$this->assertCount(0, $qb->getQuery()->getResult());
$studentResult = (new CStudentPublication())
->setTitle('work from student')
@ -102,7 +140,7 @@ class CStudentPublicationRepositoryTest extends AbstractApiTest
$em->flush();
$qb = $repo->getStudentAssignments($item, $course);
$this->assertSame(1, \count($qb->getQuery()->getResult()));
$this->assertCount(1, $qb->getQuery()->getResult());
//$this->assertSame(1, $repo->countUserPublications($student, $course));
//$this->assertSame(1, $repo->findWorksByTeacher($teacher, $course));

@ -10,6 +10,7 @@ use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Repository\Node\CourseRepository;
use Chamilo\CourseBundle\Entity\CSurvey;
use Chamilo\CourseBundle\Entity\CSurveyAnswer;
use Chamilo\CourseBundle\Entity\CSurveyInvitation;
use Chamilo\CourseBundle\Entity\CSurveyQuestion;
use Chamilo\CourseBundle\Entity\CSurveyQuestionOption;
use Chamilo\CourseBundle\Repository\CSurveyAnswerRepository;
@ -17,6 +18,7 @@ use Chamilo\CourseBundle\Repository\CSurveyQuestionRepository;
use Chamilo\CourseBundle\Repository\CSurveyRepository;
use Chamilo\Tests\AbstractApiTest;
use Chamilo\Tests\ChamiloTestTrait;
use DateTime;
class CSurveyRepositoryTest extends AbstractApiTest
{
@ -33,6 +35,21 @@ class CSurveyRepositoryTest extends AbstractApiTest
$survey = (new CSurvey())
->setTitle('survey')
->setCode('survey')
->setSubtitle('subtitle')
->setSurveythanks('thanks')
->setIsMandatory(false)
->setSurveyType(1)
->setSurveyVersion('v1')
->setAccessCondition('condition')
->setShuffle(false)
->setTemplate('tpl')
->setAnonymous('0')
->setVisibleResults(1)
->setReminderMail('reminder')
->setRgt(1)
->setMailSubject('subject')
->setInviteMail('invite')
->setLang('lang')
->setParent($course)
->setCreator($teacher)
;
@ -53,9 +70,12 @@ class CSurveyRepositoryTest extends AbstractApiTest
$surveyRepo = self::getContainer()->get(CSurveyRepository::class);
$surveyQuestionRepo = self::getContainer()->get(CSurveyQuestionRepository::class);
$surveyAnswerRepo = self::getContainer()->get(CSurveyAnswerRepository::class);
$surveyInvitationRepo = $em->getRepository(CSurveyInvitation::class);
$surveyOptionRepo = $em->getRepository(CSurveyQuestionOption::class);
$course = $this->createCourse('new');
$teacher = $this->createUser('teacher');
$student = $this->createUser('student');
$survey = (new CSurvey())
->setTitle('survey')
@ -82,17 +102,20 @@ class CSurveyRepositoryTest extends AbstractApiTest
;
$this->assertHasNoEntityViolations($question);
$em->persist($question);
$em->flush();
$questionOption = (new CSurveyQuestionOption())
$option = (new CSurveyQuestionOption())
->setSurvey($survey)
->setQuestion($question)
->setOptionText('text')
->setValue(1)
->setSurvey($survey)
->setSort(1)
->setOptionText('option text')
;
$this->assertHasNoEntityViolations($questionOption);
$em->persist($questionOption);
$em->persist($option);
$this->assertHasNoEntityViolations($option);
$em->flush();
$this->assertSame('hola?', $question->getSurveyQuestion());
$em->flush();
$answer = (new CSurveyAnswer())
@ -104,8 +127,21 @@ class CSurveyRepositoryTest extends AbstractApiTest
;
$this->assertHasNoEntityViolations($answer);
$em->persist($answer);
$em->flush();
$invitation = (new CSurveyInvitation())
->setCourse($course)
->setUser($student)
->setGroup(null)
->setSession(null)
->setSurvey($survey)
->setInvitationCode('code')
->setInvitationDate(new DateTime())
->setAnswered(0)
->setReminderDate(new DateTime())
;
$em->persist($invitation);
$em->flush();
$em->clear();
/** @var CSurvey $survey */
@ -113,6 +149,7 @@ class CSurveyRepositoryTest extends AbstractApiTest
/** @var CSurveyQuestion $question */
$question = $surveyQuestionRepo->find($question->getIid());
$this->assertSame(1, $survey->getInvitations()->count());
$this->assertSame(1, $survey->getQuestions()->count());
$this->assertSame(1, $question->getOptions()->count());
$this->assertSame(1, $question->getAnswers()->count());
@ -120,7 +157,8 @@ class CSurveyRepositoryTest extends AbstractApiTest
$this->assertSame(1, $surveyRepo->count([]));
$this->assertSame(1, $surveyQuestionRepo->count([]));
$this->assertSame(1, $surveyAnswerRepo->count([]));
$this->assertSame(1, $surveyInvitationRepo->count([]));
$this->assertSame(1, $surveyOptionRepo->count([]));
$this->assertSame(1, $courseRepo->count([]));
/** @var Course $course */
@ -131,5 +169,7 @@ class CSurveyRepositoryTest extends AbstractApiTest
$this->assertSame(0, $surveyRepo->count([]));
$this->assertSame(0, $surveyQuestionRepo->count([]));
$this->assertSame(0, $surveyAnswerRepo->count([]));
$this->assertSame(0, $surveyInvitationRepo->count([]));
$this->assertSame(0, $surveyOptionRepo->count([]));
}
}

Loading…
Cancel
Save