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/CourseBundle/Repository/CLpCategoryRepositoryTest.php

84 lines
2.6 KiB

<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\Tests\CourseBundle\Repository;
use Chamilo\CourseBundle\Entity\CLpCategory;
use Chamilo\CourseBundle\Entity\CLpCategoryRelUser;
use Chamilo\CourseBundle\Repository\CLpCategoryRepository;
use Chamilo\Tests\AbstractApiTest;
use Chamilo\Tests\ChamiloTestTrait;
class CLpCategoryRepositoryTest extends AbstractApiTest
{
use ChamiloTestTrait;
public function testCreate(): void
{
$em = $this->getEntityManager();
$repo = self::getContainer()->get(CLpCategoryRepository::class);
$course = $this->createCourse('new');
$teacher = $this->createUser('teacher');
4 years ago
$category = (new CLpCategory())
->setTitle('cat')
->setParent($course)
->setCreator($teacher)
;
Internal: Move display_order from ResourceNode to ResourceLink (#5143) * Internal: Move display_order from ResourceNode to ResourceLink #5137 * Internal: Use ResourceLink $displayOrder instead of ResourceNode $displayOrder #5137 * Internal: Remove ResourceNode $displayOrder #5137 * Vendor: Bump stof/doctrine-extensions-bundle version to 1.10 #5137 * Forum: Fix query to get forums in category ordered by resourceLink.displayOrder * LP: Refactoring delete method to mark the resource link as deleted instead of remove the lp as resource * LP: Fix query to set a custom order in lp list * LP: Fix buttons to sort learn paths * Rename ResourceNode::getResourceLinkByTypeGroup to ResourceNode::getResourceLinkByContext and change order or its params * LP: Change display resource link display order when moving category position * LP: Fix layout for old list view * Forum: Fix sorting for forums and categories * Course Progress: Fix sorting for sections * Internal: Enable SoftDeleteable for ResourceLink entities * Remove ResourceLink::VISIBILITY_DELETED in favor of soft delete * Internal: Refactoring migration about display_order in course tools * LP: Refactoring the category delete method to make a soft delete of the resource link * LP: Refactoring the thematic delete method to make a soft delete of the resource link * LP: Refactoring the forum delete methods to make a soft delete of the resource link * Add shortcut method to remove resource link from its resource * CI: Fix ResourceNodeRepositoryTest by adding a link to the resource node * Internal: Migration: Drop display_order column from c_lp table * Internal: Migration: Drop position column from c_lp_category table * Internal: Migration: Drop cat_order column from c_forum_category table * Internal: Migration: Drop forum_order column from c_forum_forum table * Internal: Migration: Drop display_order column from c_thematic table * Minor: Format code * Announcement: Fix order of the course announcements * Internal: Refactoring migration * Internal: Migration: Drop display_order column from c_glossary table * Refactoring method to move display order of resource links
2 years ago
$category->addCourseLink($course);
4 years ago
$this->assertHasNoEntityViolations($category);
$em->persist($category);
$em->flush();
Internal: Move display_order from ResourceNode to ResourceLink (#5143) * Internal: Move display_order from ResourceNode to ResourceLink #5137 * Internal: Use ResourceLink $displayOrder instead of ResourceNode $displayOrder #5137 * Internal: Remove ResourceNode $displayOrder #5137 * Vendor: Bump stof/doctrine-extensions-bundle version to 1.10 #5137 * Forum: Fix query to get forums in category ordered by resourceLink.displayOrder * LP: Refactoring delete method to mark the resource link as deleted instead of remove the lp as resource * LP: Fix query to set a custom order in lp list * LP: Fix buttons to sort learn paths * Rename ResourceNode::getResourceLinkByTypeGroup to ResourceNode::getResourceLinkByContext and change order or its params * LP: Change display resource link display order when moving category position * LP: Fix layout for old list view * Forum: Fix sorting for forums and categories * Course Progress: Fix sorting for sections * Internal: Enable SoftDeleteable for ResourceLink entities * Remove ResourceLink::VISIBILITY_DELETED in favor of soft delete * Internal: Refactoring migration about display_order in course tools * LP: Refactoring the category delete method to make a soft delete of the resource link * LP: Refactoring the thematic delete method to make a soft delete of the resource link * LP: Refactoring the forum delete methods to make a soft delete of the resource link * Add shortcut method to remove resource link from its resource * CI: Fix ResourceNodeRepositoryTest by adding a link to the resource node * Internal: Migration: Drop display_order column from c_lp table * Internal: Migration: Drop position column from c_lp_category table * Internal: Migration: Drop cat_order column from c_forum_category table * Internal: Migration: Drop forum_order column from c_forum_forum table * Internal: Migration: Drop display_order column from c_thematic table * Minor: Format code * Announcement: Fix order of the course announcements * Internal: Refactoring migration * Internal: Migration: Drop display_order column from c_glossary table * Refactoring method to move display order of resource links
2 years ago
$link = $category->getResourceNode()->getResourceLinkByContext($course);
$this->assertSame($category->getResourceIdentifier(), $category->getIid());
Internal: Move display_order from ResourceNode to ResourceLink (#5143) * Internal: Move display_order from ResourceNode to ResourceLink #5137 * Internal: Use ResourceLink $displayOrder instead of ResourceNode $displayOrder #5137 * Internal: Remove ResourceNode $displayOrder #5137 * Vendor: Bump stof/doctrine-extensions-bundle version to 1.10 #5137 * Forum: Fix query to get forums in category ordered by resourceLink.displayOrder * LP: Refactoring delete method to mark the resource link as deleted instead of remove the lp as resource * LP: Fix query to set a custom order in lp list * LP: Fix buttons to sort learn paths * Rename ResourceNode::getResourceLinkByTypeGroup to ResourceNode::getResourceLinkByContext and change order or its params * LP: Change display resource link display order when moving category position * LP: Fix layout for old list view * Forum: Fix sorting for forums and categories * Course Progress: Fix sorting for sections * Internal: Enable SoftDeleteable for ResourceLink entities * Remove ResourceLink::VISIBILITY_DELETED in favor of soft delete * Internal: Refactoring migration about display_order in course tools * LP: Refactoring the category delete method to make a soft delete of the resource link * LP: Refactoring the thematic delete method to make a soft delete of the resource link * LP: Refactoring the forum delete methods to make a soft delete of the resource link * Add shortcut method to remove resource link from its resource * CI: Fix ResourceNodeRepositoryTest by adding a link to the resource node * Internal: Migration: Drop display_order column from c_lp table * Internal: Migration: Drop position column from c_lp_category table * Internal: Migration: Drop cat_order column from c_forum_category table * Internal: Migration: Drop forum_order column from c_forum_forum table * Internal: Migration: Drop display_order column from c_thematic table * Minor: Format code * Announcement: Fix order of the course announcements * Internal: Refactoring migration * Internal: Migration: Drop display_order column from c_glossary table * Refactoring method to move display order of resource links
2 years ago
$this->assertSame(0, $link?->getDisplayOrder());
4 years ago
$this->assertSame('cat', (string) $category);
$this->assertSame(1, $repo->count([]));
4 years ago
$link = $repo->getLink($category, $this->getContainer()->get('router'));
$this->assertSame('/main/lp/lp_controller.php?id='.$category->getIid().'&action=view_category', $link);
}
public function testCreateWithUser(): void
{
$em = $this->getEntityManager();
$repo = self::getContainer()->get(CLpCategoryRepository::class);
$course = $this->createCourse('new');
$teacher = $this->createUser('teacher');
$student = $this->createUser('student');
$student2 = $this->createUser('student2');
$category = (new CLpCategory())
->setTitle('cat')
4 years ago
->setParent($course)
->setCreator($teacher)
;
$em->persist($category);
$em->flush();
$categoryRelUser = (new CLpCategoryRelUser())
4 years ago
->setCategory($category)
->setUser($teacher)
;
$em->persist($categoryRelUser);
$category->addUser($categoryRelUser);
$em->flush();
$this->assertSame(1, $repo->count([]));
4 years ago
/** @var CLpCategory $category */
$category = $repo->find($category->getIid());
$this->assertTrue($category->hasResourceNode());
$this->assertTrue($category->hasUserAdded($teacher));
$this->assertFalse($category->hasUserAdded($student));
}
}