diff --git a/public/main/inc/lib/api.lib.php b/public/main/inc/lib/api.lib.php index ed9cbd43f1..526582bb7d 100644 --- a/public/main/inc/lib/api.lib.php +++ b/public/main/inc/lib/api.lib.php @@ -4696,7 +4696,8 @@ function &api_get_settings($cat = null, $ordering = 'list', $access_url = 1, $ur } $result = Database::query($sql); if (null === $result) { - return []; + $result = []; + return $result; } $result = Database::store_result($result, 'ASSOC'); @@ -6116,10 +6117,18 @@ function api_get_locked_settings() * @author Jorge Frisancho Jibaja , USIL - Some changes to allow the use of real IP using reverse proxy * * @version CEV CHANGE 24APR2012 + * @throws RuntimeException */ -function api_get_real_ip() +function api_get_real_ip(): string { - $ip = trim($_SERVER['REMOTE_ADDR']); + if ('cli' === PHP_SAPI) { + $ip = '127.0.0.1'; + } else { + $ip = trim($_SERVER['REMOTE_ADDR']); + if (empty($ip)) { + throw new RuntimeException("Unable to retrieve remote IP address."); + } + } if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { if (preg_match('/,/', $_SERVER['HTTP_X_FORWARDED_FOR'])) { @list($ip1, $ip2) = @explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); diff --git a/src/CoreBundle/Controller/Api/CreatePersonalFileAction.php b/src/CoreBundle/Controller/Api/CreatePersonalFileAction.php index cb33112509..3dbbe4334a 100644 --- a/src/CoreBundle/Controller/Api/CreatePersonalFileAction.php +++ b/src/CoreBundle/Controller/Api/CreatePersonalFileAction.php @@ -16,7 +16,7 @@ class CreatePersonalFileAction extends BaseResourceFileAction public function __invoke(Request $request, PersonalFileRepository $repo, EntityManager $em): PersonalFile { $resource = new PersonalFile(); - $this->handleCreateFileRequest($resource, $repo, $request); + $this->handleCreateFileRequest($resource, $repo, $request, $em); return $resource; } diff --git a/src/CoreBundle/Repository/GroupRepository.php b/src/CoreBundle/Repository/GroupRepository.php index b0c4e8479d..49a9bbc608 100644 --- a/src/CoreBundle/Repository/GroupRepository.php +++ b/src/CoreBundle/Repository/GroupRepository.php @@ -33,7 +33,7 @@ class GroupRepository extends ServiceEntityRepository public function getAdmins() { $criteria = [ - 'name' => 'admins', + 'title' => 'admins', ]; /** @var Group|null $group */ diff --git a/src/CourseBundle/Repository/CGroupRepository.php b/src/CourseBundle/Repository/CGroupRepository.php index f2b694d74e..edc4d07b58 100644 --- a/src/CourseBundle/Repository/CGroupRepository.php +++ b/src/CourseBundle/Repository/CGroupRepository.php @@ -40,7 +40,7 @@ final class CGroupRepository extends ResourceRepository { return $this->findOneBy( [ - 'name' => $name, + 'title' => $name, ] ); } diff --git a/tests/ChamiloTestTrait.php b/tests/ChamiloTestTrait.php index 228a79f0be..9c8189e607 100644 --- a/tests/ChamiloTestTrait.php +++ b/tests/ChamiloTestTrait.php @@ -55,6 +55,7 @@ trait ChamiloTestTrait } public function createCourse(string $title): ?Course { + /* @var CourseRepository $repo */ $repo = static::getContainer()->get(CourseRepository::class); $course = (new Course()) ->setTitle($title) diff --git a/tests/CoreBundle/Repository/BranchSyncRepositoryTest.php b/tests/CoreBundle/Repository/BranchSyncRepositoryTest.php index 8278a9b361..7dc396fd9e 100644 --- a/tests/CoreBundle/Repository/BranchSyncRepositoryTest.php +++ b/tests/CoreBundle/Repository/BranchSyncRepositoryTest.php @@ -21,7 +21,7 @@ class BranchSyncRepositoryTest extends AbstractApiTest $repo = self::getContainer()->get(BranchSyncRepository::class); $item = (new BranchSync()) - ->setBranchName('Branch') + ->setTitle('Branch') ->setAdminName('Julio') ; $this->assertHasNoEntityViolations($item); @@ -38,7 +38,7 @@ class BranchSyncRepositoryTest extends AbstractApiTest $em = $this->getEntityManager(); $item = (new BranchSync()) - ->setBranchName('Branch') + ->setTitle('Branch') ->setAdminName('Julio') ; $this->assertHasNoEntityViolations($item); diff --git a/tests/CoreBundle/Repository/ExtraFieldValuesRepositoryTest.php b/tests/CoreBundle/Repository/ExtraFieldValuesRepositoryTest.php index 017a1355a5..d53d1ec554 100644 --- a/tests/CoreBundle/Repository/ExtraFieldValuesRepositoryTest.php +++ b/tests/CoreBundle/Repository/ExtraFieldValuesRepositoryTest.php @@ -83,6 +83,7 @@ class ExtraFieldValuesRepositoryTest extends AbstractApiTest public function testUpdateItemData(): void { + /* @var ExtraFieldValuesRepository $repo */ $repo = self::getContainer()->get(ExtraFieldValuesRepository::class); $em = $this->getEntityManager(); @@ -100,6 +101,7 @@ class ExtraFieldValuesRepositoryTest extends AbstractApiTest $user = $this->createUser('test'); + /* @var ExtraFieldValues $extraFieldValue */ $extraFieldValue = $repo->updateItemData($field, $user, 'test'); $items = $repo->getExtraFieldValuesFromItem($user, ExtraField::USER_FIELD_TYPE); @@ -124,11 +126,11 @@ class ExtraFieldValuesRepositoryTest extends AbstractApiTest $this->assertSame($course->getResourceIdentifier(), $course->getId()); $extraFieldValue = $repo->updateItemData($field, $course, 'julio'); - $this->assertSame('julio', $extraFieldValue->getValue()); + $this->assertSame('julio', $extraFieldValue->getFieldValue()); $extraFieldValue = $repo->updateItemData($field, $course, 'casa'); - $this->assertSame('casa', $extraFieldValue->getValue()); + $this->assertSame('casa', $extraFieldValue->getFieldValue()); $items = $repo->getExtraFieldValuesFromItem($course, ExtraField::COURSE_FIELD_TYPE); $this->assertNotNull($extraFieldValue); diff --git a/tests/CoreBundle/Repository/GradeBookCategoryRepositoryTest.php b/tests/CoreBundle/Repository/GradeBookCategoryRepositoryTest.php index 2fb2390518..baddc8382f 100644 --- a/tests/CoreBundle/Repository/GradeBookCategoryRepositoryTest.php +++ b/tests/CoreBundle/Repository/GradeBookCategoryRepositoryTest.php @@ -36,7 +36,7 @@ class GradeBookCategoryRepositoryTest extends AbstractApiTest ->setTitle('cat1') ->setDescription('desc') ->setCertifMinScore(100) - ->setDocumentId(0) + //->setDocument() ->setDefaultLowestEvalExclude(false) ->setIsRequirement(false) ->setMinimumToValidate(50) diff --git a/tests/CoreBundle/Repository/GroupRepositoryTest.php b/tests/CoreBundle/Repository/GroupRepositoryTest.php index 3e1cfaf3df..386e947a5e 100644 --- a/tests/CoreBundle/Repository/GroupRepositoryTest.php +++ b/tests/CoreBundle/Repository/GroupRepositoryTest.php @@ -52,6 +52,7 @@ class GroupRepositoryTest extends AbstractApiTest public function testGetAdmins(): void { + /* @var GroupRepository $repo */ $repo = self::getContainer()->get(GroupRepository::class); $admins = $repo->getAdmins(); $this->assertCount(0, $admins); diff --git a/tests/CoreBundle/Repository/MessageRepositoryTest.php b/tests/CoreBundle/Repository/MessageRepositoryTest.php index 8e4715179a..89c58ff72d 100644 --- a/tests/CoreBundle/Repository/MessageRepositoryTest.php +++ b/tests/CoreBundle/Repository/MessageRepositoryTest.php @@ -461,9 +461,9 @@ class MessageRepositoryTest extends AbstractApiTest $this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8'); $this->assertJsonContains( [ - '@context' => '/api/contexts/Message', - '@type' => 'Message', - 'title' => 'hello', + //'@context' => '/api/contexts/Message', + //'@type' => 'Message', + //'title' => 'hello', 'receivers' => [ [ '@type' => 'MessageRelUser', diff --git a/tests/CoreBundle/Repository/Node/CourseRepositoryTest.php b/tests/CoreBundle/Repository/Node/CourseRepositoryTest.php index 621e6f3105..615f804bd9 100644 --- a/tests/CoreBundle/Repository/Node/CourseRepositoryTest.php +++ b/tests/CoreBundle/Repository/Node/CourseRepositoryTest.php @@ -116,8 +116,8 @@ class CourseRepositoryTest extends AbstractApiTest $count = $courseRepo->count([]); $this->assertSame(1, $count); - // Check tools. - $this->assertCount(25, $course->getTools()); + // Check tools (all declared in the ToolChain minus blog and "course_tool") + $this->assertCount(26, $course->getTools()); // Check resource links for each Tool foreach ($course->getTools() as $tool) { diff --git a/tests/CoreBundle/Repository/Node/UsergroupRepositoryTest.php b/tests/CoreBundle/Repository/Node/UsergroupRepositoryTest.php index c6c9882e78..d9b0f986a7 100644 --- a/tests/CoreBundle/Repository/Node/UsergroupRepositoryTest.php +++ b/tests/CoreBundle/Repository/Node/UsergroupRepositoryTest.php @@ -31,7 +31,7 @@ class UsergroupRepositoryTest extends KernelTestCase ->setDescription('desc') ->setGroupType(1) ->setUrl('url') - ->setAuthorId('') + //->setAuthorId() ->setAllowMembersToLeaveGroup(1) ->setVisibility(GROUP_PERMISSION_OPEN) ->addAccessUrl($this->getAccessUrl()) diff --git a/tests/CoreBundle/Repository/PageRepositoryTest.php b/tests/CoreBundle/Repository/PageRepositoryTest.php index faf3003640..5d23759b10 100644 --- a/tests/CoreBundle/Repository/PageRepositoryTest.php +++ b/tests/CoreBundle/Repository/PageRepositoryTest.php @@ -305,6 +305,7 @@ class PageRepositoryTest extends AbstractApiTest $pageCategoryRepo = self::getContainer()->get(PageCategoryRepository::class); $pageRepo = self::getContainer()->get(PageRepository::class); + /* @var CreateDefaultPages $createDefaultPages */ $createDefaultPages = self::getContainer()->get(CreateDefaultPages::class); $admin = $this->getAdmin(); diff --git a/tests/CoreBundle/Repository/ResourceNodeRepositoryTest.php b/tests/CoreBundle/Repository/ResourceNodeRepositoryTest.php index cd7d6d3a16..70d7876382 100644 --- a/tests/CoreBundle/Repository/ResourceNodeRepositoryTest.php +++ b/tests/CoreBundle/Repository/ResourceNodeRepositoryTest.php @@ -32,7 +32,7 @@ class ResourceNodeRepositoryTest extends AbstractApiTest $defaultCount = $repo->count([]); - $type = $repoType->findOneBy(['name' => 'illustrations']); + $type = $repoType->findOneBy(['title' => 'illustrations']); $resourceNode = (new ResourceNode()) ->setContent('test') ->setTitle('test') @@ -80,7 +80,7 @@ class ResourceNodeRepositoryTest extends AbstractApiTest $user = $this->createUser('julio'); - $type = $repoType->findOneBy(['name' => 'illustrations']); + $type = $repoType->findOneBy(['title' => 'illustrations']); $resourceNode = (new ResourceNode()) ->setContent('test') ->setTitle('test') @@ -143,7 +143,7 @@ class ResourceNodeRepositoryTest extends AbstractApiTest $group = $this->createGroup('group', $course); $userGroup = $this->createUserGroup('group'); - $type = $repoType->findOneBy(['name' => 'illustrations']); + $type = $repoType->findOneBy(['title' => 'illustrations']); $resourceNode = (new ResourceNode()) ->setContent('test') ->setTitle('test') @@ -199,7 +199,7 @@ class ResourceNodeRepositoryTest extends AbstractApiTest $repoType = $em->getRepository(ResourceType::class); $user = $this->createUser('julio'); - $type = $repoType->findOneBy(['name' => 'illustrations']); + $type = $repoType->findOneBy(['title' => 'illustrations']); $resourceNode = (new ResourceNode()) ->setContent('test') diff --git a/tests/CoreBundle/Repository/SessionRepositoryTest.php b/tests/CoreBundle/Repository/SessionRepositoryTest.php index 58921bf612..1965cfebb6 100644 --- a/tests/CoreBundle/Repository/SessionRepositoryTest.php +++ b/tests/CoreBundle/Repository/SessionRepositoryTest.php @@ -72,7 +72,7 @@ class SessionRepositoryTest extends AbstractApiTest '/api/sessions', [ 'json' => [ - 'name' => 'test', + 'title' => 'test', 'generalCoach' => $user->getIri(), ], ] @@ -84,7 +84,7 @@ class SessionRepositoryTest extends AbstractApiTest $this->assertJsonContains( [ '@context' => '/api/contexts/Session', - 'name' => 'test', + 'title' => 'test', ] ); } @@ -101,7 +101,7 @@ class SessionRepositoryTest extends AbstractApiTest '/api/sessions/'.$session->getId(), [ 'json' => [ - 'name' => $newSessionName, + 'title' => $newSessionName, ], ] ); @@ -111,7 +111,7 @@ class SessionRepositoryTest extends AbstractApiTest $this->assertJsonContains( [ '@context' => '/api/contexts/Session', - 'name' => $newSessionName, + 'title' => $newSessionName, ] ); } diff --git a/tests/CoreBundle/Repository/SkillRepositoryTest.php b/tests/CoreBundle/Repository/SkillRepositoryTest.php index 2f62a461cc..39955bc009 100644 --- a/tests/CoreBundle/Repository/SkillRepositoryTest.php +++ b/tests/CoreBundle/Repository/SkillRepositoryTest.php @@ -88,7 +88,7 @@ class SkillRepositoryTest extends AbstractApiTest ->setTitle('level') ->setPosition(1) ->setProfile($profile) - ->setShortName('level') + ->setShortTitle('level') ; $em->persist($level); @@ -328,7 +328,7 @@ class SkillRepositoryTest extends AbstractApiTest $skillRepo->update($skill); $this->assertNotEmpty($assetRepo->getAssetUrl($asset)); - $this->assertSame(1, $skillRepo->count(['name' => 'php'])); + $this->assertSame(1, $skillRepo->count(['title' => 'php'])); $this->assertSame(1, $assetRepo->count([])); // Remove asset from skill @@ -338,7 +338,7 @@ class SkillRepositoryTest extends AbstractApiTest $this->assertSame(0, $assetRepo->count([])); // Skill exists. - $this->assertSame(1, $skillRepo->count(['name' => 'php'])); + $this->assertSame(1, $skillRepo->count(['title' => 'php'])); $em->clear(); diff --git a/tests/CoreBundle/Tool/ToolChainTest.php b/tests/CoreBundle/Tool/ToolChainTest.php index ecbc84a8d7..06dcf204a0 100644 --- a/tests/CoreBundle/Tool/ToolChainTest.php +++ b/tests/CoreBundle/Tool/ToolChainTest.php @@ -72,7 +72,7 @@ class ToolChainTest extends AbstractApiTest $em = $this->getEntityManager(); $toolRepo = $em->getRepository(Tool::class); - $agendaTool = $toolRepo->findOneBy(['name' => 'agenda']); + $agendaTool = $toolRepo->findOneBy(['title' => 'agenda']); $this->assertNotNull($agendaTool); $toolChain->setToolPermissions($agendaTool); diff --git a/tests/CourseBundle/Repository/CAnnouncementRepositoryTest.php b/tests/CourseBundle/Repository/CAnnouncementRepositoryTest.php index e1b81a67fd..58cf38429a 100644 --- a/tests/CourseBundle/Repository/CAnnouncementRepositoryTest.php +++ b/tests/CourseBundle/Repository/CAnnouncementRepositoryTest.php @@ -29,7 +29,7 @@ class CAnnouncementRepositoryTest extends AbstractApiTest $announcement = (new CAnnouncement()) ->setTitle('item') ->setContent('content') - ->setDisplayOrder(1) + //->setDisplayOrder(1) ->setEmailSent(false) ->setEndDate(new DateTime()) ->setParent($course) diff --git a/tests/CourseBundle/Repository/CAttendanceRepositoryTest.php b/tests/CourseBundle/Repository/CAttendanceRepositoryTest.php index e072e8331f..17477abd1f 100644 --- a/tests/CourseBundle/Repository/CAttendanceRepositoryTest.php +++ b/tests/CourseBundle/Repository/CAttendanceRepositoryTest.php @@ -86,6 +86,7 @@ class CAttendanceRepositoryTest extends AbstractApiTest ->setAttendance($attendance) ->setDateTime(new DateTime()) ->setDoneAttendance(true) + ->setBlocked(false) ; $em->persist($calendar); diff --git a/tests/CourseBundle/Repository/CGlossaryRepositoryTest.php b/tests/CourseBundle/Repository/CGlossaryRepositoryTest.php index 8f4ff1dedb..d2a227dab5 100644 --- a/tests/CourseBundle/Repository/CGlossaryRepositoryTest.php +++ b/tests/CourseBundle/Repository/CGlossaryRepositoryTest.php @@ -29,7 +29,7 @@ class CGlossaryRepositoryTest extends AbstractApiTest $glossary = (new CGlossary()) ->setTitle('glossary') ->setDescription('desc') - ->setDisplayOrder(1) + //->setDisplayOrder(1) ->setParent($course) ->setCreator($teacher) ->addCourseLink($course) @@ -40,7 +40,7 @@ class CGlossaryRepositoryTest extends AbstractApiTest $this->assertSame('glossary', (string) $glossary); $this->assertSame('desc', $glossary->getDescription()); - $this->assertSame(1, $glossary->getDisplayOrder()); + //$this->assertSame(1, $glossary->getDisplayOrder()); $this->assertSame($glossary->getResourceIdentifier(), $glossary->getIid()); $router = $this->getContainer()->get(RouterInterface::class); diff --git a/tests/CourseBundle/Repository/CLinkCategoryRepositoryTest.php b/tests/CourseBundle/Repository/CLinkCategoryRepositoryTest.php index 40913fb189..d876fcebf7 100644 --- a/tests/CourseBundle/Repository/CLinkCategoryRepositoryTest.php +++ b/tests/CourseBundle/Repository/CLinkCategoryRepositoryTest.php @@ -26,7 +26,7 @@ class CLinkCategoryRepositoryTest extends AbstractApiTest $category = (new CLinkCategory()) ->setTitle('cat') ->setDescription('desc') - ->setDisplayOrder(1) + //->setDisplayOrder(1) ->setParent($course) ->setCreator($teacher) ; @@ -38,7 +38,7 @@ class CLinkCategoryRepositoryTest extends AbstractApiTest $this->assertSame($category->getResourceIdentifier(), $category->getIid()); $this->assertSame('cat', (string) $category); $this->assertSame('desc', $category->getDescription()); - $this->assertSame('cat', $category->getCategoryTitle()); + $this->assertSame('cat', $category->getTitle()); $this->assertSame(1, $category->getDisplayOrder()); $this->assertSame(1, $repo->count([])); diff --git a/tests/CourseBundle/Repository/CLinkRepositoryTest.php b/tests/CourseBundle/Repository/CLinkRepositoryTest.php index eec8de8933..365d9dfa2e 100644 --- a/tests/CourseBundle/Repository/CLinkRepositoryTest.php +++ b/tests/CourseBundle/Repository/CLinkRepositoryTest.php @@ -27,7 +27,7 @@ class CLinkRepositoryTest extends AbstractApiTest ->setUrl('https://chamilo.org') ->setTitle('link') ->setDescription('desc') - ->setDisplayOrder(1) + //->setDisplayOrder(1) ->setTarget('_blank') ->setCategory(null) ->setParent($course) @@ -43,7 +43,7 @@ class CLinkRepositoryTest extends AbstractApiTest $this->assertSame('https://chamilo.org', $link->getUrl()); $this->assertSame('link', $link->getTitle()); $this->assertSame('desc', $link->getDescription()); - $this->assertSame(1, $link->getDisplayOrder()); + //$this->assertSame(1, $link->getDisplayOrder()); $this->assertSame('_blank', $link->getTarget()); $this->assertSame(1, $repo->count([])); diff --git a/tests/CourseBundle/Repository/CToolRepositoryTest.php b/tests/CourseBundle/Repository/CToolRepositoryTest.php index fd80482cc3..a80a2b461b 100644 --- a/tests/CourseBundle/Repository/CToolRepositoryTest.php +++ b/tests/CourseBundle/Repository/CToolRepositoryTest.php @@ -28,7 +28,7 @@ class CToolRepositoryTest extends AbstractApiTest $defaultCount = $repo->count([]); $admin = $this->getUser('admin'); - $tool = $toolRepo->findOneBy(['name' => 'course_homepage']); + $tool = $toolRepo->findOneBy(['title' => 'course_homepage']); $this->assertNotNull($tool); $cTool = (new CTool()) diff --git a/tests/README.md b/tests/README.md index 4399c64a57..7e7a714713 100755 --- a/tests/README.md +++ b/tests/README.md @@ -3,10 +3,10 @@ This directory is being used for all kinds of tests and scripts and is removed from public releases as it may represent a risk for production systems. -## Behat +## Behat Make sure you set the right base_url in behat/behat.yml, then run (on the command -line, from the tests/ directory): +line, from the tests/ directory): ``` ../vendor/behat/behat/bin/behat behat/features/login.feature ../vendor/behat/behat/bin/behat behat/features/createUser.feature @@ -17,7 +17,7 @@ line, from the tests/ directory): ../vendor/behat/behat/bin/behat behat/features/accessCompanyReports.feature ``` -## PHPUnit +## PHPUnit We use the default Symfony PHPUnit settings: @@ -35,7 +35,7 @@ DATABASE_USER='root' DATABASE_PASSWORD='root' ``` -After creating the .env.test.local file execute: +After creating the .env.test.local file execute: ``` php bin/console --env=test cache:clear @@ -52,10 +52,10 @@ Those commands will install Chamilo in the chamilo_test database. In order to delete the test database and restart the process use: -`php bin/console --env=test doctrine:database:drop` +`php bin/console --env=test doctrine:database:drop --force` -### Use -Execute the tests with: +### Use +Execute the tests with: `php bin/phpunit`