Calendar Event: Add tests

pull/3959/head
Julio 4 years ago
parent cb6ce41a1c
commit c7bb1acf8c
  1. 2
      src/CourseBundle/Repository/CCalendarEventRepository.php
  2. 6
      tests/ChamiloTestTrait.php
  3. 47
      tests/CourseBundle/Repository/CCalendarEventRepositoryTest.php

@ -58,7 +58,7 @@ final class CCalendarEventRepository extends ResourceRepository
$event->addResourceToGroupList($sendTo['groups'], $course, $session);
}
// Storing the selected users
// Storing the selected users.
if (\is_array($sendTo['users'])) {
$sendTo['users'] = array_map(
fn ($userId) => $em->find(User::class, $userId),

@ -10,6 +10,7 @@ use Chamilo\CoreBundle\Repository\Node\AccessUrlRepository;
use Chamilo\CoreBundle\Repository\Node\CourseRepository;
use Chamilo\CoreBundle\Repository\Node\UserRepository;
use Chamilo\CoreBundle\Repository\SessionRepository;
use Doctrine\ORM\EntityManager;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Validator\ConstraintViolationList;
use Symfony\Component\Validator\Validator\ValidatorInterface;
@ -136,4 +137,9 @@ trait ChamiloTestTrait
{
return $localTime->setTimezone(new \DateTimeZone('UTC'))->format('c');
}
public function getManager(): EntityManager
{
return self::getContainer()->get('doctrine')->getManager();
}
}

@ -7,6 +7,7 @@ declare(strict_types=1);
namespace Chamilo\Tests\CourseBundle\Repository;
use Chamilo\CoreBundle\Entity\ResourceLink;
use Chamilo\CoreBundle\Repository\Node\UserRepository;
use Chamilo\CourseBundle\Entity\CCalendarEvent;
use Chamilo\CourseBundle\Repository\CCalendarEventRepository;
use Chamilo\Tests\AbstractApiTest;
@ -118,6 +119,8 @@ class CCalendarEventRepositoryTest extends AbstractApiTest
public function testCreatePersonalEventAsAnotherUser(): void
{
self::bootKernel();
// 1. Create user 'test'.
$user = $this->createUser('test');
$resourceNodeId = $user->getResourceNode()->getId();
@ -167,6 +170,8 @@ class CCalendarEventRepositoryTest extends AbstractApiTest
public function testAccessPersonalEvent(): void
{
self::bootKernel();
// 1. Create user 'test'.
$user = $this->createUser('test');
$token = $this->getUserToken(
@ -233,20 +238,50 @@ class CCalendarEventRepositoryTest extends AbstractApiTest
$event->setCollective(true);
$calendarRepo->update($event);
// view
// View.
$this->createClientWithCredentials($anotherToken)->request('GET', $eventIri);
$this->assertResponseStatusCodeSame(403);
// edit
$this->createClientWithCredentials($anotherToken)->request('PUT', $eventIri, ['json' => ['title' => 'hehe']]);
// Edit.
$this->createClientWithCredentials($anotherToken)->request(
'PUT',
$eventIri,
['json' => ['title' => 'hehe', 'content' => 'modified']]
);
$this->assertResponseStatusCodeSame(403);
// Now also add "another" as shared. @todo
/*$event->addUserLink($another);
// Delete
$this->createClientWithCredentials($anotherToken)->request('DELETE', $eventIri);
$this->assertResponseStatusCodeSame(403);
// Share event with "another" user.
$userRepo = self::getContainer()->get(UserRepository::class);
$calendarRepo = self::getContainer()->get(CCalendarEventRepository::class);
/** @var CCalendarEvent $event */
$event = $calendarRepo->find($eventId);
$another = $userRepo->find($another->getId());
// Add "another" as to the user.
$event
->addUserLink($another)
;
$calendarRepo->update($event);
$this->createClientWithCredentials($anotherToken)->request('GET', $eventIri);
$this->assertResponseStatusCodeSame(403);*/
$this->assertResponseStatusCodeSame(200);
// Edit.
$this->createClientWithCredentials($anotherToken)->request(
'PUT',
$eventIri,
['json' => ['title' => 'hehe', 'content' => 'modified']]
);
$this->assertResponseStatusCodeSame(200);
// Delete
$this->createClientWithCredentials($anotherToken)->request('DELETE', $eventIri);
$this->assertResponseStatusCodeSame(403);
}
public function testCreateCourseEvent(): void

Loading…
Cancel
Save