CToolIntro: Fix test + remove unused code.

pull/4004/head
Julio 4 years ago
parent c95f5514bb
commit 3b0b977985
  1. 22
      src/CoreBundle/Controller/Api/CreateCToolIntroAction.php
  2. 31
      src/CoreBundle/Controller/Api/UpdateCToolIntroAction.php
  3. 5
      src/CourseBundle/Entity/CToolIntro.php
  4. 22
      tests/CourseBundle/Repository/CToolIntroRepositoryTest.php

@ -1,22 +0,0 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Controller\Api;
use Chamilo\CourseBundle\Entity\CToolIntro;
use Chamilo\CourseBundle\Repository\CToolIntroRepository;
use Doctrine\ORM\EntityManager;
use Symfony\Component\HttpFoundation\Request;
class CreateCToolIntroAction extends BaseResourceFileAction
{
public function __invoke(Request $request, CToolIntroRepository $repo, EntityManager $em): CToolIntro
{
$result = $this->handleCreateRequest(new CToolIntro(), $repo, $request);
return $repo->updateToolIntro($em, $result['introText']);
}
}

@ -1,31 +0,0 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Controller\Api;
use Chamilo\CourseBundle\Entity\CToolIntro;
use Chamilo\CourseBundle\Repository\CToolIntroRepository;
use Symfony\Component\HttpFoundation\Request;
class UpdateCToolIntroAction extends BaseResourceFileAction
{
public function __invoke(
CToolIntro $toolIntro,
Request $request,
CToolIntroRepository $repo,
EntityManager $em
): CToolIntro {
$this->handleUpdateRequest($toolIntro, $repo, $request, $em);
$result = json_decode($request->getContent(), true);
var_dump($result);
//$toolIntro = $repo->updateToolIntro($em, $result['introText']);
return $toolIntro;
}
}

@ -9,8 +9,6 @@ namespace Chamilo\CourseBundle\Entity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use Chamilo\CoreBundle\Controller\Api\CreateCToolIntroAction;
//use Chamilo\CoreBundle\Controller\Api\UpdateCToolIntroAction;
use Chamilo\CoreBundle\Entity\AbstractResource;
use Chamilo\CoreBundle\Entity\ResourceInterface;
use Chamilo\CoreBundle\Entity\ResourceShowCourseResourcesInSessionInterface;
@ -33,7 +31,6 @@ use Symfony\Component\Validator\Constraints as Assert;
'security' => "is_granted('ROLE_USER')",
],
'post' => [
'controller' => CreateCToolIntroAction::class,
'security_post_denormalize' => "is_granted('CREATE', object)",
],
],
@ -42,8 +39,6 @@ use Symfony\Component\Validator\Constraints as Assert;
'security' => "is_granted('VIEW', object)",
],
'put' => [
//'controller' => UpdateCToolIntroAction::class,
//'deserialize' => false,
'security' => "is_granted('EDIT', object)",
],
'delete' => [

@ -6,6 +6,7 @@ declare(strict_types=1);
namespace Chamilo\Tests\CourseBundle\Repository;
use Chamilo\CoreBundle\Entity\ResourceLink;
use Chamilo\CourseBundle\Entity\CTool;
use Chamilo\CourseBundle\Entity\CToolIntro;
use Chamilo\CourseBundle\Repository\CToolIntroRepository;
@ -75,9 +76,7 @@ class CToolIntroRepositoryTest extends AbstractApiTest
public function testCreateIntroApi(): void
{
$course = $this->createCourse('new');
$token = $this->getUserToken();
$resourceNodeId = $course->getResourceNode()->getId();
/** @var CTool $courseTool */
@ -85,7 +84,7 @@ class CToolIntroRepositoryTest extends AbstractApiTest
$iri = '/api/c_tools/'.$courseTool->getIid();
$this->createClientWithCredentials($token)->request(
$response = $this->createClientWithCredentials($token)->request(
'POST',
'/api/c_tool_intros',
[
@ -93,6 +92,12 @@ class CToolIntroRepositoryTest extends AbstractApiTest
'introText' => 'introduction here',
'courseTool' => $iri,
'parentResourceNodeId' => $resourceNodeId,
'resourceLinkList' => [
[
'cid' => $course->getId(),
'visibility' => ResourceLink::VISIBILITY_PUBLISHED
]
]
],
]
);
@ -105,6 +110,17 @@ class CToolIntroRepositoryTest extends AbstractApiTest
'@type' => 'CToolIntro',
'introText' => 'introduction here',
]);
$repo = self::getContainer()->get(CToolIntroRepository::class);
$id = $response->toArray()['iid'];
/** @var CToolIntro $toolIntro */
$toolIntro = $repo->find($id);
$this->assertNotNull($toolIntro);
$this->assertNotNull($toolIntro->getResourceNode());
$this->assertsame(1, $toolIntro->getResourceNode()->getResourceLinks()->count());
$this->assertSame(1, $repo->count([]));
}
public function testUpdateIntroApi(): void

Loading…
Cancel
Save