Tests: Add phpunit tests

pull/3965/head
Julio 4 years ago
parent 4e8a5fcedb
commit 057f7ea2ef
  1. 21
      tests/CourseBundle/Repository/CDocumentRepositoryTest.php

@ -189,14 +189,6 @@ class CDocumentRepositoryTest extends AbstractApiTest
// Test access with another user. He cannot see the file, no cid is pass as a parameter. // Test access with another user. He cannot see the file, no cid is pass as a parameter.
$this->createUser('another'); $this->createUser('another');
$token = $this->getUserToken(
[
'username' => 'another',
'password' => 'another',
],
true
);
$client = $this->getClientWithGuiCredentials('another', 'another'); $client = $this->getClientWithGuiCredentials('another', 'another');
$client->request( $client->request(
'GET', 'GET',
@ -207,14 +199,14 @@ class CDocumentRepositoryTest extends AbstractApiTest
); );
$this->assertResponseStatusCodeSame(403); // Unauthorized $this->assertResponseStatusCodeSame(403); // Unauthorized
$this->createClientWithCredentials($token)->request('GET', '/api/documents', [ $client->request('GET', '/api/documents', [
'query' => [ 'query' => [
'loadNode' => 1, 'loadNode' => 1,
'resourceNode.parent' => $course->getResourceNode()->getId(), 'resourceNode.parent' => $course->getResourceNode()->getId(),
'cid' => $courseId, 'cid' => $courseId,
], ],
]); ]);
$this->assertResponseStatusCodeSame(403); // Unauthorized $this->assertResponseStatusCodeSame(200);
// Test access with another user. He CAN see the file, the cid is pass as a parameter // Test access with another user. He CAN see the file, the cid is pass as a parameter
// and the course is open to the world by default. // and the course is open to the world by default.
@ -248,6 +240,15 @@ class CDocumentRepositoryTest extends AbstractApiTest
); );
$this->assertResponseStatusCodeSame(403); $this->assertResponseStatusCodeSame(403);
$client->request('GET', '/api/documents', [
'query' => [
'loadNode' => 1,
'resourceNode.parent' => $course->getResourceNode()->getId(),
'cid' => $courseId,
],
]);
$this->assertResponseStatusCodeSame(403);
// Update course visibility to CLOSED // Update course visibility to CLOSED
$courseRepo = self::getContainer()->get(CourseRepository::class); $courseRepo = self::getContainer()->get(CourseRepository::class);
$course = $courseRepo->find($courseId); $course = $courseRepo->find($courseId);

Loading…
Cancel
Save