Chamilo is a learning management system focused on ease of use and accessibility
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
chamilo-lms/tests/CoreBundle/Repository/SessionRepositoryTest.php

75 lines
2.2 KiB

4 years ago
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\Tests\CoreBundle\Repository;
use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CoreBundle\Entity\SessionCategory;
4 years ago
use Chamilo\CoreBundle\Repository\SessionRepository;
use Chamilo\Tests\AbstractApiTest;
use Chamilo\Tests\ChamiloTestTrait;
class SessionRepositoryTest extends AbstractApiTest
{
use ChamiloTestTrait;
public function testCreate(): void
{
self::bootKernel();
$em = $this->getEntityManager();
4 years ago
$repo = self::getContainer()->get(SessionRepository::class);
$url = $this->getAccessUrl();
$coach = $this->createUser('coach');
$category = (new SessionCategory())
->setName('cat')
->setUrl($this->getAccessUrl())
;
$em->persist($category);
$em->flush();
$this->assertSame('cat', (string) $category);
$this->assertNull($category->getDateStart());
$this->assertNull($category->getDateEnd());
$session = (new Session())
4 years ago
->setName('session 1')
->addGeneralCoach($coach)
4 years ago
->addAccessUrl($url)
->setCategory($category)
->setDuration(100)
->setShowDescription(true)
->setDescription('desc')
->setNbrClasses(0)
->setNbrUsers(0)
->setNbrCourses(0)
->setVisibility(Session::INVISIBLE)
4 years ago
;
$this->assertHasNoEntityViolations($session);
$em->persist($session);
4 years ago
$em->flush();
$this->assertSame(1, $repo->count([]));
$this->assertNotNull($session->getCategory());
$this->assertSame('session 1', (string) $session);
$this->assertSame(0, \count($session->getAllUsersFromCourse(0)));
$this->assertSame(100, $session->getDuration());
$this->assertTrue($session->isActiveForStudent());
$this->assertTrue($session->isActiveForCoach());
$this->assertFalse($session->isCurrentlyAccessible());
$user = $this->createUser('test');
$this->assertFalse($session->hasUserAsGeneralCoach($user));
$this->assertIsArray(Session::getStatusList());
4 years ago
}
}