1fcad7d9b2
- Add ExportController: allMiskinPDF (all data) + radiusMiskinPDF
(server-side Haversine filtering per ibadah radius)
- Add two table-based PDF Blade views (dompdf-compatible, no flexbox/grid)
- Add export routes (/export/pdf, /export/pdf/radius/{id}/{radius})
with numeric route constraints
- Add "Ekspor PDF" button to data tabular view
- Add CSV + PDF radius export buttons to map analysis panel;
exportRadiusCSV() reuses existing isInside(); PDF href synced on
ibadah click and radius slider change
- 5 new tests: access control, PDF content-type, 404 + param validation
- Mark K-04 and Section 5 (Cetak & Ekspor) complete in missing_features.md
- Update README with export features
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
76 lines
2.1 KiB
PHP
76 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\RumahIbadah;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class ExportTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
foreach (['administrator', 'pengurus_ibadah', 'petugas_pendataan', 'pemangku_kebijakan'] as $role) {
|
|
\Spatie\Permission\Models\Role::create(['name' => $role, 'guard_name' => 'web']);
|
|
}
|
|
}
|
|
|
|
private function createUser(string $role): User
|
|
{
|
|
$user = User::factory()->create();
|
|
$user->assignRole($role);
|
|
return $user;
|
|
}
|
|
|
|
public function test_unauthenticated_cannot_export_pdf(): void
|
|
{
|
|
$this->get('/export/pdf')->assertRedirect('/login');
|
|
}
|
|
|
|
public function test_authenticated_can_export_all_miskin_pdf(): void
|
|
{
|
|
$this->actingAs($this->createUser('pemangku_kebijakan'));
|
|
|
|
$response = $this->get('/export/pdf');
|
|
$response->assertOk();
|
|
$response->assertHeader('content-type', 'application/pdf');
|
|
}
|
|
|
|
public function test_radius_pdf_returns_404_for_invalid_ibadah(): void
|
|
{
|
|
$this->actingAs($this->createUser('administrator'));
|
|
|
|
$this->get('/export/pdf/radius/99999/500')->assertNotFound();
|
|
}
|
|
|
|
public function test_radius_pdf_returns_pdf_for_valid_ibadah(): void
|
|
{
|
|
$admin = $this->createUser('administrator');
|
|
$this->actingAs($admin);
|
|
|
|
$ibadah = RumahIbadah::create([
|
|
'user_id' => $admin->id,
|
|
'nama' => 'Test Masjid',
|
|
'jenis' => 'masjid',
|
|
'latitude' => -7.0,
|
|
'longitude' => 110.0,
|
|
'radius' => 500,
|
|
]);
|
|
|
|
$response = $this->get("/export/pdf/radius/{$ibadah->id}/500");
|
|
$response->assertOk();
|
|
$response->assertHeader('content-type', 'application/pdf');
|
|
}
|
|
|
|
public function test_radius_pdf_rejects_non_numeric_params(): void
|
|
{
|
|
$this->actingAs($this->createUser('administrator'));
|
|
|
|
$this->get('/export/pdf/radius/abc/def')->assertNotFound();
|
|
}
|
|
}
|