This commit is contained in:
@@ -48,6 +48,28 @@ class PortalServicesTest extends TestCase
|
||||
$this->get('/management/portal-services')->assertRedirect('/login');
|
||||
}
|
||||
|
||||
public function test_document_management_writes_redirect_to_the_management_get_route(): void
|
||||
{
|
||||
$manager = User::factory()->create();
|
||||
config(['portal.managers' => [$manager->email]]);
|
||||
$this->actingAs($manager);
|
||||
|
||||
// A stale Referer can point at the write-only resource endpoint. Both
|
||||
// validation failures and successful writes must finish at a real GET.
|
||||
$this->from('/management/portal-services/resources/4')
|
||||
->post('/management/portal-services/resources/4', ['published' => 'invalid'])
|
||||
->assertRedirect(route('services.manage'))
|
||||
->assertSessionHasErrors('published');
|
||||
$this->get(route('services.manage'))->assertOk()->assertInertia(fn (Assert $page) => $page->component('portal/manage'));
|
||||
|
||||
$this->from('/management/portal-services/resources/4')
|
||||
->post('/management/portal-services/resources', [])
|
||||
->assertRedirect(route('services.manage'))
|
||||
->assertSessionHasErrors('document_id');
|
||||
|
||||
$this->get('/management/portal-services/resources/4')->assertStatus(405);
|
||||
}
|
||||
|
||||
public function test_support_receipt_is_idempotent_private_and_requires_consent(): void
|
||||
{
|
||||
$owner = User::factory()->create();
|
||||
@@ -110,19 +132,21 @@ class PortalServicesTest extends TestCase
|
||||
$this->get('/documentos')->assertInertia(fn (Assert $page) => $page->has('resources.data', 0));
|
||||
$id = $this->registerDocumentResource($document->id, 'Guia de teste');
|
||||
$this->assertDatabaseHas('portal_resources', ['id' => $id, 'published' => false, 'rights_status' => 'authorized']);
|
||||
$this->post('/management/portal-services/resources/'.$id, ['published' => true])->assertUnprocessable();
|
||||
$this->post('/management/portal-services/resources/'.$id, ['published' => true])->assertRedirect(route('services.manage'))->assertSessionHasErrors('published');
|
||||
// A malware scan releases technical quarantine without changing privacy or editorial publication.
|
||||
DB::table('documents')->where('id', $document->id)->update(['status' => 'active', 'data_classification' => 'public']);
|
||||
$this->post('/management/portal-services/resources/'.$id, ['published' => true])->assertSessionHasNoErrors();
|
||||
$this->post('/management/portal-services/resources/'.$id, ['published' => true])->assertRedirect(route('services.manage'))->assertSessionHasNoErrors();
|
||||
$this->get('/documentos/'.$id.'/download')->assertOk()->assertDownload('exemplo.txt');
|
||||
$this->get('/documentos/'.$id.'?back=%2Fdocumentos%3Ftopic%3DInvestimento')->assertInertia(fn (Assert $page) => $page
|
||||
->component('portal/document')->where('resource.title', 'Guia de teste')->where('backUrl', '/documentos?topic=Investimento')
|
||||
->has('resource.links', 3)->missing('resource.storage_key')->missing('resource.sha256'));
|
||||
$this->get('/')->assertInertia(fn (Assert $page) => $page->has('essentialResources', 1));
|
||||
$this->get('/documentos')->assertInertia(fn (Assert $page) => $page->has('resources.data', 1)->where('resources.data.0.title', 'Guia de teste')->missing('resources.data.0.storage_key'));
|
||||
$this->get('/documentos?q=Guia%20de%20teste&document_type=guide')->assertInertia(fn (Assert $page) => $page
|
||||
->component('portal/services')->has('resources.data', 1)->where('resources.data.0.title', 'Guia de teste'));
|
||||
$this->getJson('/api/v1/documents/recommendations?module=simulator&activity_id=CAE-TEST&stage=review')->assertOk()->assertJsonPath('data.0.title', 'Guia de teste');
|
||||
$this->put('/management/portal-services/resources/'.$id, [...$this->documentResourcePayload($document->id, 'Guia de teste revisto'), 'metadata_version' => 2, 'description' => 'Resumo editado pelo gestor.'])
|
||||
->assertSessionHasNoErrors();
|
||||
->assertRedirect(route('services.manage'))->assertSessionHasNoErrors();
|
||||
$this->assertDatabaseHas('portal_resources', ['id' => $id, 'published' => true, 'title' => 'Guia de teste revisto']);
|
||||
$this->assertDatabaseHas('portal_resource_revisions', ['resource_id' => $id, 'revision_no' => 3, 'change_type' => 'metadata_updated']);
|
||||
DB::table('documents')->where('id', $document->id)->update(['data_classification' => 'internal']);
|
||||
@@ -175,7 +199,7 @@ class PortalServicesTest extends TestCase
|
||||
$this->assertDatabaseCount('portal_resource_links', 20);
|
||||
}
|
||||
|
||||
public function test_document_publication_marks_proposals_and_requires_a_confirmed_source(): void
|
||||
public function test_legislation_with_an_identified_source_can_be_published_for_consultation_without_claiming_confirmation(): void
|
||||
{
|
||||
Storage::fake('local');
|
||||
$manager = User::factory()->create();
|
||||
@@ -187,12 +211,77 @@ class PortalServicesTest extends TestCase
|
||||
$this->post('/management/portal-services/resources', $payload)->assertSessionHasNoErrors();
|
||||
$id = (int) DB::table('portal_resources')->value('id');
|
||||
DB::table('documents')->where('id', $document->id)->update(['status' => 'active', 'data_classification' => 'public']);
|
||||
$this->post('/management/portal-services/resources/'.$id, ['published' => true])->assertUnprocessable();
|
||||
$this->put('/management/portal-services/resources/'.$id, [...$payload, 'metadata_version' => 1, 'source_confirmation' => 'official_confirmed'])
|
||||
->assertSessionHasNoErrors();
|
||||
$this->post('/management/portal-services/resources/'.$id, ['published' => true])->assertSessionHasNoErrors();
|
||||
$this->get('/legislacao')->assertInertia(fn (Assert $page) => $page->where('resources.data.0.legal_status', 'proposed')
|
||||
->where('resources.data.0.source_confirmation', 'official_confirmed'));
|
||||
->where('resources.data.0.source_confirmation', 'identified'));
|
||||
}
|
||||
|
||||
public function test_recorded_user_authorization_publishes_only_eligible_document_scope_in_one_manager_action(): void
|
||||
{
|
||||
Storage::fake('local');
|
||||
$manager = User::factory()->create();
|
||||
config(['portal.managers' => [$manager->email]]);
|
||||
$this->post('/management/portal-services/disclosure-authorization/apply')->assertRedirect('/login');
|
||||
$this->actingAs($manager);
|
||||
|
||||
$resourceIds = [];
|
||||
$titles = [
|
||||
1 => 'Lei n.º 22/2022, de 28 de Dezembro — alteração ao Código do IVA (republicação)',
|
||||
2 => 'Boletim da República n.º 248/2025 — Suplemento n.º 1',
|
||||
3 => 'Boletim da República n.º 89, I Série (08-06-2017) — aviso de rectificação da Lei n.º 13/2016',
|
||||
4 => 'Codificador da Divisão Político-Administrativa (INE, 07-06-2012)',
|
||||
];
|
||||
foreach ([1, 2, 3, 4] as $number) {
|
||||
$this->post('/management/portal-services/upload', [
|
||||
'file' => UploadedFile::fake()->createWithContent("reference-$number.pdf", "document bytes $number"),
|
||||
'original_source' => 'https://example.gov.mz/reference',
|
||||
])->assertSessionHasNoErrors();
|
||||
$document = DB::table('documents')->where('file_name', "reference-$number.pdf")->firstOrFail();
|
||||
$resourceIds[] = $this->registerDocumentResource($document->id, $titles[$number], [
|
||||
'document_type' => $number === 3 ? 'legislation' : 'reference_data',
|
||||
'legislation' => $number === 3,
|
||||
'source_confirmation' => $number === 3 ? 'identified' : 'official_confirmed',
|
||||
'legal_status' => $number === 3 ? 'unknown' : 'historical',
|
||||
'rights_status' => 'unconfirmed', 'data_classification' => 'internal',
|
||||
]);
|
||||
DB::table('documents')->where('id', $document->id)->update([
|
||||
'status' => 'active', 'malware_scan_status' => 'clean', 'malware_scanned_sha256' => $document->sha256,
|
||||
]);
|
||||
}
|
||||
$this->assertCount(4, $resourceIds);
|
||||
DB::table('audit_events')->insert([
|
||||
'source_system' => 'user-instruction', 'external_id' => 'document-repository-disclosure-authorization-2026-10-06-v1',
|
||||
'data_classification' => 'internal', 'entity_type' => 'portal_document_repository', 'entity_id' => null,
|
||||
'action' => 'public_disclosure_authorized', 'actor_user_id' => null,
|
||||
'after_data' => json_encode(['resource_ids' => $resourceIds], JSON_THROW_ON_ERROR),
|
||||
]);
|
||||
|
||||
$this->post('/management/portal-services/disclosure-authorization/apply')
|
||||
->assertRedirect(route('services.manage'))->assertSessionHasNoErrors();
|
||||
$this->assertDatabaseCount('portal_resource_revisions', 8);
|
||||
$this->assertDatabaseCount('audit_events', 13);
|
||||
$this->assertSame(4, DB::table('portal_resources')->where('published', true)->count());
|
||||
$this->assertSame(4, DB::table('documents')->where('data_classification', 'public')->where('rights_status', 'authorized')->count());
|
||||
$this->assertDatabaseHas('portal_resources', ['id' => $resourceIds[2], 'published' => true, 'source_confirmation' => 'identified', 'legal_status' => 'unknown']);
|
||||
$this->assertDatabaseHas('portal_resource_links', ['resource_id' => $resourceIds[0], 'target_type' => 'requirement',
|
||||
'target_key' => 'fiscal.iva.lei_22_2022', 'review_status' => 'confirmed', 'applicability' => 'evidence']);
|
||||
$this->assertDatabaseHas('portal_resource_links', ['resource_id' => $resourceIds[1], 'target_type' => 'requirement',
|
||||
'target_key' => 'fiscal.iva.lei_10_2025', 'review_status' => 'pending', 'applicability' => 'evidence']);
|
||||
$this->assertDatabaseHas('portal_resource_links', ['resource_id' => $resourceIds[2], 'target_type' => 'requirement',
|
||||
'target_key' => 'fiscal.iva.lei_13_2016_rectification_2017', 'review_status' => 'pending', 'applicability' => 'evidence']);
|
||||
$this->assertDatabaseHas('audit_events', ['source_system' => 'portal-services', 'entity_type' => 'portal_resources',
|
||||
'actor_user_id' => $manager->id, 'action' => 'published_under_user_authorization']);
|
||||
$this->get('/documentos')->assertInertia(fn (Assert $page) => $page->has('resources.data', 4));
|
||||
$this->get('/documentos?q=22%2F2022')->assertInertia(fn (Assert $page) => $page
|
||||
->has('resources.data', 1)->where('resources.data.0.id', $resourceIds[0]));
|
||||
$this->get('/documentos?category=Guia&document_type=legislation')->assertInertia(fn (Assert $page) => $page
|
||||
->has('resources.data', 1)->where('resources.data.0.id', $resourceIds[2]));
|
||||
$this->get('/documentos/'.$resourceIds[2])->assertInertia(fn (Assert $page) => $page->component('portal/document')
|
||||
->where('resource.source_confirmation', 'identified')->where('resource.legal_status', 'unknown'));
|
||||
$this->get('/documentos/'.$resourceIds[0].'/download')->assertOk()->assertDownload('reference-1.pdf');
|
||||
$this->assertDatabaseHas('portal_resource_links', ['resource_id' => $resourceIds[0], 'target_type' => 'module', 'target_key' => 'simulator']);
|
||||
$this->post('/management/portal-services/disclosure-authorization/apply')->assertSessionHasNoErrors();
|
||||
$this->assertDatabaseCount('portal_resource_revisions', 8);
|
||||
}
|
||||
|
||||
public function test_manager_classifies_a_reviewed_document_public_before_separate_publication(): void
|
||||
@@ -286,7 +375,7 @@ class PortalServicesTest extends TestCase
|
||||
$resource = DB::table('portal_resources')->firstOrFail();
|
||||
$this->assertFalse((bool) $resource->published);
|
||||
$this->assertSame('internal', DB::table('documents')->where('id', $document->id)->value('data_classification'));
|
||||
$this->post('/management/portal-services/resources/'.$resource->id, ['published' => true])->assertUnprocessable();
|
||||
$this->post('/management/portal-services/resources/'.$resource->id, ['published' => true])->assertRedirect(route('services.manage'))->assertSessionHasErrors('published');
|
||||
$this->get('/documentos')->assertInertia(fn (Assert $page) => $page->has('resources.data', 0));
|
||||
$this->get('/documentos/'.$resource->id)->assertNotFound();
|
||||
$this->get('/documentos/'.$resource->id.'/download')->assertNotFound();
|
||||
@@ -347,6 +436,31 @@ class PortalServicesTest extends TestCase
|
||||
$this->assertDatabaseCount('documents', 1);
|
||||
}
|
||||
|
||||
public function test_public_recommendations_return_only_confirmed_requirement_citations(): void
|
||||
{
|
||||
Storage::fake('local');
|
||||
$manager = User::factory()->create();
|
||||
config(['portal.managers' => [$manager->email]]);
|
||||
$this->actingAs($manager)->post('/management/portal-services/upload', [
|
||||
'file' => UploadedFile::fake()->createWithContent('public-evidence.txt', 'Documentary evidence fixture.'),
|
||||
])->assertSessionHasNoErrors();
|
||||
$document = DB::table('documents')->firstOrFail();
|
||||
$payload = $this->documentResourcePayload($document->id, 'Fontes fiscais QA');
|
||||
$payload['associations'][] = ['target_type' => 'requirement', 'target_key' => 'fiscal.iva.lei_22_2022', 'relationship' => 'cites',
|
||||
'applicability' => 'evidence', 'review_status' => 'confirmed', 'basis_reference' => 'Citação fixture, artigo 17(1), página 3.'];
|
||||
$payload['associations'][] = ['target_type' => 'requirement', 'target_key' => 'fiscal.iva.lei_10_2025', 'relationship' => 'cites',
|
||||
'applicability' => 'evidence', 'review_status' => 'pending', 'basis_reference' => 'Citação ainda não conferida no fixture.'];
|
||||
$this->post('/management/portal-services/resources', $payload)->assertSessionHasNoErrors();
|
||||
$id = (int) DB::table('portal_resources')->where('title', 'Fontes fiscais QA')->value('id');
|
||||
DB::table('documents')->where('id', $document->id)->update(['status' => 'active', 'data_classification' => 'public']);
|
||||
$this->post('/management/portal-services/resources/'.$id, ['published' => true])->assertSessionHasNoErrors();
|
||||
|
||||
$this->getJson('/api/v1/documents/recommendations?module=simulator')->assertOk()
|
||||
->assertJsonPath('data.0.documentary_evidence.0.key', 'fiscal.iva.lei_22_2022')
|
||||
->assertJsonPath('data.0.documentary_evidence.0.status', 'citation_checked_application_pending')
|
||||
->assertJsonMissing(['key' => 'fiscal.iva.lei_10_2025']);
|
||||
}
|
||||
|
||||
private function registerDocumentResource(string $documentId, string $title, array $overrides = []): int
|
||||
{
|
||||
$payload = [...$this->documentResourcePayload($documentId, $title), ...$overrides];
|
||||
|
||||
Reference in New Issue
Block a user