99 lines
3.6 KiB
PHP
99 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Domain\Catalog\ArticleService;
|
|
use App\Domain\Catalog\ContentService;
|
|
use App\Domain\Catalog\ContentVersionStatus;
|
|
use App\Domain\Catalog\OfferService;
|
|
use App\Domain\Entitlement\GrantIssuer;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Tests\TestCase;
|
|
|
|
class CoursePlayerTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_a_course_is_shown_by_its_name_and_can_pause_at_the_decision(): void
|
|
{
|
|
$content = app(ContentService::class);
|
|
$articles = app(ArticleService::class);
|
|
$offers = app(OfferService::class);
|
|
$film = $content->publishElementVersion(
|
|
$content->createElement('film', 'film', 'Übungsfilm'),
|
|
'Erst ansehen, dann entscheiden.',
|
|
['decision_seconds' => 12, 'file' => 'inhalte/film.mp4'],
|
|
);
|
|
$course = $content->publishComposition(
|
|
$content->createComposition('Alltag üben'),
|
|
[['role' => 'Film', 'target' => $film]],
|
|
);
|
|
$article = $articles->create('kurs-alltag', 'Erprobung');
|
|
$articles->publishRelease($article, $course, 'Der Kurs für den Alltag.');
|
|
$rights = $offers->createRightsProfile('Kurs sehen', 'ehrenamtlich', [
|
|
'film' => ['streamen', 'ansehen'],
|
|
]);
|
|
$offer = $offers->create('Kursangebot');
|
|
$offers->activate($offer, [
|
|
['target' => $article->fresh(), 'rights' => $rights],
|
|
], ['grant_kind' => 'auf_abruf']);
|
|
$member = User::factory()->create();
|
|
app(GrantIssuer::class)->claim($member, $offer);
|
|
|
|
$this->actingAs($member)
|
|
->get(route('member.library'))
|
|
->assertOk()
|
|
->assertSee('Kurse')
|
|
->assertSee('Alltag üben');
|
|
|
|
$this->actingAs($member)
|
|
->get(route('member.article', $article))
|
|
->assertOk()
|
|
->assertSee('Alltag üben')
|
|
->assertSee('Erst ansehen, dann entscheiden.')
|
|
->assertSee('Zur Entscheidungsmarke')
|
|
->assertSee('data-decision="12"', false)
|
|
->assertSee($article->code);
|
|
}
|
|
|
|
public function test_an_uploaded_file_name_with_spaces_becomes_ready(): void
|
|
{
|
|
Storage::fake('cms_incoming');
|
|
Storage::fake('media_derived');
|
|
Storage::disk('cms_incoming')->put('inhalte/Mein Film.mp4', 'film');
|
|
$content = app(ContentService::class);
|
|
$version = $content->publishElementVersion(
|
|
$content->createElement('film', 'film', 'Film'),
|
|
null,
|
|
['incoming' => 'inhalte/Mein Film.mp4'],
|
|
);
|
|
|
|
$version->refresh();
|
|
|
|
$this->assertSame(ContentVersionStatus::Bereit, $version->status);
|
|
$this->assertSame('inhalte/'.$version->id.'/Mein-Film.mp4', $version->metadata['file']);
|
|
Storage::disk('media_derived')->assertExists('inhalte/'.$version->id.'/Mein-Film.mp4');
|
|
}
|
|
|
|
public function test_an_editor_can_read_an_element_and_a_member_cannot(): void
|
|
{
|
|
$version = app(ContentService::class)->publishElementVersion(
|
|
app(ContentService::class)->createElement('text', 'text', 'Hinweis'),
|
|
'Sichtbar für die Redaktion.',
|
|
);
|
|
|
|
$this->actingAs(User::factory()->redakteur()->create(), 'staff')
|
|
->get(route('content.preview', $version))
|
|
->assertOk()
|
|
->assertSee('Sichtbar für die Redaktion.');
|
|
|
|
auth('staff')->logout();
|
|
|
|
$this->actingAs(User::factory()->create(), 'web')
|
|
->get(route('content.preview', $version))
|
|
->assertRedirect();
|
|
}
|
|
}
|