previousState = is_file($file) ? file_get_contents($file) : null; $state = json_decode($this->previousState ?? '{}', true) ?: []; $state['verleih'] = ['enabled' => true]; file_put_contents($file, json_encode($state)); parent::setUp(); Storage::fake('local'); $role = Role::query()->create(['name' => 'Künstlerteam']); $role->grants()->create(['ability' => 'verleih.manage']); $this->artist = User::factory()->withRoles([$role])->create(['first_name' => 'Kim', 'last_name' => 'Kunst']); } protected function tearDown(): void { $file = storage_path('app/plugins.json'); $this->previousState === null ? @unlink($file) : file_put_contents($file, $this->previousState); parent::tearDown(); } private function item(array $overrides = []): Item { return Item::query()->create(['title' => 'Sommerwiese', 'description' => '

Acryl auf Leinwand

', 'lent' => false, 'location' => 'Lager', ...$overrides]); } public function test_team_manages_pictures_everyone_sees_them_available_first(): void { $colleague = User::factory()->create(); $this->actingAs($colleague)->get('/verleih/neu')->assertForbidden(); $this->actingAs($colleague)->post('/verleih', ['title' => 'X', 'lent' => 0])->assertForbidden(); $this->actingAs($this->artist)->post('/verleih', [ 'title' => 'Blaue Stunde', 'description' => '

Öl

', 'lent' => 1, 'location' => 'Verwaltung', 'image' => UploadedFile::fake()->image('bild.jpg', 3000, 2000), ])->assertRedirect(); $lent = Item::query()->where('title', 'Blaue Stunde')->firstOrFail(); $this->assertTrue($lent->lent); $this->assertStringNotContainsString('description); $this->assertSame(2000, $lent->image_width, 'Verkleinert auf 2000 px, ohne Zuschnitt'); $this->assertSame(1333, $lent->image_height); $this->item(['title' => 'Sommerwiese']); $this->actingAs($colleague)->get('/verleih')->assertInertia(fn (Assert $p) => $p ->component('verleih::Index') ->where('items.0.title', 'Sommerwiese')->where('items.0.lent', false) ->where('items.1.title', 'Blaue Stunde')->where('items.1.location', 'Verwaltung') ->where('canManage', false)->where('pendingRequests', null) ->where('labels.singular', 'Bild')); $this->actingAs($colleague)->get('/verleih?status=verliehen')->assertInertia(fn (Assert $p) => $p->has('items', 1)->where('counts.available', 1)); $this->actingAs($colleague)->get("/verleih/bilder/{$lent->id}/thumb")->assertOk(); auth()->logout(); $this->get("/verleih/bilder/{$lent->id}/thumb")->assertRedirect('/login'); } public function test_request_accept_decline_and_notifications(): void { Notification::fake(); Mail::fake(); $item = $this->item(); [$ada, $bob] = User::factory()->count(2)->create()->all(); $this->actingAs($ada)->post("/verleih/{$item->id}/anfragen", ['location' => 'Besprechungsraum 2. OG', 'from' => today()->addDay()->toDateString(), 'message' => 'Für die Jubiläumsfeier']) ->assertSessionHasNoErrors(); $this->actingAs($ada)->post("/verleih/{$item->id}/anfragen", ['location' => 'Nochmal'])->assertSessionHasErrors('location'); $this->actingAs($bob)->post("/verleih/{$item->id}/anfragen", ['location' => 'Empfang'])->assertSessionHasNoErrors(); Notification::assertSentTo($this->artist, PortalNotification::class, fn ($n) => str_contains($n->body, 'Besprechungsraum')); Mail::assertQueued(Notice::class, fn (Notice $mail) => $mail->hasTo($this->artist->email) && $mail->replyPerson?->is($ada)); Notification::assertNotSentTo($bob, PortalNotification::class); [$first, $second] = LoanRequest::query()->orderBy('id')->get()->all(); $this->actingAs($ada)->post("/verleih/anfragen/{$first->id}/zusagen")->assertForbidden(); $this->actingAs($this->artist)->get('/verleih/anfragen')->assertInertia(fn (Assert $p) => $p->has('pending', 2)->where('pending.0.user.id', $ada->id)); $this->actingAs($this->artist)->post("/verleih/anfragen/{$first->id}/zusagen", ['note' => 'Bringen wir Montag vorbei'])->assertSessionHasNoErrors(); $item->refresh(); $this->assertTrue($item->lent); $this->assertSame('Besprechungsraum 2. OG', $item->location); $this->assertSame($ada->id, $item->lent_to_id); Notification::assertSentTo($ada, PortalNotification::class, fn ($n) => str_starts_with($n->title, 'Zusage') && str_contains($n->body, 'Montag')); // Wer es hat, sieht nur das Team $this->actingAs($bob)->get("/verleih/{$item->id}")->assertInertia(fn (Assert $p) => $p->where('item.lent_to', null)->where('myRequest.location', 'Empfang')); $this->actingAs($this->artist)->get("/verleih/{$item->id}")->assertInertia(fn (Assert $p) => $p->where('item.lent_to.id', $ada->id)->has('requests', 2)); $this->actingAs($this->artist)->post("/verleih/anfragen/{$second->id}/absagen", ['note' => 'Ist gerade vergeben'])->assertSessionHasNoErrors(); $this->assertSame('declined', $second->fresh()->status); Notification::assertSentTo($bob, PortalNotification::class, fn ($n) => str_starts_with($n->title, 'Absage')); $this->actingAs($this->artist)->post("/verleih/anfragen/{$second->id}/zusagen")->assertSessionHasErrors('status'); // Zurückgenommen $this->actingAs($this->artist)->post("/verleih/{$item->id}/zurueck", ['location' => 'Lager Künstlerteam'])->assertRedirect(); $item->refresh(); $this->assertFalse($item->lent); $this->assertNull($item->lent_to_id); $this->assertSame('Lager Künstlerteam', $item->location); } public function test_requesters_can_withdraw_only_their_own(): void { $item = $this->item(); [$ada, $bob] = User::factory()->count(2)->create()->all(); $this->actingAs($ada)->post("/verleih/{$item->id}/anfragen", ['location' => 'Empfang']); $request = LoanRequest::query()->sole(); $this->actingAs($bob)->delete("/verleih/anfragen/{$request->id}")->assertForbidden(); $this->actingAs($ada)->delete("/verleih/anfragen/{$request->id}")->assertRedirect(); $this->assertSame('cancelled', $request->fresh()->status); } public function test_import_from_the_wordpress_plugin(): void { $file = tempnam(sys_get_temp_dir(), 'wxr'); file_put_contents($file, <<<'XML' Altes Intranet 1.2 Sonnenblumen Öl auf Leinwand, 60 × 80 cm Gemalt von Anna[gallery ids="1"]]]> 11 publish bv_objekt _bv_verliehen _bv_verleihort _thumbnail_id Entwurf 12 draft bv_objekt Hafen & Meer Aquarell

]]>
13 publish bv_objekt _bv_verliehen
sonnenblumen.jpg 21 inherit attachment
XML); $import = app(WordpressImport::class); $result = $import->import($file, $this->artist->id); $this->assertSame(['created' => 2, 'skipped' => 0, 'found' => 2], $result); $sun = Item::query()->where('wp_id', 11)->sole(); $this->assertTrue($sun->lent); $this->assertSame('Haus B, Flur', $sun->location); $this->assertSame('

Öl auf Leinwand, 60 × 80 cm

Gemalt von Anna

', $sun->description); $this->assertSame('https://intranet.example.org/wp-content/uploads/sonnenblumen.jpg', $sun->wp_image_url); $this->assertSame('Hafen & Meer', Item::query()->where('wp_id', 13)->sole()->title); $this->assertSame(1, $import->pendingImages()); // Bilder nachladen SafeOutbound::fakeResolve(['intranet.example.org' => '93.184.216.34']); $jpeg = UploadedFile::fake()->image('x.jpg', 800, 600)->getContent(); Http::fake(['intranet.example.org/*' => Http::response($jpeg, 200, ['Content-Type' => 'image/jpeg'])]); $this->assertSame(['loaded' => 1, 'failed' => 0, 'remaining' => 0], $import->fetchImages()); $this->assertNotNull($sun->fresh()->image_path); // Zweiter Lauf überschreibt nichts $sun->update(['location' => 'Im Portal geändert']); $this->assertSame(['created' => 0, 'skipped' => 2, 'found' => 2], $import->import($file)); $this->assertSame('Im Portal geändert', $sun->fresh()->location); file_put_contents($file, ']>'); $this->expectExceptionMessage('Entitäten'); $import->import($file); } }