- app.js: Der Anfangsscan übergab das Dokument, das kein Element ist; HLS-Filme im Quelltext wurden nie angebunden. Vollbild findet sein Video auch neben dem Player. - Download und Ansicht heißen nach dem Anzeigetitel statt „laden.mp4“. - Mitgliederprofil: Name, E-Mail mit Bestätigung der neuen Adresse, Passwort, Rechnungsadresse (ADR-46). - Kleine Fußzeile mit Rechtlichem aus der CMS-Navigation. - Lizenzdetail nennt, dass Einzel-/Mehrfachlizenz nicht festgelegt ist (Funktion gibt es noch nicht). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
217 lines
11 KiB
PHP
217 lines
11 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Domain\Cms\NavigationItem;
|
|
use App\Domain\Cms\Page;
|
|
use App\Domain\Identity\BillingAddress;
|
|
use App\Domain\Identity\RegisterAccount;
|
|
use App\Models\User;
|
|
use App\Notifications\ConfirmNewEmailAddress;
|
|
use App\Notifications\EmailChangeRequested;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Notifications\AnonymousNotifiable;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Illuminate\Support\Facades\Notification;
|
|
use Tests\TestCase;
|
|
|
|
/**
|
|
* Mitgliederprofil (ADR-46): Name, E-Mail-Adresse mit Bestätigung, Passwort, Rechnungsadresse; Fußzeile mit Rechtlichem.
|
|
*/
|
|
class MemberProfileTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
private const PASSWORD = 'bisheriges-passwort-1';
|
|
|
|
private function member(string $email = 'tina@example.test'): User
|
|
{
|
|
$user = app(RegisterAccount::class)->register('Tina Trainerin', $email, self::PASSWORD, true);
|
|
$user->forceFill(['email_verified_at' => now()])->save();
|
|
|
|
return $user;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------
|
|
// Name
|
|
// ---------------------------------------------------------------------------------------------------------------
|
|
|
|
public function test_the_profile_shows_all_four_blocks_and_saves_the_name_separately(): void
|
|
{
|
|
$user = $this->member();
|
|
|
|
$this->actingAs($user)->get(route('member.profile'))
|
|
->assertOk()
|
|
->assertSee('Name')->assertSee('E-Mail-Adresse')->assertSee('Passwort')->assertSee('Rechnungsadresse');
|
|
|
|
$this->post(route('member.profile.update'), ['name' => 'Tina Neu'])->assertRedirect(route('member.profile'));
|
|
|
|
$this->assertSame('Tina Neu', $user->fresh()->name);
|
|
$this->assertSame('Tina Neu', $user->party->fresh()->display_name);
|
|
$this->post(route('member.profile.update'), ['name' => ''])->assertSessionHasErrorsIn('name', 'name');
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------
|
|
// E-Mail-Adresse
|
|
// ---------------------------------------------------------------------------------------------------------------
|
|
|
|
public function test_a_new_email_address_only_applies_after_the_link_to_it_is_opened(): void
|
|
{
|
|
Notification::fake();
|
|
$user = $this->member();
|
|
|
|
$this->actingAs($user)->post(route('member.profile.email'), ['email' => 'Neu@Example.test', 'current_password' => self::PASSWORD])
|
|
->assertRedirect(route('member.profile'));
|
|
|
|
$user->refresh();
|
|
$this->assertSame('tina@example.test', $user->email, 'Bis zur Bestätigung gilt die bisherige Adresse.');
|
|
$this->assertSame('neu@example.test', $user->pending_email);
|
|
Notification::assertSentOnDemand(ConfirmNewEmailAddress::class, fn ($notification, $channels, AnonymousNotifiable $notifiable): bool => $notifiable->routes['mail'] === 'neu@example.test');
|
|
Notification::assertSentTo($user, EmailChangeRequested::class);
|
|
$this->get(route('member.profile'))->assertSee('Wartet auf Bestätigung')->assertSee('neu@example.test');
|
|
|
|
$link = $this->confirmationLink($user, 'neu@example.test');
|
|
$this->get($link)->assertRedirect(route('member.profile'));
|
|
|
|
$user->refresh();
|
|
$this->assertSame('neu@example.test', $user->email);
|
|
$this->assertNull($user->pending_email);
|
|
$this->assertNotNull($user->email_verified_at);
|
|
}
|
|
|
|
public function test_the_email_change_needs_the_current_password_and_a_free_address(): void
|
|
{
|
|
Notification::fake();
|
|
$user = $this->member();
|
|
$this->member('besetzt@example.test');
|
|
|
|
$this->actingAs($user)->post(route('member.profile.email'), ['email' => 'neu@example.test', 'current_password' => 'falsch'])
|
|
->assertSessionHasErrorsIn('email', 'current_password');
|
|
$this->post(route('member.profile.email'), ['email' => 'besetzt@example.test', 'current_password' => self::PASSWORD])
|
|
->assertSessionHasErrorsIn('email', 'email');
|
|
$this->post(route('member.profile.email'), ['email' => 'tina@example.test', 'current_password' => self::PASSWORD])
|
|
->assertSessionHasErrorsIn('email', 'email');
|
|
|
|
$this->assertNull($user->fresh()->pending_email);
|
|
Notification::assertNothingSent();
|
|
}
|
|
|
|
public function test_an_email_link_works_only_for_its_own_pending_address_and_account(): void
|
|
{
|
|
Notification::fake();
|
|
$user = $this->member();
|
|
$other = $this->member('anderes@example.test');
|
|
$user->forceFill(['pending_email' => 'neu@example.test'])->save();
|
|
|
|
$this->actingAs($other)->get($this->confirmationLink($user, 'neu@example.test'))->assertForbidden();
|
|
$this->actingAs($user)->get($this->confirmationLink($user, 'falsch@example.test'))
|
|
->assertRedirect(route('member.profile'))->assertSessionHasErrorsIn('email', 'email');
|
|
$this->assertSame('tina@example.test', $user->fresh()->email);
|
|
|
|
$this->get(route('member.profile.email.confirm', ['id' => $user->id, 'hash' => sha1('neu@example.test')]))->assertForbidden();
|
|
|
|
$this->post(route('member.profile.email.cancel'))->assertRedirect(route('member.profile'));
|
|
$this->assertNull($user->fresh()->pending_email);
|
|
}
|
|
|
|
public function test_an_address_taken_in_the_meantime_cannot_be_confirmed(): void
|
|
{
|
|
$user = $this->member();
|
|
$user->forceFill(['pending_email' => 'neu@example.test'])->save();
|
|
$this->member('neu@example.test');
|
|
|
|
$this->actingAs($user)->get($this->confirmationLink($user, 'neu@example.test'))->assertSessionHasErrorsIn('email', 'email');
|
|
$this->assertSame('tina@example.test', $user->fresh()->email);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------
|
|
// Passwort
|
|
// ---------------------------------------------------------------------------------------------------------------
|
|
|
|
public function test_the_password_changes_only_with_the_current_one(): void
|
|
{
|
|
$user = $this->member();
|
|
|
|
$this->actingAs($user)->post(route('member.profile.password'), ['current_password' => 'falsch', 'password' => 'Neues-Passwort-99', 'password_confirmation' => 'Neues-Passwort-99'])
|
|
->assertSessionHasErrorsIn('password', 'current_password');
|
|
$this->post(route('member.profile.password'), ['current_password' => self::PASSWORD, 'password' => 'Neues-Passwort-99', 'password_confirmation' => 'anders'])
|
|
->assertSessionHasErrorsIn('password', 'password');
|
|
$this->post(route('member.profile.password'), ['current_password' => self::PASSWORD, 'password' => self::PASSWORD, 'password_confirmation' => self::PASSWORD])
|
|
->assertSessionHasErrorsIn('password', 'password');
|
|
$this->assertTrue(Hash::check(self::PASSWORD, $user->fresh()->password));
|
|
|
|
$this->post(route('member.profile.password'), ['current_password' => self::PASSWORD, 'password' => 'Neues-Passwort-99', 'password_confirmation' => 'Neues-Passwort-99'])
|
|
->assertRedirect(route('member.profile'));
|
|
$this->assertTrue(Hash::check('Neues-Passwort-99', $user->fresh()->password));
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------
|
|
// Rechnungsadresse
|
|
// ---------------------------------------------------------------------------------------------------------------
|
|
|
|
public function test_the_billing_address_is_saved_updated_and_validated_per_account(): void
|
|
{
|
|
$user = $this->member();
|
|
$other = $this->member('anderes@example.test');
|
|
$data = ['recipient' => 'Tina Trainerin', 'line2' => 'Hinterhaus', 'street' => 'Hauptstraße 1', 'postal_code' => '12345', 'city' => 'Musterstadt', 'country' => 'DE'];
|
|
|
|
$this->actingAs($user)->post(route('member.profile.address'), $data)->assertRedirect(route('member.profile'));
|
|
$this->assertSame('Hauptstraße 1', $user->party->billingAddress->street);
|
|
$this->get(route('member.profile'))->assertSee('Hauptstraße 1')->assertSee('Musterstadt');
|
|
|
|
$this->post(route('member.profile.address'), ['street' => 'Neuweg 2', 'country' => 'AT'] + $data)->assertRedirect();
|
|
$this->assertSame(1, BillingAddress::query()->count(), 'Eine Adresse je Inhaber, die Änderung ersetzt sie.');
|
|
$this->assertSame('AT', $user->party->fresh()->billingAddress->country);
|
|
|
|
$this->post(route('member.profile.address'), ['street' => '', 'country' => 'XX'] + $data)
|
|
->assertSessionHasErrorsIn('address', ['street', 'country']);
|
|
$this->assertNull($other->party->billingAddress, 'Die Adresse eines Kontos erscheint nicht bei anderen.');
|
|
$this->actingAs($other)->get(route('member.profile'))->assertDontSee('Neuweg 2');
|
|
}
|
|
|
|
public function test_the_profile_is_closed_to_guests(): void
|
|
{
|
|
foreach (['member.profile'] as $route) {
|
|
$this->get(route($route))->assertRedirect('/anmelden');
|
|
}
|
|
$this->post(route('member.profile.password'), [])->assertRedirect('/anmelden');
|
|
$this->post(route('member.profile.address'), [])->assertRedirect('/anmelden');
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------
|
|
// Fußzeile
|
|
// ---------------------------------------------------------------------------------------------------------------
|
|
|
|
public function test_the_member_footer_links_the_legal_pages_from_the_cms_navigation(): void
|
|
{
|
|
NavigationItem::query()->create(['label' => 'Impressum', 'url' => '/impressum', 'placement' => 'footer_legal', 'sort_order' => 1, 'is_visible' => true]);
|
|
NavigationItem::query()->create(['label' => 'Datenschutz', 'url' => '/datenschutz', 'placement' => 'footer_legal', 'sort_order' => 2, 'is_visible' => true]);
|
|
NavigationItem::query()->create(['label' => 'Versteckt', 'url' => '/versteckt', 'placement' => 'footer_legal', 'sort_order' => 3, 'is_visible' => false]);
|
|
|
|
foreach ([route('member.dashboard'), route('member.library'), route('member.profile'), route('member.grants')] as $url) {
|
|
$this->actingAs($this->member('f'.crc32($url).'@example.test'))->get($url)
|
|
->assertOk()
|
|
->assertSee('class="mb-footer"', false)
|
|
->assertSee(url('/impressum'), false)
|
|
->assertSee(url('/datenschutz'), false)
|
|
->assertDontSee('Versteckt');
|
|
}
|
|
}
|
|
|
|
public function test_without_legal_navigation_and_pages_the_footer_has_no_invented_links(): void
|
|
{
|
|
Page::query()->whereIn('path', ['/impressum', '/datenschutz'])->delete();
|
|
|
|
$this->actingAs($this->member())->get(route('member.dashboard'))
|
|
->assertOk()
|
|
->assertSee('class="mb-footer"', false)
|
|
->assertDontSee('Impressum')
|
|
->assertDontSee('Datenschutz');
|
|
}
|
|
|
|
private function confirmationLink(User $user, string $newEmail): string
|
|
{
|
|
return (new ConfirmNewEmailAddress($user->id, $newEmail))->toMail($user)->actionUrl;
|
|
}
|
|
}
|