Skip to content

Commit

Permalink
Add video tests (#1105)
Browse files Browse the repository at this point in the history
* Add tests for videos

* Refactor playlist acl tests

Decreases redundant code
  • Loading branch information
dennis531 authored Dec 11, 2024
1 parent d373865 commit 7acaad2
Show file tree
Hide file tree
Showing 9 changed files with 371 additions and 163 deletions.
3 changes: 2 additions & 1 deletion codeception.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ suites:
- REST:
url: '%STUDIP_REST_URL%'
depends: PhpBrowser
- Asserts
- \Helper\Api:
opencast_rest_url: '%OPENCAST_REST_URL%'
opencast_url: '%OPENCAST_URL%'
api_token: '%API_TOKEN%'
opencast_admin_user: '%OPENCAST_ADMIN_NAME%'
opencast_admin_password: '%OPENCAST_ADMIN_PASSWORD%'
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"codeception/module-phpbrowser": "^1.0.0",
"codeception/module-asserts": "^1.0.0",
"codeception/module-rest": "^1.0.0",
"vlucas/phpdotenv": "^5.6"
"vlucas/phpdotenv": "^5.6",
"guzzlehttp/guzzle": ">=7.5.1"
}
}
2 changes: 1 addition & 1 deletion tests/.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
STUDIP_REST_URL=http://localhost/plugins.php/opencastv3/api
OPENCAST_REST_URL=http://127.0.0.1:8081/api
OPENCAST_URL=http://127.0.0.1:8081

# Opencast server ID
CONFIG_ID=1
Expand Down
159 changes: 0 additions & 159 deletions tests/AclCest.php

This file was deleted.

36 changes: 36 additions & 0 deletions tests/CoursesCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
class CoursesCest
{
private $config_id;
private $api_token;
private $course_student;
private $course_id;

public function _before(ApiTester $I)
{
$config = $I->getConfig();

$this->config_id = $config['config_id'];
$this->api_token = $config['api_token'];
$this->course_student = $config['course_student'];
$this->course_id = $config['course_id'];

$I->amHttpAuthenticated($config['dozent_name'], $config['dozent_password']);
Expand Down Expand Up @@ -68,10 +72,27 @@ public function testAddPlaylist(ApiTester $I)
$I->seeResponseContainsJson(['users' => [['perm' => 'owner']]]);

list($token) = $I->grabDataFromResponseByJsonPath('$.token');
list($service_playlist_id) = $I->grabDataFromResponseByJsonPath('$.service_playlist_id');

// Add playlist to course
$response = $I->sendPost('/courses/' . $this->course_id . '/playlist/' . $token);
$I->seeResponseCodeIs(204);

// Check if student of course has read access only
$response = $I->sendGetAsJson('/opencast/user/' . $this->course_student, ['token' => $this->api_token]);

$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();

$I->seeResponseContainsJson([
'username' => $this->course_student,
'roles' => [
'PLAYLIST_' . $service_playlist_id . '_read',
]
]);
$I->dontSeeResponseContainsJson(['roles' => [
'PLAYLIST_' . $service_playlist_id . '_write',
]]);
}

public function testRemovePlaylist(ApiTester $I)
Expand All @@ -92,6 +113,7 @@ public function testRemovePlaylist(ApiTester $I)
$I->seeResponseContainsJson(['users' => [['perm' => 'owner']]]);

list($token) = $I->grabDataFromResponseByJsonPath('$.token');
list($service_playlist_id) = $I->grabDataFromResponseByJsonPath('$.service_playlist_id');

// Add playlist to course
$response = $I->sendPost('/courses/' . $this->course_id . '/playlist/' . $token);
Expand All @@ -100,6 +122,20 @@ public function testRemovePlaylist(ApiTester $I)
// Remove playlist from course
$response = $I->sendDelete('/courses/' . $this->course_id . '/playlist/' . $token);
$I->seeResponseCodeIs(204);

// Check if student of course has no access
$response = $I->sendGetAsJson('/opencast/user/' . $this->course_student, ['token' => $this->api_token]);

$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();

$roles = ['PLAYLIST_' . $service_playlist_id . '_read', 'PLAYLIST_' . $service_playlist_id . '_write'];
foreach ($roles as $role) {
$I->dontseeResponseContainsJson([
'username' => $this->course_student,
'roles' => [$role]
]);
}
}

}
37 changes: 37 additions & 0 deletions tests/PlaylistsCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,26 @@

class PlaylistsCest
{
private $opencast_url;
private $config_id;
private $api_token;
private $opencast_admin_user;
private $opencast_admin_password;

private $dozent_name;
private $author_name;
private $author_password;

public function _before(ApiTester $I)
{
$config = $I->getConfig();

$this->opencast_url = $config['opencast_url'];
$this->config_id = $config['config_id'];
$this->api_token = $config['api_token'];
$this->opencast_admin_user = $config['opencast_admin_user'];
$this->opencast_admin_password = $config['opencast_admin_password'];
$this->dozent_name = $config['dozent_name'];
$this->author_name = $config['author_name'];
$this->author_password = $config['author_password'];

Expand All @@ -34,6 +44,33 @@ public function testCreatePlaylist(ApiTester $I)

$I->seeResponseContainsJson($playlist);
$I->seeResponseContainsJson(['users' => [['perm' => 'owner']]]);

list($service_playlist_id) = $I->grabDataFromResponseByJsonPath('$.service_playlist_id');

// Check if user has correct playlist role
$response = $I->sendGetAsJson('/opencast/user/' . $this->dozent_name, ['token' => $this->api_token]);

$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();

$I->seeResponseContainsJson([
'username' => $this->dozent_name,
'roles' => [
'PLAYLIST_' . $service_playlist_id . '_write',
]
]);

// Check ACLs in Opencast

// Login as opencast admin
$I->amHttpAuthenticated($this->opencast_admin_user, $this->opencast_admin_password);

$response = $I->sendGetAsJson($this->opencast_url . '/api/playlists/' . $service_playlist_id);
$I->seeResponseContainsJson(['accessControlEntries' => [
['allow' => true, 'role' => 'PLAYLIST_' . $service_playlist_id . '_read', 'action' => 'read'],
['allow' => true, 'role' => 'PLAYLIST_' . $service_playlist_id . '_write', 'action' => 'read'],
['allow' => true, 'role' => 'PLAYLIST_' . $service_playlist_id . '_write', 'action' => 'write'],
]]);
}

public function testDeletePlaylist(ApiTester $I)
Expand Down
Loading

0 comments on commit 7acaad2

Please sign in to comment.