Files
projectsend/tests/Feature/Platform/CustomAssetActivityLogTest.php
T
ignacionelson 6e47d76ba6 ProjectSend 2.0.0
Client file sharing, rebuilt from the ground up: a private area per
client, resumable uploads, folders, groups and categories, sharing with
expiry dates and download limits, comments, file versions, an activity
log, a REST API, and sixteen languages.

This repository begins here. ProjectSend 2 was developed privately, and
that development history is not published — the previous generation
remains available, with its own history, at projectsend/legacy.

Free software under the GNU General Public License v2, or (at your
option) any later version.
2026-08-14 01:38:12 -03:00

69 lines
2.7 KiB
PHP

<?php
declare(strict_types=1);
use App\Models\User;
use App\Modules\Audit\Action;
use App\Modules\Audit\ActivityLog;
use App\Modules\Identity\Models\Role;
use App\Modules\Identity\Models\RolePermission;
use Illuminate\Support\Str;
use ProjectSend\CommunityModules\Modules\CustomAssets\Models\CustomAsset;
beforeEach(function () {
User::factory()->create();
});
/** A staff user whose role has exactly the given custom-asset permission keys. */
function staffWithCustomAssetPermissions(array $permissions): User
{
$role = Role::query()->create(['name' => 'Role '.Str::random(6)]);
foreach ($permissions as $permission) {
RolePermission::query()->create(['role_id' => $role->id, 'permission' => $permission]);
}
return User::factory()->create(['role_id' => $role->id]);
}
test('creating, updating, toggling, and deleting a custom asset each record a real activity log entry', function () {
$staff = staffWithCustomAssetPermissions(['create_assets', 'edit_assets', 'delete_assets']);
$this->actingAs($staff)->post('/system/settings/custom-assets', [
'title' => 'Tracking snippet',
'language' => 'js',
'content' => 'console.log(1);',
'surfaces' => ['public'],
'position' => 'head',
'enabled' => false,
])->assertRedirect();
$asset = CustomAsset::query()->sole();
$created = ActivityLog::query()->where('action', Action::CustomAssetCreated)->sole();
expect($created->actor_id)->toBe($staff->id)
->and($created->subject_name)->toBe('Tracking snippet');
$this->actingAs($staff)->patch("/system/settings/custom-assets/{$asset->id}", [
'title' => 'Tracking snippet (renamed)',
'language' => 'js',
'content' => 'console.log(2);',
'surfaces' => ['public'],
'position' => 'head',
'enabled' => false,
])->assertRedirect();
$updated = ActivityLog::query()->where('action', Action::CustomAssetUpdated)->sole();
expect($updated->subject_name)->toBe('Tracking snippet (renamed)');
$this->actingAs($staff)->patch("/system/settings/custom-assets/{$asset->id}/toggle")->assertRedirect();
$enabled = ActivityLog::query()->where('action', Action::CustomAssetEnabled)->sole();
expect($enabled->subject_id)->toBe($asset->id);
$this->actingAs($staff)->delete("/system/settings/custom-assets/{$asset->id}")->assertRedirect();
$deleted = ActivityLog::query()->where('action', Action::CustomAssetDeleted)->sole();
expect($deleted->context)->toBe(['name' => 'Tracking snippet (renamed)'])
->and(ActivityLog::query()->where('action', Action::CustomAssetDisabled)->count())->toBe(0);
})->skip(! class_exists(CustomAsset::class), 'projectsend/community-modules is not installed in this environment.');