dir = sys_get_temp_dir().'/inhaus-ep-'.bin2hex(random_bytes(4)); mkdir($this->dir); $this->app->instance(MaintenanceFlag::class, new MaintenanceFlag($this->dir.'/.maintenance')); $this->app->instance(UpdateProgress::class, new UpdateProgress($this->dir.'/.progress')); $this->app->instance(InstalledVersion::class, new InstalledVersion($this->dir.'/.version')); } protected function tearDown(): void { Filesystem::deleteDirectory($this->dir); parent::tearDown(); } public function test_update_endpoints_are_admin_only(): void { $this->postJson('/admin/update/check')->assertUnauthorized(); $user = User::factory()->create(); foreach (['check', 'install', 'channel', 'migrations'] as $endpoint) { $this->actingAs($user)->postJson("/admin/update/{$endpoint}")->assertForbidden(); } $this->actingAs($user)->getJson('/admin/update/progress')->assertForbidden(); $this->actingAs($user)->get('/admin/aktualisierung')->assertForbidden(); } public function test_maintenance_mode_shows_503_but_keeps_update_pages_reachable(): void { $admin = User::factory()->admin()->create(); app(MaintenanceFlag::class)->activate(300); $this->actingAs($admin)->get('/') ->assertStatus(503) ->assertHeader('Retry-After') ->assertSee('Das Portal wird gerade aktualisiert'); $this->actingAs($admin)->getJson('/admin/update/progress')->assertOk()->assertJson(['step' => 'idle']); $this->actingAs($admin)->get('/admin/aktualisierung')->assertOk(); $this->get('/up')->assertOk(); app(MaintenanceFlag::class)->deactivate(); $this->actingAs($admin)->get('/')->assertOk(); } public function test_first_check_of_fresh_installation_remembers_latest_sha(): void { Http::fake(['*' => Http::response(['has_update' => false, 'latest_sha' => str_repeat('d', 40), 'version' => '0.2.0'])]); $this->actingAs(User::factory()->admin()->create()) ->postJson('/admin/update/check') ->assertOk() ->assertJson(['ok' => true, 'result' => ['has_update' => false, 'changelog' => []]]); Http::assertSent(fn ($request) => ! str_contains($request->url(), 'current_sha')); $this->assertSame(str_repeat('d', 40), app(InstalledVersion::class)->current()); } public function test_check_shows_changelog_preview_without_commit_texts(): void { app(InstalledVersion::class)->save(str_repeat('a', 40)); Http::fake(['*' => Http::response([ 'has_update' => true, 'latest_sha' => str_repeat('b', 40), 'version' => '0.3.0', 'versions_behind' => 4, 'changelog_preview' => [ 'entries' => [['version' => '0.3.0', 'heading' => '0.3.0', 'text' => "- Neue **Umfragen**\n- "]], 'complete' => false, ], ])]); $response = $this->actingAs(User::factory()->admin()->create()) ->postJson('/admin/update/check') ->assertOk() ->assertJsonPath('result.has_update', true) ->assertJsonPath('result.version', '0.3.0') ->assertJsonPath('result.latest_short', 'bbbbbbb') ->assertJsonPath('result.versions_behind', 4) ->assertJsonPath('result.changelog_complete', false); Http::assertSent(fn ($request) => str_contains($request->url(), 'current_sha='.str_repeat('a', 40))); $this->assertStringContainsString('Umfragen', $response->json('result.changelog.0.html')); $this->assertStringNotContainsString('