125 lines
8.9 KiB
PHP
125 lines
8.9 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\User;
|
|
use App\Services\ContentManagement;
|
|
use App\Services\PortalProfileAdministration;
|
|
use App\Services\OpportunityManagement;
|
|
use Illuminate\Support\Facades\Crypt;
|
|
use Illuminate\Support\Str;
|
|
use Illuminate\Http\UploadedFile;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use App\Services\Malware\MalwareScanner;
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Inertia\Testing\AssertableInertia as Assert;
|
|
use Tests\TestCase;
|
|
|
|
class ContentManagementEntryTest extends TestCase
|
|
{
|
|
use DatabaseTransactions;
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$db = DB::selectOne('select current_database() as name, inet_server_port() as port');
|
|
$this->assertSame('simulator_fiscal_delta_20261021_test', $db->name);
|
|
$this->assertSame(55441, (int) $db->port);
|
|
$this->withoutVite();
|
|
}
|
|
|
|
public function test_entry_does_not_grant_access_to_an_investor(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
config(['portal.managers' => [], 'portal.document_managers' => []]);
|
|
$this->assertSame([], app(ContentManagement::class)->access($user));
|
|
$this->actingAs($user)->get('/gestao-conteudos')->assertForbidden();
|
|
}
|
|
|
|
public function test_existing_manager_gets_reused_destinations_and_document_intent_and_search(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
config(['portal.managers' => [$user->email]]);
|
|
$this->actingAs($user)->get('/gestao-conteudos')->assertOk()->assertInertia(fn (Assert $page) => $page->component('management/content-hub')
|
|
->where('access.documents.edit', true)->where('access.opportunities.create', '/management/opportunities/create'));
|
|
$this->get('/management/portal-services?intent=legislation&q=not-existing-qa-title')->assertOk()->assertInertia(fn (Assert $page) => $page
|
|
->where('managementFilters.intent', 'legislation')->has('associationOptions.sector')->has('associationOptions.stage')->has('resources', 0));
|
|
$this->get('/management/portal-services?state=published')->assertOk();
|
|
$this->get('/management/portal-services?state=withdrawn')->assertOk();
|
|
}
|
|
|
|
public function test_team_promoter_uses_operational_editor_without_general_administration(): void
|
|
{
|
|
config(['portal.profile_access_enabled' => true, 'portal.opportunity_specialized_drafts_enabled' => true, 'portal.managers' => []]);
|
|
$actor = User::factory()->create();
|
|
$actor->forceFill(['two_factor_secret' => Crypt::encryptString('JBSWY3DPEHPK3PXP'), 'two_factor_confirmed_at' => now()])->save();
|
|
$org = (string) Str::uuid();
|
|
DB::table('organizations')->insert(['id' => $org, 'name' => 'Synthetic QA content team', 'organization_type' => 'private']);
|
|
DB::table('memberships')->insert(['id' => (string) Str::uuid(), 'user_id' => $actor->id, 'organization_id' => $org, 'role' => 'officer']);
|
|
app(PortalProfileAdministration::class)->insertGrant((string) Str::uuid(), User::factory()->create(), [
|
|
'user_id' => $actor->id, 'role' => 'promoter', 'organization_id' => $org,
|
|
'opportunity_types' => OpportunityManagement::CATEGORIES, 'responsibilities' => [], 'source' => 'synthetic-content-entry-test',
|
|
]);
|
|
$before = DB::table('portal_role_assignments')->count();
|
|
$this->actingAs($actor)->withSession(['portal.mfa_actor' => $actor->id, 'portal.mfa_at' => time(), 'portal.access_revision' => (int) $actor->portal_access_revision]);
|
|
$this->get('/gestao-conteudos')->assertOk()->assertInertia(fn (Assert $page) => $page
|
|
->where('access.opportunities.create', '/minhas-oportunidades/create')->where('access.opportunities.profileWorkflow', true)->missing('access.documents'));
|
|
$this->get('/minhas-oportunidades/create')->assertOk();
|
|
$this->get('/management/portal-services')->assertForbidden();
|
|
$this->assertSame($before, DB::table('portal_role_assignments')->count());
|
|
}
|
|
|
|
public function test_new_legislation_is_recovered_edited_published_and_withdrawn_with_history(): void
|
|
{
|
|
Storage::fake('local');
|
|
config(['queue.default' => 'sync', 'services.malware.scanner' => 'clamd', 'services.malware.host' => '127.0.0.1', 'services.malware.port' => 3310]);
|
|
$this->assertTrue(app(MalwareScanner::class)->health()['available'], 'Real ClamD required for this QA demonstration');
|
|
$user = User::factory()->create();
|
|
config(['portal.managers' => [$user->email]]);
|
|
$this->actingAs($user);
|
|
$name = 'synthetic-entry-'.Str::uuid().'.txt';
|
|
$this->post('/management/portal-services/upload', ['intent' => 'legislation', 'file' => UploadedFile::fake()->createWithContent($name, 'Synthetic QA legislation example, no legal value.')])
|
|
->assertSessionHasNoErrors()->assertSessionHas('uploaded_document_id')->assertRedirect('/management/portal-services?intent=legislation');
|
|
$document = DB::table('documents')->where('file_name', $name)->first();
|
|
$this->assertSame('clean', $document->malware_scan_status);
|
|
$payload = ['document_id' => $document->id, 'title' => $name, 'category' => 'Synthetic QA', 'topic' => 'Synthetic QA',
|
|
'document_type' => 'legislation', 'issuer' => 'Synthetic QA only', 'source_url' => 'https://example.invalid/synthetic-qa', 'language' => 'pt', 'version_label' => 'QA-1',
|
|
'territorial_scope' => 'national', 'source_confirmation' => 'identified', 'legal_status' => 'proposed',
|
|
'rights_status' => 'authorized', 'data_classification' => 'public', 'source_reference' => 'Synthetic QA example, no official provenance or legal value.',
|
|
'legislation' => true, 'essential' => false, 'independent_review' => false, 'associations' => []];
|
|
$this->post('/management/portal-services/resources', $payload)->assertRedirect()->assertSessionHasNoErrors();
|
|
$resource = DB::table('portal_resources')->where('document_id', $document->id)->first();
|
|
$this->assertNotNull($resource);
|
|
$this->assertSame($name, $resource->title);
|
|
$this->get('/management/portal-services?q='.$name)->assertOk()->assertInertia(fn (Assert $page) => $page->has('resources', 1)->where('resources.0.title', $name));
|
|
$this->put('/management/portal-services/resources/'.$resource->id, [...$payload, 'title' => $name.' edited', 'metadata_version' => $resource->metadata_version])->assertSessionHasNoErrors();
|
|
$this->post('/management/portal-services/resources/'.$resource->id, ['published' => true])->assertSessionHasNoErrors();
|
|
$this->get('/documentos/'.$resource->id.'/download')->assertOk()->assertDownload($name);
|
|
$this->post('/management/portal-services/resources/'.$resource->id, ['published' => false])->assertSessionHasNoErrors();
|
|
$this->get('/management/portal-services?state=withdrawn&q='.$name)->assertOk()->assertInertia(fn (Assert $page) => $page->has('resources', 1));
|
|
$this->get('/management/portal-services?state=draft&q='.$name)->assertOk()->assertInertia(fn (Assert $page) => $page->has('resources', 0));
|
|
$this->get('/documentos/'.$resource->id.'/download')->assertNotFound();
|
|
$this->assertDatabaseHas('documents', ['id' => $document->id, 'sha256' => $document->sha256]);
|
|
$this->assertSame(4, DB::table('portal_resource_revisions')->where('resource_id', $resource->id)->count());
|
|
}
|
|
|
|
public function test_existing_named_editorial_designation_survives_removal_of_technical_reservation(): void
|
|
{
|
|
$actor = User::factory()->create();
|
|
$other = User::factory()->create();
|
|
$actor->forceFill(['two_factor_secret' => Crypt::encryptString('JBSWY3DPEHPK3PXP'), 'two_factor_confirmed_at' => now()])->save();
|
|
config(['portal.homologation_only' => false, 'portal.profile_access_enabled' => true,
|
|
'portal.managers' => [], 'homologation_editorial.accounts' => [$actor->email]]);
|
|
DB::table('portal_superuser_pair')->updateOrInsert(['id' => 1], ['first_user_id' => $actor->id, 'second_user_id' => $other->id, 'approved_by' => $other->id]);
|
|
$this->actingAs($actor)->withSession(['portal.mfa_actor' => $actor->id, 'portal.mfa_at' => time(), 'portal.access_revision' => (int) $actor->portal_access_revision]);
|
|
$this->get('/gestao-conteudos')->assertOk()->assertInertia(fn (Assert $page) => $page->where('access.documents.edit', true));
|
|
$this->get('/management/portal-services?intent=legislation')->assertOk()->assertInertia(fn (Assert $page) => $page
|
|
->where('editorialScopeOnly', true)->where('documentAccessOnly', false));
|
|
config(['homologation_editorial.accounts' => []]);
|
|
$this->get('/management/portal-services')->assertForbidden();
|
|
config(['homologation_editorial.accounts' => [$actor->email]]);
|
|
$this->withSession(['portal.mfa_at' => time() - 901]);
|
|
$this->assertFalse(app(\App\Services\DocumentManagementAccess::class)->editorial($actor));
|
|
}
|
|
}
|