Controllers: Fix tests, remove unused code, add tests.

pull/4020/head^2
Julio 5 years ago
parent 39c7644515
commit 82e3f51214
  1. 485
      src/CoreBundle/Controller/Admin/AdminController.php
  2. 8
      src/CoreBundle/Controller/Admin/PluginsController.php
  3. 13
      src/CoreBundle/Controller/Admin/SettingsController.php
  4. 5
      src/CoreBundle/Controller/CourseController.php
  5. 4
      src/CoreBundle/Controller/EditorController.php
  6. 2
      src/CoreBundle/Controller/ResourceController.php
  7. 9
      src/CoreBundle/Resources/views/Admin/Settings/index.html.twig
  8. 1
      src/CoreBundle/Resources/views/Admin/Settings/plugins.html.twig
  9. 13
      src/CoreBundle/Resources/views/Admin/Settings/pluginsAdd.html.twig
  10. 14
      tests/CoreBundle/Controller/Admin/PluginControllerTest.php
  11. 17
      tests/CoreBundle/Controller/Admin/SettingsControllerTest.php
  12. 19
      tests/CoreBundle/Controller/CourseControllerTest.php
  13. 41
      tests/CoreBundle/Controller/CoursesControllerTest.php
  14. 31
      tests/CoreBundle/Controller/EditorControllerTest.php
  15. 57
      tests/CoreBundle/Controller/ResourceControllerTest.php
  16. 16
      tests/CourseBundle/Repository/CDocumentRepositoryTest.php

@ -7,492 +7,9 @@ declare(strict_types=1);
namespace Chamilo\CoreBundle\Controller\Admin;
use Chamilo\CoreBundle\Controller\BaseController;
use Display;
use FormValidator;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/admin")
*/
#[Route('/admin')]
class AdminController extends BaseController
{
/**
* @Route("/", methods={"GET"}, name="administration")
*
* @return Response
*/
public function indexAction()
{
if ($this->isGranted('ROLE_ADMIN')) {
return $this->loadAdminMenu();
}
throw $this->createAccessDeniedException();
}
/**
* @return FormValidator
*/
private function getSearchForm(string $url)
{
$form = new FormValidator(
'search-form',
'get',
$url,
'',
[
'class' => 'form-inline',
]
);
$form->addElement('text', 'keyword');
$form->addElement('button', 'submit', get_lang('Search'));
return $form;
}
/**
* Move in template.lib.
*/
private function loadAdminMenu(): Response
{
// Access restrictions.
api_protect_admin_script(true);
$adminUrl = api_get_path(WEB_CODE_PATH).'admin/';
$blocks = [];
/* Users */
$blocks['users']['icon'] = Display::return_icon(
'members.png',
get_lang('Users'),
[],
ICON_SIZE_MEDIUM,
false
);
$blocks['users']['label'] = api_ucfirst(get_lang('Users'));
if (api_is_platform_admin()) {
$search_form = $this->getSearchForm($adminUrl.'user_list.php')->returnForm();
$blocks['users']['search_form'] = $search_form;
$items = [
[
'url' => $adminUrl.'user_list.php',
'label' => get_lang('User list'),
],
[
'url' => $adminUrl.'user_add.php',
'label' => get_lang('Add a user'),
],
[
'url' => $adminUrl.'user_export.php',
'label' => get_lang('ExportUser listXMLCSV'),
],
[
'url' => $adminUrl.'user_import.php',
'label' => get_lang('ImportUser listXMLCSV'),
],
];
$items[] = [
'url' => $adminUrl.'extra_fields.php?type=user',
'label' => get_lang('Profiling'),
];
} else {
$items = [
[
'url' => $adminUrl.'user_list.php',
'label' => get_lang('User list'),
],
[
'url' => $adminUrl.'user_add.php',
'label' => get_lang('Add a user'),
],
[
'url' => $adminUrl.'user_import.php',
'label' => get_lang('ImportUser listXMLCSV'),
],
];
}
$items[] = [
'url' => $adminUrl.'usergroups.php',
'label' => get_lang('Classes'),
];
$blocks['users']['items'] = $items;
$blocks['users']['extra'] = null;
if (api_is_platform_admin()) {
/* Courses */
$blocks['courses']['icon'] = Display::return_icon(
'course.png',
get_lang('Courses'),
[],
ICON_SIZE_MEDIUM,
false
);
$blocks['courses']['label'] = api_ucfirst(get_lang('Courses'));
$search_form = $this->getSearchForm(
$adminUrl.'course_list.php'
)->returnForm();
$blocks['courses']['search_form'] = $search_form;
$items = [];
$items[] = [
'url' => $adminUrl.'course_list.php',
'label' => get_lang('Course list'),
];
if ('true' !== api_get_setting('course.course_validation')) {
$items[] = [
'url' => $adminUrl.'course_add.php',
'label' => get_lang('Create a course'),
];
} else {
$items[] = [
'url' => $adminUrl.'course_request_review.php',
'label' => get_lang('Review incoming course requests'),
];
$items[] = [
'url' => $adminUrl.'course_request_accepted.php',
'label' => get_lang('Accepted course requests'),
];
$items[] = [
'url' => $adminUrl.'course_request_rejected.php',
'label' => get_lang('Rejected course requests'),
];
}
$items[] = [
'url' => $adminUrl.'course_export.php',
'label' => get_lang('Export courses'),
];
$items[] = [
'url' => $adminUrl.'course_import.php',
'label' => get_lang('Import courses list'),
];
$items[] = [
'url' => $adminUrl.'course_category.php',
'label' => get_lang('Courses categories'),
];
$items[] = [
'url' => $adminUrl.'subscribe_user2course.php',
'label' => get_lang('Add a user to a course'),
];
$items[] = [
'url' => $adminUrl.'course_user_import.php',
'label' => get_lang('Import users list'),
];
$items[] = [
'url' => $adminUrl.'extra_fields.php?type=course',
'label' => get_lang('Manage extra fields for courses'),
];
$items[] = [
'url' => $adminUrl.'extra_fields.php?type=question',
'label' => get_lang('Manage extra fields for questions'),
];
/*if (api_get_setting('gradebook.gradebook_enable_grade_model') == 'true') {
$items[] = array(
'url' => $adminUrl.'grade_models.php',
'label' => get_lang('Grading model'),
);
}*/
$blocks['courses']['items'] = $items;
$blocks['courses']['extra'] = null;
/* Portal */
$blocks['platform']['icon'] = Display::return_icon(
'platform.png',
get_lang('Portal'),
[],
ICON_SIZE_MEDIUM,
false
);
$blocks['platform']['label'] = api_ucfirst(get_lang('Portal'));
$form = $this->getSearchForm($adminUrl.'settings.php');
$form->addElement('hidden', 'category', 'search_setting');
$search_form = $form->returnForm();
$blocks['platform']['search_form'] = $search_form;
$items = [];
$items[] = [
'url' => $this->generateUrl(
'admin_settings'
),
'label' => get_lang('PortalConfigSettings'),
];
$items[] = [
'url' => $adminUrl.'settings.php?category=Plugins',
'label' => get_lang('Plugins'),
];
$items[] = [
'url' => $adminUrl.'settings.php?category=Regions',
'label' => get_lang('Regions'),
];
$items[] = [
'url' => $adminUrl.'system_announcements.php',
'label' => get_lang('Portal news'),
];
$items[] = [
'url' => api_get_path(
WEB_CODE_PATH
).'calendar/agenda_js.php?type=admin',
'label' => get_lang('Global agenda'),
];
$items[] = [
'url' => $adminUrl.'configure_homepage.php',
'label' => get_lang('Edit portal homepage'),
];
$items[] = [
'url' => $adminUrl.'configure_inscription.php',
'label' => get_lang('Setting the registration page'),
];
$items[] = [
'url' => $adminUrl.'statistics/index.php',
'label' => get_lang('Statistics'),
];
$items[] = [
'url' => api_get_path(
WEB_CODE_PATH
).'mySpace/company_reports.php',
'label' => get_lang('Reports'),
];
if (api_get_multiple_access_url() && api_is_global_platform_admin()) {
$items[] = [
'url' => $adminUrl.'access_urls.php',
'label' => get_lang('Configure multiple access URL'),
];
}
if ('true' ===
api_get_setting('registration.allow_terms_conditions')
) {
$items[] = [
'url' => $adminUrl.'legal_add.php',
'label' => get_lang('Terms and Conditions'),
];
}
$blocks['platform']['items'] = $items;
$blocks['platform']['extra'] = null;
}
/* Course sessions */
$blocks['sessions']['icon'] = Display::return_icon(
'session.png',
get_lang('Course sessions'),
[],
ICON_SIZE_MEDIUM,
false
);
$blocks['sessions']['label'] = api_ucfirst(get_lang('Course sessions'));
$search_form = $this->getSearchForm(
api_get_path(WEB_CODE_PATH).'session/session_list.php'
)->returnForm();
$blocks['sessions']['search_form'] = $search_form;
$items = [];
$items[] = [
'url' => api_get_path(
WEB_CODE_PATH
).'session/session_list.php',
'label' => get_lang('Training sessions list'),
];
$items[] = [
'url' => api_get_path(
WEB_CODE_PATH
).'session/session_add.php',
'label' => get_lang('Add a training session'),
];
$items[] = [
'url' => api_get_path(WEB_CODE_PATH).'session/session_category_list.php',
'label' => get_lang('Training sessions listCategory'),
];
$items[] = [
'url' => api_get_path(WEB_CODE_PATH).'session/session_import.php',
'label' => get_lang('Import sessions list'),
];
$items[] = [
'url' => api_get_path(WEB_CODE_PATH).'session/session_export.php',
'label' => get_lang('Export sessions list'),
];
$items[] = [
'url' => $adminUrl.'../coursecopy/copy_course_session.php',
'label' => get_lang('Copy from course in session to another session'),
];
if (api_is_platform_admin()) {
if (is_dir(
api_get_path(SYS_TEST_PATH).'datafiller/'
)) { // option only visible in development mode. Enable through code if required
$items[] = [
'url' => $adminUrl.'user_move_stats.php',
'label' => get_lang('Move users results from/to a session'),
];
}
$items[] = [
'url' => $adminUrl.'career_dashboard.php',
'label' => get_lang('Careers and promotions'),
];
}
$items[] = [
'url' => $adminUrl.'exercise_report.php',
'label' => get_lang('ExerciseReport'),
];
$items[] = [
'url' => $adminUrl.'extra_fields.php?type=session',
'label' => get_lang('Manage session fields'),
];
$blocks['sessions']['items'] = $items;
$blocks['sessions']['extra'] = null;
/* Settings */
if (api_is_platform_admin()) {
$blocks['settings']['icon'] = Display::return_icon(
'settings.png',
get_lang('System'),
[],
ICON_SIZE_MEDIUM,
false
);
$blocks['settings']['label'] = api_ucfirst(get_lang('System'));
$items = [];
$items[] = [
'url' => $adminUrl.'special_exports.php',
'label' => get_lang('Special exports'),
];
$dbPath = api_get_configuration_value('db_admin_path');
if (!empty($dbPath)) {
$items[] = [
'url' => $dbPath,
'label' => get_lang('Databases (phpMyAdmin)').' ('.get_lang('Database management is only available for the server administrator').') ',
];
}
$items[] = [
'url' => $adminUrl.'system_status.php',
'label' => get_lang('System status'),
];
if (is_dir(api_get_path(SYS_TEST_PATH).'datafiller/')) {
$items[] = [
'url' => $adminUrl.'filler.php',
'label' => get_lang('Data filler'),
];
}
$items[] = [
'url' => $adminUrl.'archive_cleanup.php',
'label' => get_lang('Cleanup of cache and temporary files'),
];
//$items[] = array('url' => $adminUrl.'system_management.php', 'label' => get_lang('System Management'));
$blocks['settings']['items'] = $items;
$blocks['settings']['extra'] = null;
$blocks['settings']['search_form'] = null;
//Skills
if ('true' === api_get_setting('skill.allow_skills_tool')) {
$blocks['skills']['icon'] = Display::return_icon(
'skill-badges.png',
get_lang('Skills'),
[],
ICON_SIZE_MEDIUM,
false
);
$blocks['skills']['label'] = get_lang('Skills');
$items = [];
//$items[] = array('url' => $adminUrl.'skills.php', 'label' => get_lang('Skills Tree'));
$items[] = [
'url' => $adminUrl.'skills_wheel.php',
'label' => get_lang('Skills wheel'),
];
$items[] = [
'url' => $adminUrl.'skills_import.php',
'label' => get_lang('Skills import'),
];
//$items[] = array('url' => $adminUrl.'skills_profile.php', 'label' => get_lang('Skills Profile'));
$items[] = [
'url' => api_get_path(
WEB_CODE_PATH
).'social/skills_ranking.php',
'label' => get_lang('Skills ranking'),
];
$items[] = [
'url' => $adminUrl.'skills_gradebook.php',
'label' => get_lang('Skills and assessments'),
];
$blocks['skills']['items'] = $items;
$blocks['skills']['extra'] = null;
$blocks['skills']['search_form'] = null;
}
/* Chamilo.org */
$blocks['chamilo']['icon'] = Display::return_icon(
'platform.png',
'Chamilo.org',
[],
ICON_SIZE_MEDIUM,
false
);
$blocks['chamilo']['label'] = 'Chamilo.org';
$items = [];
$items[] = [
'url' => 'http://www.chamilo.org/',
'label' => get_lang('Chamilo homepage'),
];
$items[] = [
'url' => 'http://www.chamilo.org/forum',
'label' => get_lang('Chamilo forum'),
];
$items[] = [
'url' => '../../documentation/installation_guide.html',
'label' => get_lang('Installation guide'),
];
$items[] = [
'url' => '../../documentation/changelog.html',
'label' => get_lang('Changes in last version'),
];
$items[] = [
'url' => '../../documentation/credits.html',
'label' => get_lang('Contributors list'),
];
$items[] = [
'url' => '../../documentation/security.html',
'label' => get_lang('Security guide'),
];
$items[] = [
'url' => '../../documentation/optimization.html',
'label' => get_lang('Optimization guide'),
];
$items[] = [
'url' => 'http://www.chamilo.org/extensions',
'label' => get_lang('Chamilo extensions'),
];
$items[] = [
'url' => 'http://www.chamilo.org/en/providers',
'label' => get_lang('Chamilo official services providers'),
];
$blocks['chamilo']['items'] = $items;
$blocks['chamilo']['extra'] = null;
$blocks['chamilo']['search_form'] = null;
}
$admin_ajax_url = api_get_path(WEB_AJAX_PATH).'admin.ajax.php';
return $this->render(
'ChamiloCoreBundle:Admin:index.html.twig',
[
'blocks' => $blocks,
'web_admin_ajax_url' => $admin_ajax_url,
]
);
}
}

@ -9,7 +9,6 @@ namespace Chamilo\CoreBundle\Controller\Admin;
use AppPlugin;
use Chamilo\CoreBundle\Controller\BaseController;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
@ -31,11 +30,8 @@ class PluginsController extends BaseController
);
}
/**
* @Security("is_granted('ROLE_ADMIN')")
*
* @Route("/add")
*/
#[IsGranted('ROLE_ADMIN')]
#[Route('/add', name: 'chamilo_core_plugins', methods:['GET', 'POST'])]
public function pluginsAddAction(): Response
{
$appPlugin = new AppPlugin();

@ -22,19 +22,10 @@ class SettingsController extends BaseController
{
use ControllerTrait;
#[IsGranted('ROLE_ADMIN')]
#[Route('/settings', name: 'admin_settings')]
public function indexAction(): Response
{
$manager = $this->getSettingsManager();
$schemas = $manager->getSchemas();
return $this->render(
'@ChamiloCore/Admin/Settings/index.html.twig',
[
'schemas' => $schemas,
]
);
return $this->redirectToRoute('chamilo_platform_settings', ['namespace' => 'platform']);
}
/**
@ -184,7 +175,7 @@ class SettingsController extends BaseController
* Sync settings from classes with the database.
*/
#[IsGranted('ROLE_ADMIN')]
#[Route('/settings_sync', name: 'admin_settings')]
#[Route('/settings_sync', name: 'sync_settings')]
public function syncSettings(): Response
{
$manager = $this->getSettingsManager();

@ -243,9 +243,8 @@ class CourseController extends ToolBaseController
return $this->redirect($url);
}
public function redirectToShortCut(string $toolName, CToolRepository $repo, ToolChain $toolChain): RedirectResponse
/*public function redirectToShortCut(string $toolName, CToolRepository $repo, ToolChain $toolChain): RedirectResponse
{
/** @var CTool|null $tool */
$tool = $repo->findOneBy([
'name' => $toolName,
]);
@ -265,7 +264,7 @@ class CourseController extends ToolBaseController
$url = $link.'?'.$this->getCourseUrlQuery();
return $this->redirect($url);
}
}*/
/**
* Edit configuration with given namespace.

@ -26,10 +26,8 @@ class EditorController extends BaseController
* Get templates (left column when creating a document).
*
* @Route("/templates", methods={"GET"}, name="editor_templates")
*
* @return Response
*/
public function editorTemplatesAction(TranslatorInterface $translator, RouterInterface $router)
public function editorTemplatesAction(TranslatorInterface $translator, RouterInterface $router): Response
{
$editor = new CkEditor(
$translator,

@ -254,7 +254,6 @@ class ResourceController extends AbstractResourceController implements CourseCon
{
$id = $request->get('id');
$resourceNode = $this->getResourceNodeRepository()->findOneBy(['uuid' => $id]);
//$resourceNode = $this->getResourceNodeRepository()->find($id);
if (null === $resourceNode) {
throw new FileNotFoundException($this->trans('Resource not found'));
@ -286,6 +285,7 @@ class ResourceController extends AbstractResourceController implements CourseCon
$qb = $resourceNodeRepo->getChildrenQueryBuilder($resourceNode);
$qb->addCriteria($criteria);
/** @var ArrayCollection|ResourceNode[] $children */
$children = $qb->getQuery()->getResult();
$count = \count($children);

@ -1,13 +1,6 @@
{% extends "@ChamiloCore/Layout/layout_one_col.html.twig" %}
{% block page_title %}
{{ 'Settings' | trans }}
{% endblock %}
{% block page_subtitle %}
{% endblock %}
{% block page_content %}
{% block content %}
<div class="row">
<div class="col-xs-3 col-md-3">
{% include '@ChamiloCore/Admin/Settings/menu.html.twig' %}

@ -1,7 +1,6 @@
{% extends "@ChamiloCore/Layout/layout_one_col.html.twig" %}
{% block content %}
<a href="{{ url('chamilo_core_admin_plugins_pluginsadd') }}">
Add
</a>

@ -1,13 +1,7 @@
{% extends "::layout.html.twig" %}
{% extends "@ChamiloCore/Layout/layout_one_col.html.twig" %}
{% block page_title %}
{{ 'Settings' | trans }}
{% endblock %}
{% block page_subtitle %}
{% endblock %}
{% block page_content %}
{% block content %}
Add
<div>
{% for plugin in plugins %}
<div class="panel panel-default">
@ -15,7 +9,6 @@
<div class="panel-body">
</div>
</div>
{% endfor %}
</div>
{% endblock%}

@ -26,4 +26,18 @@ class PluginControllerTest extends WebTestCase
$this->assertStringContainsString('Plugin', $content);
}
public function testAdd(): void
{
$client = static::createClient();
$admin = $this->getUser('admin');
$client->loginUser($admin);
$client->request('GET', '/plugins/add');
$this->assertResponseIsSuccessful();
$content = (string) $client->getResponse()->getContent();
$this->assertStringContainsString('Add', $content);
}
}

@ -20,11 +20,19 @@ class SettingsControllerTest extends WebTestCase
$admin = $this->getUser('admin');
$client->loginUser($admin);
$client->request('GET', '/admin/settings');
$this->assertResponseRedirects('/admin/settings/platform');
}
public function testAdminSettings(): void
{
$client = static::createClient();
$admin = $this->getUser('admin');
$client->loginUser($admin);
$client->request('GET', '/admin/settings/admin');
$this->assertResponseIsSuccessful();
$this->assertSelectorTextContains('#sectionMainContent', 'Administrator email');
//$this->assertStringContainsString('Administrator email', $client->getResponse()->getContent());
}
public function testSearchSettingAction(): void
@ -42,10 +50,7 @@ class SettingsControllerTest extends WebTestCase
'search[keyword]' => 'allow_message_tool',
]);
$this->assertStringContainsString(
'Allow message tool',
$client->getResponse()->getContent()
);
$this->assertStringContainsString('Allow message tool', $client->getResponse()->getContent());
}
public function testUpdateSettingAction(): void

@ -32,13 +32,6 @@ class CourseControllerTest extends WebTestCase
'/course/'.$course->getId().'/home.json'
);
$this->assertResponseIsSuccessful();
/*$this->assertJsonContains(
[
'course' => [
'code' => $course->getCode(),
],
]
);*/
// Test as registered user (course is open).
$test = $this->createUser('test');
@ -64,10 +57,7 @@ class CourseControllerTest extends WebTestCase
$userTest1 = $this->createUser('test1');
$client->loginUser($userTest1);
$client->request(
'GET',
'/course/'.$course->getId().'/home.json'
);
$client->request('GET', '/course/'.$course->getId().'/home.json');
$this->assertResponseStatusCodeSame(403);
}
@ -95,13 +85,6 @@ class CourseControllerTest extends WebTestCase
'/course/'.$course->getId().'/home.json'
);
$this->assertResponseIsSuccessful();
/*$this->assertJsonContains(
[
'course' => [
'code' => $course->getCode(),
],
]
);*/
}
public function testRedirectTool(): void

@ -6,6 +6,8 @@ declare(strict_types=1);
namespace Chamilo\Tests\CoreBundle\Controller;
use Chamilo\CourseBundle\Entity\CDocument;
use Chamilo\CourseBundle\Repository\CDocumentRepository;
use Chamilo\Tests\ChamiloTestTrait;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
@ -25,4 +27,43 @@ class CoursesControllerTest extends WebTestCase
$client->request('GET', '/courses/'.$course->getCode().'/index.php');
$this->assertResponseRedirects('/course/'.$course->getId().'/home');
}
public function testDocumentRedirect(): void
{
$client = static::createClient();
$admin = $this->getUser('admin');
// simulate $testUser being logged in
$client->loginUser($admin);
$course = $this->createCourse('Test');
$documentRepo = self::getContainer()->get(CDocumentRepository::class);
$admin = $this->getUser('admin');
$document = (new CDocument())
->setFiletype('file')
->setTitle('title123')
->setParent($course)
->setCreator($admin)
->addCourseLink($course)
;
$documentRepo->create($document);
$this->assertSame(1, $documentRepo->count([]));
$path = $this->getUploadedFile()->getRealPath();
$resourceFile = $documentRepo->addFileFromPath($document, 'logo.png', $path, true);
$this->assertNotNull($resourceFile);
/** @var CDocument $document */
$document = $documentRepo->find($document->getIid());
$node = $document->getResourceNode();
$this->assertTrue($node->hasResourceFile());
$client->request('GET', '/courses/'.$course->getCode().'/document/title123');
$id = $node->getUuid()->toRfc4122();
$this->assertResponseRedirects('/r/document/file/'.$id.'/view');
}
}

@ -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 EditorControllerTest 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', '/editor/templates');
$this->assertResponseIsSuccessful();
$this->assertStringContainsString('Template', $client->getResponse()->getContent());
}
}

@ -0,0 +1,57 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\Tests\CoreBundle\Controller;
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\ResourceNode;
use Chamilo\CoreBundle\Repository\Node\CourseRepository;
use Chamilo\CourseBundle\Entity\CCourseDescription;
use Chamilo\CourseBundle\Entity\CDocument;
use Chamilo\CourseBundle\Repository\CDocumentRepository;
use Chamilo\CourseBundle\Settings\SettingsCourseManager;
use Chamilo\Tests\ChamiloTestTrait;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\Response;
class ResourceControllerTest extends WebTestCase
{
use ChamiloTestTrait;
public function testDownloadAction(): void
{
$client = static::createClient();
$admin = $this->getUser('admin');
$client->loginUser($admin);
$documentRepo = self::getContainer()->get(CDocumentRepository::class);
$course = $this->createCourse('Test');
$document = (new CDocument())
->setFiletype('file')
->setTitle('title 123')
->setTemplate(false)
->setReadonly(false)
->setParent($course)
->setCreator($admin)
->addCourseLink($course)
;
$documentRepo->create($document);
$documentRepo->addFileFromString($document, 'test', 'text/html', 'my file', true);
/** @var CDocument $document */
$document = $documentRepo->find($document->getIid());
$node = $document->getResourceNode();
$this->assertTrue($node->hasResourceFile());
$id = $node->getUuid()->toRfc4122();
$urlDownload = '/r/document/files/'.$id.'/download';
$client->request('GET', $urlDownload);
$this->assertResponseIsSuccessful();
}
}

@ -701,15 +701,13 @@ class CDocumentRepositoryTest extends AbstractApiTest
$this->assertSame($file->getSize(), $size);
$docs = $documentRepo->findDocumentsByAuthor($this->getUser('admin')->getId());
$this->assertSame(0, \count($docs));
$this->assertCount(0, $docs);
}
public function testAddFileFromString(): void
{
self::bootKernel();
$course = $this->createCourse('Test');
$documentRepo = self::getContainer()->get(CDocumentRepository::class);
$course = $this->createCourse('Test');
$admin = $this->getUser('admin');
$document = (new CDocument())
@ -742,8 +740,6 @@ class CDocumentRepositoryTest extends AbstractApiTest
public function testAddFileFromPath(): void
{
self::bootKernel();
$course = $this->createCourse('Test');
$documentRepo = self::getContainer()->get(CDocumentRepository::class);
$admin = $this->getUser('admin');
@ -772,8 +768,6 @@ class CDocumentRepositoryTest extends AbstractApiTest
public function testAddFileFromFileRequest(): void
{
self::bootKernel();
$course = $this->createCourse('Test');
$documentRepo = self::getContainer()->get(CDocumentRepository::class);
$admin = $this->getUser('admin');
@ -806,8 +800,6 @@ class CDocumentRepositoryTest extends AbstractApiTest
public function testCreateWithAddResourceNode(): void
{
self::bootKernel();
$course = $this->createCourse('Test');
$documentRepo = self::getContainer()->get(CDocumentRepository::class);
$admin = $this->getUser('admin');
@ -832,8 +824,6 @@ class CDocumentRepositoryTest extends AbstractApiTest
public function testCreateDocumentWithLinks(): void
{
self::bootKernel();
$course = $this->createCourse('Test');
$documentRepo = self::getContainer()->get(CDocumentRepository::class);
$admin = $this->getUser('admin');
@ -978,8 +968,6 @@ class CDocumentRepositoryTest extends AbstractApiTest
public function testSetVisibility(): void
{
self::bootKernel();
$course = $this->createCourse('Test');
$documentRepo = self::getContainer()->get(CDocumentRepository::class);
$admin = $this->getUser('admin');

Loading…
Cancel
Save