|
|
@ -7,13 +7,16 @@ declare(strict_types=1); |
|
|
|
namespace Chamilo\Tests\CourseBundle\Repository; |
|
|
|
namespace Chamilo\Tests\CourseBundle\Repository; |
|
|
|
|
|
|
|
|
|
|
|
use Chamilo\CourseBundle\Entity\CForum; |
|
|
|
use Chamilo\CourseBundle\Entity\CForum; |
|
|
|
|
|
|
|
use Chamilo\CourseBundle\Entity\CForumAttachment; |
|
|
|
use Chamilo\CourseBundle\Entity\CForumPost; |
|
|
|
use Chamilo\CourseBundle\Entity\CForumPost; |
|
|
|
use Chamilo\CourseBundle\Entity\CForumThread; |
|
|
|
use Chamilo\CourseBundle\Entity\CForumThread; |
|
|
|
|
|
|
|
use Chamilo\CourseBundle\Repository\CForumAttachmentRepository; |
|
|
|
use Chamilo\CourseBundle\Repository\CForumPostRepository; |
|
|
|
use Chamilo\CourseBundle\Repository\CForumPostRepository; |
|
|
|
use Chamilo\CourseBundle\Repository\CForumRepository; |
|
|
|
use Chamilo\CourseBundle\Repository\CForumRepository; |
|
|
|
use Chamilo\CourseBundle\Repository\CForumThreadRepository; |
|
|
|
use Chamilo\CourseBundle\Repository\CForumThreadRepository; |
|
|
|
use Chamilo\Tests\AbstractApiTest; |
|
|
|
use Chamilo\Tests\AbstractApiTest; |
|
|
|
use Chamilo\Tests\ChamiloTestTrait; |
|
|
|
use Chamilo\Tests\ChamiloTestTrait; |
|
|
|
|
|
|
|
use DateTime; |
|
|
|
|
|
|
|
|
|
|
|
class CForumPostRepositoryTest extends AbstractApiTest |
|
|
|
class CForumPostRepositoryTest extends AbstractApiTest |
|
|
|
{ |
|
|
|
{ |
|
|
@ -21,13 +24,13 @@ class CForumPostRepositoryTest extends AbstractApiTest |
|
|
|
|
|
|
|
|
|
|
|
public function testCreate(): void |
|
|
|
public function testCreate(): void |
|
|
|
{ |
|
|
|
{ |
|
|
|
self::bootKernel(); |
|
|
|
|
|
|
|
$course = $this->createCourse('new'); |
|
|
|
$course = $this->createCourse('new'); |
|
|
|
$teacher = $this->createUser('teacher'); |
|
|
|
$teacher = $this->createUser('teacher'); |
|
|
|
|
|
|
|
|
|
|
|
$forumRepo = self::getContainer()->get(CForumRepository::class); |
|
|
|
$forumRepo = self::getContainer()->get(CForumRepository::class); |
|
|
|
$threadRepo = self::getContainer()->get(CForumThreadRepository::class); |
|
|
|
$threadRepo = self::getContainer()->get(CForumThreadRepository::class); |
|
|
|
$postRepo = self::getContainer()->get(CForumPostRepository::class); |
|
|
|
$postRepo = self::getContainer()->get(CForumPostRepository::class); |
|
|
|
|
|
|
|
$attachmentRepo = self::getContainer()->get(CForumAttachmentRepository::class); |
|
|
|
|
|
|
|
|
|
|
|
$forum = (new CForum()) |
|
|
|
$forum = (new CForum()) |
|
|
|
->setForumTitle('forum') |
|
|
|
->setForumTitle('forum') |
|
|
@ -46,6 +49,12 @@ class CForumPostRepositoryTest extends AbstractApiTest |
|
|
|
|
|
|
|
|
|
|
|
$post = (new CForumPost()) |
|
|
|
$post = (new CForumPost()) |
|
|
|
->setPostTitle('post') |
|
|
|
->setPostTitle('post') |
|
|
|
|
|
|
|
->setPostText('text') |
|
|
|
|
|
|
|
->setPostDate(new DateTime()) |
|
|
|
|
|
|
|
->setPostNotification(true) |
|
|
|
|
|
|
|
->setVisible(true) |
|
|
|
|
|
|
|
->setStatus(1) |
|
|
|
|
|
|
|
->setPostParent(null) |
|
|
|
->setParent($course) |
|
|
|
->setParent($course) |
|
|
|
->setCreator($teacher) |
|
|
|
->setCreator($teacher) |
|
|
|
->setThread($thread) |
|
|
|
->setThread($thread) |
|
|
@ -53,10 +62,38 @@ class CForumPostRepositoryTest extends AbstractApiTest |
|
|
|
->setUser($teacher) |
|
|
|
->setUser($teacher) |
|
|
|
; |
|
|
|
; |
|
|
|
$postRepo->create($post); |
|
|
|
$postRepo->create($post); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$file = $this->getUploadedFile(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$attachment = (new CForumAttachment()) |
|
|
|
|
|
|
|
->setComment('comment') |
|
|
|
|
|
|
|
->setCId($course->getId()) |
|
|
|
|
|
|
|
->setFilename($file->getFilename()) |
|
|
|
|
|
|
|
->setPath('') |
|
|
|
|
|
|
|
->setPost($post) |
|
|
|
|
|
|
|
->setSize($file->getSize()) |
|
|
|
|
|
|
|
->setParent($post) |
|
|
|
|
|
|
|
->setCreator($teacher) |
|
|
|
|
|
|
|
->addCourseLink($course) |
|
|
|
|
|
|
|
; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$attachmentRepo->create($attachment); |
|
|
|
|
|
|
|
$attachmentRepo->addFile($attachment, $file); |
|
|
|
|
|
|
|
$attachmentRepo->update($attachment); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertNotNull($attachment->getResourceNode()); |
|
|
|
|
|
|
|
$this->assertNotNull($attachment->getResourceNode()->getResourceFile()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->getEntityManager()->clear(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$post = $postRepo->find($post->getIid()); |
|
|
|
|
|
|
|
|
|
|
|
$this->assertSame('post', (string) $post); |
|
|
|
$this->assertSame('post', (string) $post); |
|
|
|
|
|
|
|
$this->assertSame(1, $post->getAttachments()->count()); |
|
|
|
$this->assertSame(1, $postRepo->count([])); |
|
|
|
$this->assertSame(1, $postRepo->count([])); |
|
|
|
$this->assertSame(1, $threadRepo->count([])); |
|
|
|
$this->assertSame(1, $threadRepo->count([])); |
|
|
|
$this->assertSame(1, $forumRepo->count([])); |
|
|
|
$this->assertSame(1, $forumRepo->count([])); |
|
|
|
|
|
|
|
$this->assertSame(1, $attachmentRepo->count([])); |
|
|
|
|
|
|
|
|
|
|
|
/** @var CForumThread $thread */ |
|
|
|
/** @var CForumThread $thread */ |
|
|
|
$thread = $threadRepo->find($thread->getIid()); |
|
|
|
$thread = $threadRepo->find($thread->getIid()); |
|
|
@ -67,10 +104,11 @@ class CForumPostRepositoryTest extends AbstractApiTest |
|
|
|
$this->assertSame(1, $forum->getThreads()->count()); |
|
|
|
$this->assertSame(1, $forum->getThreads()->count()); |
|
|
|
$this->assertSame(1, $forum->getPosts()->count()); |
|
|
|
$this->assertSame(1, $forum->getPosts()->count()); |
|
|
|
|
|
|
|
|
|
|
|
$forumRepo->delete($forum); |
|
|
|
/*$forumRepo->delete($forum); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertSame(0, $attachmentRepo->count([])); |
|
|
|
$this->assertSame(0, $postRepo->count([])); |
|
|
|
$this->assertSame(0, $postRepo->count([])); |
|
|
|
$this->assertSame(0, $threadRepo->count([])); |
|
|
|
$this->assertSame(0, $threadRepo->count([])); |
|
|
|
$this->assertSame(0, $forumRepo->count([])); |
|
|
|
$this->assertSame(0, $forumRepo->count([]));*/ |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|