Tests: Add phpunit tests, entities: set default values in construct

pull/3959/head
Julio 4 years ago
parent 6d015e52ec
commit 1bbb516973
  1. 1
      public/main/forum/forumfunction.inc.php
  2. 2
      public/main/inc/lib/tracking.lib.php
  3. 3
      public/main/survey/survey.lib.php
  4. 8
      src/CoreBundle/Entity/Asset.php
  5. 22
      src/CourseBundle/Entity/CForum.php
  6. 1
      src/CourseBundle/Entity/CForumCategory.php
  7. 13
      src/CourseBundle/Entity/CStudentPublication.php
  8. 4
      src/CourseBundle/Entity/CSurvey.php
  9. 4
      src/CourseBundle/Entity/CThematic.php
  10. 2
      tests/CourseBundle/Repository/CAnnouncementAttachmentRepositoryTest.php
  11. 2
      tests/CourseBundle/Repository/CAnnouncementRepositoryTest.php
  12. 2
      tests/CourseBundle/Repository/CAttendanceRepositoryTest.php
  13. 48
      tests/CourseBundle/Repository/CForumCategoryRepositoryTest.php
  14. 46
      tests/CourseBundle/Repository/CForumRepositoryTest.php
  15. 2
      tests/CourseBundle/Repository/CGroupCategoryRepositoryTest.php
  16. 47
      tests/CourseBundle/Repository/CLinkCategoryRepositoryTest.php
  17. 46
      tests/CourseBundle/Repository/CLinkRepositoryTest.php
  18. 2
      tests/CourseBundle/Repository/CLpCategoryRepositoryTest.php
  19. 2
      tests/CourseBundle/Repository/CLpRepositoryTest.php
  20. 44
      tests/CourseBundle/Repository/CQuizRepositoryTest.php
  21. 48
      tests/CourseBundle/Repository/CStudentPublicationRepositoryTest.php
  22. 44
      tests/CourseBundle/Repository/CSurveyRepositoryTest.php
  23. 46
      tests/CourseBundle/Repository/CThematicRepositoryTest.php

@ -813,7 +813,6 @@ function store_forum($values, $courseInfo = [], $returnId = false)
->setModerated((bool) ($values['moderated']['moderated'] ?? false)) ->setModerated((bool) ($values['moderated']['moderated'] ?? false))
->setStartTime(!empty($values['start_time']) ? api_get_utc_datetime($values['start_time'], true, true) : null) ->setStartTime(!empty($values['start_time']) ? api_get_utc_datetime($values['start_time'], true, true) : null)
->setEndTime(!empty($values['end_time']) ? api_get_utc_datetime($values['end_time'], true, true) : null) ->setEndTime(!empty($values['end_time']) ? api_get_utc_datetime($values['end_time'], true, true) : null)
->setSessionId($session_id)
->setLp($lp) ->setLp($lp)
; ;

@ -7435,8 +7435,6 @@ class Tracking
$data['post_group_id'] = (int) $data['post_group_id']; $data['post_group_id'] = (int) $data['post_group_id'];
$publication = new CStudentPublication(); $publication = new CStudentPublication();
$publication $publication
->setUrl($new_url)
->setCId($course_id)
->setTitle($data['title']) ->setTitle($data['title'])
->setDescription($data['description'].' file moved') ->setDescription($data['description'].' file moved')
->setActive($data['active']) ->setActive($data['active'])

@ -261,9 +261,6 @@ class SurveyManager
$extraParams['form_fields'] = ''; $extraParams['form_fields'] = '';
} }
$survey->setFormFields($extraParams['form_fields']); $survey->setFormFields($extraParams['form_fields']);
} else {
$survey->setShowFormProfile(0);
$survey->setFormFields(0);
} }
$extraParams['one_question_per_page'] = isset($values['one_question_per_page']) ? $values['one_question_per_page'] : 0; $extraParams['one_question_per_page'] = isset($values['one_question_per_page']) ? $values['one_question_per_page'] : 0;

@ -42,17 +42,12 @@ class Asset
protected int $id; protected int $id;
/** /**
* @Assert\NotBlank()
*
* @ORM\Column(type="string", length=255) * @ORM\Column(type="string", length=255)
*/ */
#[Assert\NotBlank]
protected ?string $title = null; protected ?string $title = null;
/** /**
* @todo use attributes
*
* @Assert\NotBlank()
*
* @Assert\Choice({ * @Assert\Choice({
* Asset::SCORM, * Asset::SCORM,
* Asset::WATERMARK, * Asset::WATERMARK,
@ -64,6 +59,7 @@ class Asset
* *
* @ORM\Column(type="string", length=255) * @ORM\Column(type="string", length=255)
*/ */
#[Assert\NotBlank]
protected ?string $category = null; protected ?string $category = null;
/** /**

@ -122,11 +122,6 @@ class CForum extends AbstractResource implements ResourceInterface
*/ */
protected int $locked; protected int $locked;
/**
* @ORM\Column(name="session_id", type="integer", nullable=false)
*/
protected int $sessionId;
/** /**
* @ORM\Column(name="forum_image", type="string", length=255, nullable=false) * @ORM\Column(name="forum_image", type="string", length=255, nullable=false)
*/ */
@ -432,23 +427,6 @@ class CForum extends AbstractResource implements ResourceInterface
return $this->locked; return $this->locked;
} }
public function setSessionId(int $sessionId): self
{
$this->sessionId = $sessionId;
return $this;
}
/**
* Get sessionId.
*
* @return int
*/
public function getSessionId()
{
return $this->sessionId;
}
public function setForumImage(string $forumImage): self public function setForumImage(string $forumImage): self
{ {
$this->forumImage = $forumImage; $this->forumImage = $forumImage;

@ -64,6 +64,7 @@ class CForumCategory extends AbstractResource implements ResourceInterface
{ {
$this->catComment = ''; $this->catComment = '';
$this->locked = 0; $this->locked = 0;
$this->catOrder = 0;
$this->forums = new ArrayCollection(); $this->forums = new ArrayCollection();
} }

@ -36,9 +36,9 @@ class CStudentPublication extends AbstractResource implements ResourceInterface
protected int $iid; protected int $iid;
/** /**
* @Assert\NotBlank()
* @ORM\Column(name="title", type="string", length=255, nullable=false) * @ORM\Column(name="title", type="string", length=255, nullable=false)
*/ */
#[Assert\NotBlank]
protected string $title; protected string $title;
/** /**
@ -74,6 +74,8 @@ class CStudentPublication extends AbstractResource implements ResourceInterface
/** /**
* @ORM\Column(name="filetype", type="string", length=10, nullable=false) * @ORM\Column(name="filetype", type="string", length=10, nullable=false)
*/ */
#[Assert\NotBlank]
#[Assert\Choice(callback: 'getFileTypes')]
protected string $filetype; protected string $filetype;
/** /**
@ -133,6 +135,7 @@ class CStudentPublication extends AbstractResource implements ResourceInterface
/** /**
* @ORM\Column(name="weight", type="float", precision=6, scale=2, nullable=false) * @ORM\Column(name="weight", type="float", precision=6, scale=2, nullable=false)
*/ */
#[Assert\NotBlank]
protected float $weight; protected float $weight;
/** /**
@ -165,6 +168,9 @@ class CStudentPublication extends AbstractResource implements ResourceInterface
$this->qualificatorId = 0; $this->qualificatorId = 0;
$this->qualification = 0; $this->qualification = 0;
$this->assignment = null; $this->assignment = null;
$this->postGroupId = 0;
$this->allowTextAssignment = 0;
$this->filetype = 'folder';
$this->sentDate = new DateTime(); $this->sentDate = new DateTime();
$this->children = new ArrayCollection(); $this->children = new ArrayCollection();
$this->comments = new ArrayCollection(); $this->comments = new ArrayCollection();
@ -175,6 +181,11 @@ class CStudentPublication extends AbstractResource implements ResourceInterface
return $this->getTitle(); return $this->getTitle();
} }
public function getFileTypes(): array
{
return ['file', 'folder'];
}
/** /**
* Get iid. * Get iid.
* *

@ -121,6 +121,7 @@ class CSurvey extends AbstractResource implements ResourceInterface
/** /**
* @ORM\Column(name="anonymous", type="string", length=10, nullable=false) * @ORM\Column(name="anonymous", type="string", length=10, nullable=false)
*/ */
#[Assert\NotBlank]
protected string $anonymous; protected string $anonymous;
/** /**
@ -227,6 +228,8 @@ class CSurvey extends AbstractResource implements ResourceInterface
$this->creationDate = new DateTime(); $this->creationDate = new DateTime();
$this->invited = 0; $this->invited = 0;
$this->answered = 0; $this->answered = 0;
$this->anonymous = '0';
$this->formFields = '0';
$this->subtitle = ''; $this->subtitle = '';
$this->inviteMail = ''; $this->inviteMail = '';
$this->lang = ''; $this->lang = '';
@ -236,6 +239,7 @@ class CSurvey extends AbstractResource implements ResourceInterface
$this->oneQuestionPerPage = false; $this->oneQuestionPerPage = false;
$this->surveyVersion = ''; $this->surveyVersion = '';
$this->surveyType = 0; $this->surveyType = 0;
$this->showFormProfile = 0;
$this->questions = new ArrayCollection(); $this->questions = new ArrayCollection();
$this->children = new ArrayCollection(); $this->children = new ArrayCollection();
$this->invitations = new ArrayCollection(); $this->invitations = new ArrayCollection();

@ -34,10 +34,9 @@ class CThematic extends AbstractResource implements ResourceInterface
protected int $iid; protected int $iid;
/** /**
* @Assert\NotBlank()
*
* @ORM\Column(name="title", type="text", nullable=false) * @ORM\Column(name="title", type="text", nullable=false)
*/ */
#[Assert\NotBlank]
protected string $title; protected string $title;
/** /**
@ -80,6 +79,7 @@ class CThematic extends AbstractResource implements ResourceInterface
$this->plans = new ArrayCollection(); $this->plans = new ArrayCollection();
$this->advances = new ArrayCollection(); $this->advances = new ArrayCollection();
$this->active = true; $this->active = true;
$this->displayOrder = 0;
} }
public function __toString(): string public function __toString(): string

@ -21,7 +21,7 @@ class CAnnouncementAttachmentRepositoryTest extends AbstractApiTest
{ {
self::bootKernel(); self::bootKernel();
$em = self::getContainer()->get('doctrine')->getManager(); $em = $this->getManager();
$repo = self::getContainer()->get(CAnnouncementRepository::class); $repo = self::getContainer()->get(CAnnouncementRepository::class);
$repoAttachment = self::getContainer()->get(CAnnouncementAttachmentRepository::class); $repoAttachment = self::getContainer()->get(CAnnouncementAttachmentRepository::class);

@ -19,7 +19,7 @@ class CAnnouncementRepositoryTest extends AbstractApiTest
{ {
self::bootKernel(); self::bootKernel();
$em = self::getContainer()->get('doctrine')->getManager(); $em = $this->getManager();
$repo = self::getContainer()->get(CAnnouncementRepository::class); $repo = self::getContainer()->get(CAnnouncementRepository::class);
$course = $this->createCourse('new'); $course = $this->createCourse('new');

@ -19,7 +19,7 @@ class CAttendanceRepositoryTest extends AbstractApiTest
{ {
self::bootKernel(); self::bootKernel();
$em = self::getContainer()->get('doctrine')->getManager(); $em = $this->getManager();
$repo = self::getContainer()->get(CAttendanceRepository::class); $repo = self::getContainer()->get(CAttendanceRepository::class);
$course = $this->createCourse('new'); $course = $this->createCourse('new');

@ -0,0 +1,48 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\Tests\CourseBundle\Repository;
use Chamilo\CourseBundle\Entity\CForum;
use Chamilo\CourseBundle\Entity\CForumCategory;
use Chamilo\CourseBundle\Entity\CLp;
use Chamilo\CourseBundle\Entity\CQuiz;
use Chamilo\CourseBundle\Entity\CSurvey;
use Chamilo\CourseBundle\Repository\CForumCategoryRepository;
use Chamilo\CourseBundle\Repository\CForumRepository;
use Chamilo\CourseBundle\Repository\CLpRepository;
use Chamilo\CourseBundle\Repository\CQuizRepository;
use Chamilo\CourseBundle\Repository\CSurveyRepository;
use Chamilo\Tests\AbstractApiTest;
use Chamilo\Tests\ChamiloTestTrait;
class CForumCategoryRepositoryTest extends AbstractApiTest
{
use ChamiloTestTrait;
public function testCreate(): void
{
self::bootKernel();
$em = $this->getManager();
$repo = self::getContainer()->get(CForumCategoryRepository::class);
$course = $this->createCourse('new');
$teacher = $this->createUser('teacher');
$item = (new CForumCategory())
->setCatTitle('cat')
->setParent($course)
->setCreator($teacher)
;
$this->assertHasNoEntityViolations($item);
$em->persist($item);
$em->flush();
$this->assertSame('cat', (string) $item);
$this->assertSame(1, $repo->count([]));
}
}

@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\Tests\CourseBundle\Repository;
use Chamilo\CourseBundle\Entity\CForum;
use Chamilo\CourseBundle\Entity\CLp;
use Chamilo\CourseBundle\Entity\CQuiz;
use Chamilo\CourseBundle\Entity\CSurvey;
use Chamilo\CourseBundle\Repository\CForumRepository;
use Chamilo\CourseBundle\Repository\CLpRepository;
use Chamilo\CourseBundle\Repository\CQuizRepository;
use Chamilo\CourseBundle\Repository\CSurveyRepository;
use Chamilo\Tests\AbstractApiTest;
use Chamilo\Tests\ChamiloTestTrait;
class CForumRepositoryTest extends AbstractApiTest
{
use ChamiloTestTrait;
public function testCreate(): void
{
self::bootKernel();
$em = $this->getManager();
$repo = self::getContainer()->get(CForumRepository::class);
$course = $this->createCourse('new');
$teacher = $this->createUser('teacher');
$item = (new CForum())
->setForumTitle('forum')
->setParent($course)
->setCreator($teacher)
;
$this->assertHasNoEntityViolations($item);
$em->persist($item);
$em->flush();
$this->assertSame('forum', (string) $item);
$this->assertSame(1, $repo->count([]));
}
}

@ -19,7 +19,7 @@ class CGroupCategoryRepositoryTest extends AbstractApiTest
{ {
self::bootKernel(); self::bootKernel();
$em = self::getContainer()->get('doctrine')->getManager(); $em = $this->getManager();
$repo = self::getContainer()->get(CGroupCategoryRepository::class); $repo = self::getContainer()->get(CGroupCategoryRepository::class);
$course = $this->createCourse('new'); $course = $this->createCourse('new');

@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\Tests\CourseBundle\Repository;
use Chamilo\CourseBundle\Entity\CLink;
use Chamilo\CourseBundle\Entity\CLinkCategory;
use Chamilo\CourseBundle\Entity\CLp;
use Chamilo\CourseBundle\Entity\CSurvey;
use Chamilo\CourseBundle\Repository\CLinkCategoryRepository;
use Chamilo\CourseBundle\Repository\CLinkRepository;
use Chamilo\CourseBundle\Repository\CLpRepository;
use Chamilo\CourseBundle\Repository\CSurveyRepository;
use Chamilo\Tests\AbstractApiTest;
use Chamilo\Tests\ChamiloTestTrait;
class CLinkCategoryRepositoryTest extends AbstractApiTest
{
use ChamiloTestTrait;
public function testCreate(): void
{
self::bootKernel();
$em = $this->getManager();
$repo = self::getContainer()->get(CLinkCategoryRepository::class);
$course = $this->createCourse('new');
$teacher = $this->createUser('teacher');
$item = (new CLinkCategory())
->setCategoryTitle('cat')
->setParent($course)
->setCreator($teacher)
;
$this->assertHasNoEntityViolations($item);
$em->persist($item);
$em->flush();
$this->assertSame('cat', (string) $item);
$this->assertSame(1, $repo->count([]));
}
}

@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\Tests\CourseBundle\Repository;
use Chamilo\CourseBundle\Entity\CLink;
use Chamilo\CourseBundle\Entity\CLp;
use Chamilo\CourseBundle\Entity\CSurvey;
use Chamilo\CourseBundle\Repository\CLinkRepository;
use Chamilo\CourseBundle\Repository\CLpRepository;
use Chamilo\CourseBundle\Repository\CSurveyRepository;
use Chamilo\Tests\AbstractApiTest;
use Chamilo\Tests\ChamiloTestTrait;
class CLinkRepositoryTest extends AbstractApiTest
{
use ChamiloTestTrait;
public function testCreate(): void
{
self::bootKernel();
$em = $this->getManager();
$repo = self::getContainer()->get(CLinkRepository::class);
$course = $this->createCourse('new');
$teacher = $this->createUser('teacher');
$item = (new CLink())
->setUrl('https://chamilo.org')
->setTitle('link')
->setParent($course)
->setCreator($teacher)
;
$this->assertHasNoEntityViolations($item);
$em->persist($item);
$em->flush();
$this->assertSame('link', (string) $item);
$this->assertSame(1, $repo->count([]));
}
}

@ -19,7 +19,7 @@ class CLpCategoryRepositoryTest extends AbstractApiTest
{ {
self::bootKernel(); self::bootKernel();
$em = self::getContainer()->get('doctrine')->getManager(); $em = $this->getManager();
$repo = self::getContainer()->get(CLpCategoryRepository::class); $repo = self::getContainer()->get(CLpCategoryRepository::class);
$course = $this->createCourse('new'); $course = $this->createCourse('new');

@ -19,7 +19,7 @@ class CLpRepositoryTest extends AbstractApiTest
{ {
self::bootKernel(); self::bootKernel();
$em = self::getContainer()->get('doctrine')->getManager(); $em = $this->getManager();
$repo = self::getContainer()->get(CLpRepository::class); $repo = self::getContainer()->get(CLpRepository::class);
$course = $this->createCourse('new'); $course = $this->createCourse('new');

@ -0,0 +1,44 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\Tests\CourseBundle\Repository;
use Chamilo\CourseBundle\Entity\CLp;
use Chamilo\CourseBundle\Entity\CQuiz;
use Chamilo\CourseBundle\Entity\CSurvey;
use Chamilo\CourseBundle\Repository\CLpRepository;
use Chamilo\CourseBundle\Repository\CQuizRepository;
use Chamilo\CourseBundle\Repository\CSurveyRepository;
use Chamilo\Tests\AbstractApiTest;
use Chamilo\Tests\ChamiloTestTrait;
class CQuizRepositoryTest extends AbstractApiTest
{
use ChamiloTestTrait;
public function testCreate(): void
{
self::bootKernel();
$em = $this->getManager();
$repo = self::getContainer()->get(CQuizRepository::class);
$course = $this->createCourse('new');
$teacher = $this->createUser('teacher');
$item = (new CQuiz())
->setTitle('exercise')
->setParent($course)
->setCreator($teacher)
;
$this->assertHasNoEntityViolations($item);
$em->persist($item);
$em->flush();
$this->assertSame('exercise', (string) $item);
$this->assertSame(1, $repo->count([]));
}
}

@ -0,0 +1,48 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\Tests\CourseBundle\Repository;
use Chamilo\CourseBundle\Entity\CLp;
use Chamilo\CourseBundle\Entity\CQuiz;
use Chamilo\CourseBundle\Entity\CStudentPublication;
use Chamilo\CourseBundle\Entity\CSurvey;
use Chamilo\CourseBundle\Repository\CLpRepository;
use Chamilo\CourseBundle\Repository\CQuizRepository;
use Chamilo\CourseBundle\Repository\CStudentPublicationRepository;
use Chamilo\CourseBundle\Repository\CSurveyRepository;
use Chamilo\Tests\AbstractApiTest;
use Chamilo\Tests\ChamiloTestTrait;
class CStudentPublicationRepositoryTest extends AbstractApiTest
{
use ChamiloTestTrait;
public function testCreate(): void
{
self::bootKernel();
$em = $this->getManager();
$repo = self::getContainer()->get(CStudentPublicationRepository::class);
$course = $this->createCourse('new');
$teacher = $this->createUser('teacher');
$item = (new CStudentPublication())
->setTitle('publi')
->setParent($course)
->setFiletype('folder')
->setWeight(100)
->setCreator($teacher)
;
$this->assertHasNoEntityViolations($item);
$em->persist($item);
$em->flush();
$this->assertSame('publi', (string) $item);
$this->assertSame(1, $repo->count([]));
}
}

@ -0,0 +1,44 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\Tests\CourseBundle\Repository;
use Chamilo\CourseBundle\Entity\CLp;
use Chamilo\CourseBundle\Entity\CSurvey;
use Chamilo\CourseBundle\Repository\CLpRepository;
use Chamilo\CourseBundle\Repository\CSurveyRepository;
use Chamilo\Tests\AbstractApiTest;
use Chamilo\Tests\ChamiloTestTrait;
class CSurveyRepositoryTest extends AbstractApiTest
{
use ChamiloTestTrait;
public function testCreate(): void
{
self::bootKernel();
$em = $this->getManager();
$repo = self::getContainer()->get(CSurveyRepository::class);
$course = $this->createCourse('new');
$teacher = $this->createUser('teacher');
$item = (new CSurvey())
->setTitle('survey')
->setCode('survey')
->setParent($course)
->setCreator($teacher)
;
$this->assertHasNoEntityViolations($item);
$em->persist($item);
$em->flush();
$this->assertSame('survey', (string) $item);
$this->assertSame(1, $repo->count([]));
}
}

@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\Tests\CourseBundle\Repository;
use Chamilo\CourseBundle\Entity\CLp;
use Chamilo\CourseBundle\Entity\CQuiz;
use Chamilo\CourseBundle\Entity\CSurvey;
use Chamilo\CourseBundle\Entity\CThematic;
use Chamilo\CourseBundle\Repository\CLpRepository;
use Chamilo\CourseBundle\Repository\CQuizRepository;
use Chamilo\CourseBundle\Repository\CSurveyRepository;
use Chamilo\CourseBundle\Repository\CThematicRepository;
use Chamilo\Tests\AbstractApiTest;
use Chamilo\Tests\ChamiloTestTrait;
class CThematicRepositoryTest extends AbstractApiTest
{
use ChamiloTestTrait;
public function testCreate(): void
{
self::bootKernel();
$em = $this->getManager();
$repo = self::getContainer()->get(CThematicRepository::class);
$course = $this->createCourse('new');
$teacher = $this->createUser('teacher');
$item = (new CThematic())
->setTitle('thematic')
->setParent($course)
->setCreator($teacher)
;
$this->assertHasNoEntityViolations($item);
$em->persist($item);
$em->flush();
$this->assertSame('thematic', (string) $item);
$this->assertSame(1, $repo->count([]));
}
}
Loading…
Cancel
Save