Files
Investidor-V2/outputs/investmoz-promotor-contexto-QA-20261015/prove-scopes.php
T
nala 6a76aac80f
tests / ci (push) Canceled after 0s
versao compilada 1
2026-10-16 09:17:28 +02:00

29 lines
4.3 KiB
PHP

<?php
require __DIR__.'/boot-QA.php';use App\Models\User;use App\Models\Opportunity;use App\Services\PortalProfileAccess;use Illuminate\Support\Facades\DB;
$f=json_decode(file_get_contents('C:/Users/macbook/.config/investmoz/promotor-contexto-QA-20261015/fixture-private.json'),true);
$a=app(PortalProfileAccess::class);$actor=User::findOrFail(2);$super=User::findOrFail(13);$normal=User::findOrFail(14);$own=Opportunity::findOrFail($f['record_id']);$other=Opportunity::findOrFail($f['foreign_record_id']);$before=$own->getRawOriginal();$checks=[];
$check=function($name,$ok)use(&$checks){if(!$ok)throw new RuntimeException($name);$checks[$name]=true;};
$check('existing_pair_unchanged',hash('sha256',DB::table('portal_superuser_pair')->orderBy('id')->get()->toJson())===$f['superuser_pair_sha256']);
$check('existing_role_assignments_unchanged',hash('sha256',DB::table('portal_role_assignments')->orderBy('id')->get()->toJson())===$f['role_assignments_sha256']);
$check('no_exceptional_elevations_granted',!DB::table('portal_security_approvals')->where('kind','elevation')->whereNotNull('approved_by')->where('expires_at','>',now())->exists());
$check('dual_member_is_superuser_and_promoter',$a->superuser($actor)&&$a->has($actor,'promoter'));
$check('normal_promoter_creation_without_exceptional_elevation',$a->canCreate($actor,$f['organization_id'],'investment_project'));
$check('single_promoter_behavior_preserved',$a->canCreate($normal,$f['organization_id'],'investment_project'));
$check('superuser_only_cannot_create',$a->canCreate($super,$f['organization_id'],'investment_project')===false);
$check('unapproved_type_cannot_create',$a->canCreate($actor,$f['organization_id'],'financing')===false);
$check('nonexistent_organization_cannot_create',$a->canCreate($actor,'00000000-0000-4000-8000-000000000000','investment_project')===false);
$check('own_record_view_and_edit',$a->canView($actor,$own)&&$a->canEdit($actor,$own));
$check('foreign_record_still_denied',!$a->canView($actor,$other)&&!$a->canEdit($actor,$other));
$ids=$a->scope(Opportunity::query(),$actor)->pluck('id')->all();$check('listing_only_normal_promoter_scope',in_array($own->id,$ids,true)&&!in_array($other->id,$ids,true));
foreach(['validate','publish','archive']as$operation)$check($operation.'_still_requires_exceptional_elevation',$a->operational($actor,$operation,$own->id)===false);
$check('foreign_view_keeps_exceptional_elevation',$a->operational($actor,'view',$other->id)===false);
$auditor=new class extends PortalProfileAccess {public function has(User $actor,string $role):bool{return $role==='auditor'||parent::has($actor,$role);}};
$check('auditor_denial_still_prevalent',!$auditor->canCreate($actor,$f['organization_id'],'investment_project')&&!$auditor->canEdit($actor,$own));
$unverified=clone $actor;$unverified->email_verified_at=null;$check('unverified_actor_denied',!$a->canCreate($unverified,$f['organization_id'],'investment_project'));
$closed=clone $own;$closed->workflow_context=[...$closed->workflow_context,'working_state'=>'published'];$check('closed_state_edit_still_denied',!$a->canEdit($actor,$closed));
DB::beginTransaction();try{DB::table('portal_role_assignments')->where('user_id',2)->where('role','promoter')->update(['revoked_at'=>now()]);$check('revoked_promoter_context_denied',!$a->canCreate($actor,$f['organization_id'],'investment_project')&&!$a->canView($actor,$own)&&!$a->canEdit($actor,$own));}finally{DB::rollBack();}
$check('record_unchanged_after_proof',$own->fresh()->getRawOriginal()===$before);
$check('all_role_assignments_preserved_after_negative_proof',hash('sha256',DB::table('portal_role_assignments')->orderBy('id')->get()->toJson())===$f['role_assignments_sha256']);
$check('classification_self_approval_remains_denied',!app(App\Services\OpportunityClassification::class)->canReview($actor,$own,'regulation'));
$proof=['target'=>portalQaAssertTarget($target),'checks'=>$checks,'count'=>count($checks),'role_or_pair_changes'=>0,'active_changes'=>0,'workflow_transitions'=>0,'canonical_business_saves'=>0,'exceptional_approval_controller_unchanged'=>true,'negative_revocation_proof'=>'QA transaction rolled back; no new grants'];file_put_contents(__DIR__.'/SCOPES-QA.json',json_encode($proof,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE));echo json_encode(['checks'=>count($checks),'result'=>'passed','role_changes'=>0,'active_changes'=>0]);