actingAs(User::factory()->create()); $tenant = Tenant::factory()->create(); putenv('INTUNE_TENANT_ID='.$tenant->tenant_id); $tenant->makeCurrent(); $policy = Policy::factory()->create([ 'tenant_id' => $tenant->id, 'policy_type' => $policyType, 'platform' => 'all', 'display_name' => 'Script policy', 'external_id' => 'policy-1', ]); config([ 'tenantpilot.display.show_script_content' => true, ]); $scriptContent = str_repeat('X', 20); if ($policyType === 'deviceShellScript') { $scriptContent = "#!/bin/zsh\n".str_repeat('X', 20); } $version = PolicyVersion::factory()->create([ 'policy_id' => $policy->id, 'tenant_id' => $tenant->id, 'policy_type' => $policyType, 'snapshot' => [ '@odata.type' => $odataType, 'displayName' => 'Script policy', 'description' => 'desc', 'scriptContent' => $scriptContent, ], ]); $this->get(\App\Filament\Resources\PolicyVersionResource::getUrl('index')) ->assertSuccessful(); $this->get(\App\Filament\Resources\PolicyVersionResource::getUrl('view', ['record' => $version]).'?tab=normalized-settings') ->assertSuccessful(); $originalEnv !== false ? putenv("INTUNE_TENANT_ID={$originalEnv}") : putenv('INTUNE_TENANT_ID'); })->with([ ['deviceManagementScript', '#microsoft.graph.deviceManagementScript'], ['deviceShellScript', '#microsoft.graph.deviceShellScript'], ['deviceHealthScript', '#microsoft.graph.deviceHealthScript'], ]); it('renders diff tab with highlighted script content for script policies', function () { $originalEnv = getenv('INTUNE_TENANT_ID'); putenv('INTUNE_TENANT_ID='); $this->actingAs(User::factory()->create()); config([ 'tenantpilot.display.show_script_content' => true, 'tenantpilot.display.max_script_content_chars' => 5000, ]); $tenant = Tenant::factory()->create(); putenv('INTUNE_TENANT_ID='.$tenant->tenant_id); $tenant->makeCurrent(); $policy = \App\Models\Policy::factory()->create([ 'tenant_id' => $tenant->getKey(), 'policy_type' => 'deviceManagementScript', 'platform' => 'windows', ]); $scriptOne = "# test\n".str_repeat("Write-Host 'one'\n", 40); $scriptTwo = "# test\n".str_repeat("Write-Host 'two'\n", 40); $v1 = \App\Models\PolicyVersion::factory()->create([ 'policy_id' => $policy->getKey(), 'tenant_id' => $tenant->getKey(), 'version_number' => 1, 'policy_type' => 'deviceManagementScript', 'platform' => 'windows', 'snapshot' => [ '@odata.type' => '#microsoft.graph.deviceManagementScript', 'displayName' => 'My script', 'scriptContent' => base64_encode($scriptOne), ], ]); $v2 = \App\Models\PolicyVersion::factory()->create([ 'policy_id' => $policy->getKey(), 'tenant_id' => $tenant->getKey(), 'version_number' => 2, 'policy_type' => 'deviceManagementScript', 'platform' => 'windows', 'snapshot' => [ '@odata.type' => '#microsoft.graph.deviceManagementScript', 'displayName' => 'My script', 'scriptContent' => base64_encode($scriptTwo), ], ]); $url = \App\Filament\Resources\PolicyVersionResource::getUrl('view', ['record' => $v2]); $this->get($url.'?tab=diff') ->assertSuccessful() ->assertSee('torchlight', false); $originalEnv !== false ? putenv("INTUNE_TENANT_ID={$originalEnv}") : putenv('INTUNE_TENANT_ID'); });