|
|
@ -6,8 +6,6 @@ declare(strict_types=1); |
|
|
|
|
|
|
|
|
|
|
|
namespace Chamilo\Tests\CourseBundle\Repository; |
|
|
|
namespace Chamilo\Tests\CourseBundle\Repository; |
|
|
|
|
|
|
|
|
|
|
|
use Chamilo\CoreBundle\Entity\Course; |
|
|
|
|
|
|
|
use Chamilo\CoreBundle\Repository\Node\CourseRepository; |
|
|
|
|
|
|
|
use Chamilo\CourseBundle\Entity\CDocument; |
|
|
|
use Chamilo\CourseBundle\Entity\CDocument; |
|
|
|
use Chamilo\Tests\AbstractApiTest; |
|
|
|
use Chamilo\Tests\AbstractApiTest; |
|
|
|
use Chamilo\Tests\ChamiloTestTrait; |
|
|
|
use Chamilo\Tests\ChamiloTestTrait; |
|
|
@ -20,7 +18,7 @@ class CDocumentRepositoryTest extends AbstractApiTest |
|
|
|
{ |
|
|
|
{ |
|
|
|
use ChamiloTestTrait; |
|
|
|
use ChamiloTestTrait; |
|
|
|
|
|
|
|
|
|
|
|
public function testGetDocuments(): void |
|
|
|
public function testGetDocumentsAsAdmin(): void |
|
|
|
{ |
|
|
|
{ |
|
|
|
$token = $this->getUserToken([]); |
|
|
|
$token = $this->getUserToken([]); |
|
|
|
$response = $this->createClientWithCredentials($token)->request('GET', '/api/documents'); |
|
|
|
$response = $this->createClientWithCredentials($token)->request('GET', '/api/documents'); |
|
|
@ -35,10 +33,6 @@ class CDocumentRepositoryTest extends AbstractApiTest |
|
|
|
'@id' => '/api/documents', |
|
|
|
'@id' => '/api/documents', |
|
|
|
'@type' => 'hydra:Collection', |
|
|
|
'@type' => 'hydra:Collection', |
|
|
|
'hydra:totalItems' => 0, |
|
|
|
'hydra:totalItems' => 0, |
|
|
|
/*'hydra:view' => [ |
|
|
|
|
|
|
|
'@id' => '/api/documents?page=1', |
|
|
|
|
|
|
|
'@type' => 'hydra:PartialCollectionView', |
|
|
|
|
|
|
|
],*/ |
|
|
|
|
|
|
|
]); |
|
|
|
]); |
|
|
|
|
|
|
|
|
|
|
|
$this->assertCount(0, $response->toArray()['hydra:member']); |
|
|
|
$this->assertCount(0, $response->toArray()['hydra:member']); |
|
|
@ -47,18 +41,7 @@ class CDocumentRepositoryTest extends AbstractApiTest |
|
|
|
|
|
|
|
|
|
|
|
public function testCreateFolder(): void |
|
|
|
public function testCreateFolder(): void |
|
|
|
{ |
|
|
|
{ |
|
|
|
$courseRepo = self::getContainer()->get(CourseRepository::class); |
|
|
|
$course = $this->createCourse('Test'); |
|
|
|
|
|
|
|
|
|
|
|
$admin = $this->getUser('admin'); |
|
|
|
|
|
|
|
$accessUrl = $this->getAccessUrl(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$course = (new Course()) |
|
|
|
|
|
|
|
->setTitle('Test course') |
|
|
|
|
|
|
|
->setCode('test_course') |
|
|
|
|
|
|
|
->addAccessUrl($accessUrl) |
|
|
|
|
|
|
|
->setCreator($admin) |
|
|
|
|
|
|
|
; |
|
|
|
|
|
|
|
$courseRepo->create($course); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create folder. |
|
|
|
// Create folder. |
|
|
|
$resourceLinkList = [ |
|
|
|
$resourceLinkList = [ |
|
|
@ -66,13 +49,15 @@ class CDocumentRepositoryTest extends AbstractApiTest |
|
|
|
'visibility' => 2, |
|
|
|
'visibility' => 2, |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$folderName = 'folder1'; |
|
|
|
$token = $this->getUserToken([]); |
|
|
|
$token = $this->getUserToken([]); |
|
|
|
$this->createClientWithCredentials($token)->request( |
|
|
|
$this->createClientWithCredentials($token)->request( |
|
|
|
'POST', |
|
|
|
'POST', |
|
|
|
'/api/documents', |
|
|
|
'/api/documents', |
|
|
|
[ |
|
|
|
[ |
|
|
|
'json' => [ |
|
|
|
'json' => [ |
|
|
|
'title' => 'folder1', |
|
|
|
'title' => $folderName, |
|
|
|
|
|
|
|
'filetype' => 'folder', |
|
|
|
'parentResourceNodeId' => $course->getResourceNode()->getId(), |
|
|
|
'parentResourceNodeId' => $course->getResourceNode()->getId(), |
|
|
|
'resourceLinkList' => json_encode($resourceLinkList), |
|
|
|
'resourceLinkList' => json_encode($resourceLinkList), |
|
|
|
], |
|
|
|
], |
|
|
@ -85,39 +70,101 @@ class CDocumentRepositoryTest extends AbstractApiTest |
|
|
|
$this->assertJsonContains([ |
|
|
|
$this->assertJsonContains([ |
|
|
|
'@context' => '/api/contexts/Documents', |
|
|
|
'@context' => '/api/contexts/Documents', |
|
|
|
'@type' => 'Documents', |
|
|
|
'@type' => 'Documents', |
|
|
|
'title' => 'folder1', |
|
|
|
'title' => $folderName, |
|
|
|
]); |
|
|
|
]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function testCreateFile(): void |
|
|
|
public function testUploadFile(): void |
|
|
|
{ |
|
|
|
{ |
|
|
|
$courseRepo = self::getContainer()->get(CourseRepository::class); |
|
|
|
$course = $this->createCourse('Test'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$resourceLinkList = [ |
|
|
|
|
|
|
|
'cid' => $course->getId(), |
|
|
|
|
|
|
|
'visibility' => 2, |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$path = $this->getContainer()->get('kernel')->getProjectDir(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$filePath = $path.'/public/img/logo.png'; |
|
|
|
|
|
|
|
$fileName = basename($filePath); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$file = new UploadedFile( |
|
|
|
|
|
|
|
$filePath, |
|
|
|
|
|
|
|
$fileName, |
|
|
|
|
|
|
|
'image/png', |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$token = $this->getUserToken([]); |
|
|
|
|
|
|
|
$this->createClientWithCredentials($token)->request( |
|
|
|
|
|
|
|
'POST', |
|
|
|
|
|
|
|
'/api/documents', |
|
|
|
|
|
|
|
[ |
|
|
|
|
|
|
|
'headers' => [ |
|
|
|
|
|
|
|
'Content-Type' => 'multipart/form-data', |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
'extra' => [ |
|
|
|
|
|
|
|
'files' => [ |
|
|
|
|
|
|
|
'uploadFile' => $file, |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
'json' => [ |
|
|
|
|
|
|
|
'filetype' => 'file', |
|
|
|
|
|
|
|
'size' => filesize($filePath), |
|
|
|
|
|
|
|
'parentResourceNodeId' => $course->getResourceNode()->getId(), |
|
|
|
|
|
|
|
'resourceLinkList' => json_encode($resourceLinkList), |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
$admin = $this->getUser('admin'); |
|
|
|
$this->assertResponseIsSuccessful(); |
|
|
|
// Get access url. |
|
|
|
$this->assertResponseStatusCodeSame(201); |
|
|
|
$accessUrl = $this->getAccessUrl(); |
|
|
|
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8'); |
|
|
|
|
|
|
|
$this->assertJsonContains([ |
|
|
|
|
|
|
|
'@context' => '/api/contexts/Documents', |
|
|
|
|
|
|
|
'@type' => 'Documents', |
|
|
|
|
|
|
|
'title' => $fileName, |
|
|
|
|
|
|
|
'filetype' => 'file', |
|
|
|
|
|
|
|
]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$course = (new Course()) |
|
|
|
public function testUploadFileInSideASubFolder(): void |
|
|
|
->setTitle('Test course') |
|
|
|
{ |
|
|
|
->setCode('test_course') |
|
|
|
$course = $this->createCourse('Test'); |
|
|
|
->addAccessUrl($accessUrl) |
|
|
|
|
|
|
|
->setCreator($admin) |
|
|
|
|
|
|
|
; |
|
|
|
|
|
|
|
$courseRepo->create($course); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create file. |
|
|
|
// Create folder. |
|
|
|
$resourceLinkList = [ |
|
|
|
$resourceLinkList = [ |
|
|
|
'cid' => $course->getId(), |
|
|
|
'cid' => $course->getId(), |
|
|
|
'visibility' => 2, |
|
|
|
'visibility' => 2, |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$token = $this->getUserToken([]); |
|
|
|
|
|
|
|
// Creates a folder. |
|
|
|
|
|
|
|
$folderName = 'test'; |
|
|
|
|
|
|
|
$response = $this->createClientWithCredentials($token)->request( |
|
|
|
|
|
|
|
'POST', |
|
|
|
|
|
|
|
'/api/documents', |
|
|
|
|
|
|
|
[ |
|
|
|
|
|
|
|
'json' => [ |
|
|
|
|
|
|
|
'title' => $folderName, |
|
|
|
|
|
|
|
'filetype' => 'folder', |
|
|
|
|
|
|
|
'parentResourceNodeId' => $course->getResourceNode()->getId(), |
|
|
|
|
|
|
|
'resourceLinkList' => json_encode($resourceLinkList), |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertResponseIsSuccessful(); |
|
|
|
|
|
|
|
$data = json_decode($response->getContent()); |
|
|
|
|
|
|
|
$resourceNodeId = $data->resourceNode->id; |
|
|
|
|
|
|
|
|
|
|
|
$path = $this->getContainer()->get('kernel')->getProjectDir(); |
|
|
|
$path = $this->getContainer()->get('kernel')->getProjectDir(); |
|
|
|
|
|
|
|
|
|
|
|
$filePath = $path.'/public/img/logo.png'; |
|
|
|
$filePath = $path.'/public/img/logo.png'; |
|
|
|
|
|
|
|
$fileName = basename($filePath); |
|
|
|
|
|
|
|
|
|
|
|
$file = new UploadedFile( |
|
|
|
$file = new UploadedFile( |
|
|
|
$filePath, |
|
|
|
$filePath, |
|
|
|
'logo.png', |
|
|
|
$fileName, |
|
|
|
'image/png', |
|
|
|
'image/png', |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
@ -135,13 +182,10 @@ class CDocumentRepositoryTest extends AbstractApiTest |
|
|
|
], |
|
|
|
], |
|
|
|
], |
|
|
|
], |
|
|
|
'json' => [ |
|
|
|
'json' => [ |
|
|
|
'title' => 'my image', |
|
|
|
|
|
|
|
'type' => 'image/jpeg', |
|
|
|
|
|
|
|
'filetype' => 'file', |
|
|
|
'filetype' => 'file', |
|
|
|
'size' => filesize($filePath), |
|
|
|
'size' => filesize($filePath), |
|
|
|
'parentResourceNodeId' => $course->getResourceNode()->getId(), |
|
|
|
'parentResourceNodeId' => $resourceNodeId, |
|
|
|
'resourceLinkList' => json_encode($resourceLinkList), |
|
|
|
'resourceLinkList' => json_encode($resourceLinkList), |
|
|
|
//'uploadFile' => new F |
|
|
|
|
|
|
|
], |
|
|
|
], |
|
|
|
] |
|
|
|
] |
|
|
|
); |
|
|
|
); |
|
|
@ -152,7 +196,8 @@ class CDocumentRepositoryTest extends AbstractApiTest |
|
|
|
$this->assertJsonContains([ |
|
|
|
$this->assertJsonContains([ |
|
|
|
'@context' => '/api/contexts/Documents', |
|
|
|
'@context' => '/api/contexts/Documents', |
|
|
|
'@type' => 'Documents', |
|
|
|
'@type' => 'Documents', |
|
|
|
'title' => 'my image', |
|
|
|
'title' => $fileName, |
|
|
|
|
|
|
|
'filetype' => 'file', |
|
|
|
]); |
|
|
|
]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|