Tests: Add phpunit tests

pull/3965/head
Julio 5 years ago
parent 36c0f6bf01
commit 3d3d69beb1
  1. 16
      tests/CoreBundle/Controller/Admin/SettingsControllerTest.php
  2. 18
      tests/CoreBundle/Controller/CourseControllerTest.php
  3. 29
      tests/CoreBundle/Controller/NewsControllerTest.php
  4. 31
      tests/CoreBundle/Controller/UserControllerTest.php
  5. 25
      tests/CoreBundle/Repository/SysAnnouncementRepositoryTest.php
  6. 43
      tests/CourseBundle/Repository/CCourseDescriptionRepositoryTest.php

@ -93,4 +93,20 @@ class SettingsControllerTest extends WebTestCase
$this->assertResponseIsSuccessful();
}
}
public function testSyncSettings(): void
{
$client = static::createClient();
//$settingsManager = $this->getContainer()->get(SettingsManager::class);
// retrieve the admin
$admin = $this->getUser('admin');
// simulate $testUser being logged in
$client->loginUser($admin);
$client->request('GET', '/admin/settings_sync');
$this->assertResponseIsSuccessful();
}
}

@ -6,6 +6,7 @@ declare(strict_types=1);
namespace Chamilo\Tests\CoreBundle\Controller;
use Chamilo\CourseBundle\Entity\CCourseDescription;
use Chamilo\Tests\ChamiloTestTrait;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\Response;
@ -48,10 +49,27 @@ class CourseControllerTest extends WebTestCase
$client = static::createClient();
$course = $this->createCourse('new course');
$admin = $this->getUser('admin');
$teacher = $this->createUser('teacher');
// simulate $testUser being logged in
$client->loginUser($admin);
$course->addTeacher($teacher);
$em = $this->getEntityManager();
$item = (new CCourseDescription())
->setTitle('title')
->setContent('content')
->setDescriptionType(1)
->setProgress(100)
->setParent($course)
->setCreator($teacher)
->addCourseLink($course)
;
$em->persist($item);
$em->persist($course);
$em->flush();
$client->request('GET', '/course/'.$course->getId().'/about');
$this->assertSame(Response::HTTP_OK, $client->getResponse()->getStatusCode());

@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\Tests\CoreBundle\Controller;
use Chamilo\Tests\ChamiloTestTrait;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class NewsControllerTest extends WebTestCase
{
use ChamiloTestTrait;
public function testIndex(): void
{
$client = static::createClient();
// retrieve the admin
$admin = $this->getUser('admin');
// simulate $testUser being logged in
$client->loginUser($admin);
$client->request('GET', '/news/list');
$this->assertResponseIsSuccessful();
}
}

@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\Tests\CoreBundle\Controller;
use Chamilo\Tests\ChamiloTestTrait;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class UserControllerTest extends WebTestCase
{
use ChamiloTestTrait;
public function testIndex(): void
{
$client = static::createClient();
// retrieve the admin
$admin = $this->getUser('admin');
// simulate $testUser being logged in
$client->loginUser($admin);
$client->request('GET', '/user/admin');
$this->assertResponseIsSuccessful();
$this->assertSelectorTextContains('#sectionMainContent', 'admin');
}
}

@ -6,8 +6,10 @@ declare(strict_types=1);
namespace Chamilo\Tests\CoreBundle\Repository;
use Chamilo\CoreBundle\Entity\SysAnnouncement;
use Chamilo\CoreBundle\Repository\SysAnnouncementRepository;
use Chamilo\Tests\ChamiloTestTrait;
use DateTime;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class SysAnnouncementRepositoryTest extends WebTestCase
@ -25,4 +27,27 @@ class SysAnnouncementRepositoryTest extends WebTestCase
$this->assertSame(1, $count);
}
public function testCreate(): void
{
self::bootKernel();
$repo = self::getContainer()->get(SysAnnouncementRepository::class);
$count = $repo->count([]);
$this->assertSame(1, $count);
$em = $this->getEntityManager();
$sysAnnouncement = (new SysAnnouncement())
->setTitle('Welcome to Chamilo!')
->setContent('content')
->setUrl($this->getAccessUrl())
->setDateStart(new DateTime())
->setDateEnd(new DateTime('now +30 days'))
->addRole('ROLE_ANONYMOUS')
->addRole('ROLE_USER') // connected users
;
$em->persist($sysAnnouncement);
$em->flush();
$count = $repo->count([]);
$this->assertSame(2, $count);
}
}

@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\Tests\CourseBundle\Repository;
use Chamilo\CourseBundle\Entity\CCourseDescription;
use Chamilo\CourseBundle\Repository\CCourseDescriptionRepository;
use Chamilo\Tests\AbstractApiTest;
use Chamilo\Tests\ChamiloTestTrait;
class CCourseDescriptionRepositoryTest extends AbstractApiTest
{
use ChamiloTestTrait;
public function testCreate(): void
{
self::bootKernel();
$em = $this->getEntityManager();
$repo = self::getContainer()->get(CCourseDescriptionRepository::class);
$course = $this->createCourse('new');
$teacher = $this->createUser('teacher');
$item = (new CCourseDescription())
->setTitle('title')
->setContent('content')
->setDescriptionType(1)
->setProgress(100)
->setParent($course)
->setCreator($teacher)
;
$this->assertHasNoEntityViolations($item);
$em->persist($item);
$em->flush();
$this->assertSame('title', (string) $item);
$this->assertSame(1, $repo->count([]));
}
}
Loading…
Cancel
Save