Settings pages: - Redesign layout to match Sendkit (max-w-4xl, space-y-12, Separator sections) - Merge Members page into Workspace settings with Table, invite Dialog, ConfirmDeleteModal - Add workspace logo upload/delete routes and controller methods - Translate all hardcoded strings in Workspace.vue modals Language system: - Drop languages table, replace language_id FK with locale string column on users - Create config/languages.php for available languages and default locale - Add Spanish (es) translations (13 files) - Simplify HandleInertiaRequests, ProfileController, RegisteredUserController Code quality: - Add declare(strict_types=1) to all PHP files - Fix MastodonPublisher using wrong attribute (filename -> original_filename) - Fix HasMediaTest for new has_photo/photo_url accessors - Fix PublishToSocialPlatformTest type error revealed by strict_types - Remove orphaned Language model from AppServiceProvider morph map - Update User TypeScript interface (has_photo, photo_url, locale) - Eager load media relation on workspaces to prevent N+1 - Add 8 new tests for workspace logo upload/delete - Update workspace settings test to assert members/invitations props All 710 tests passing.
142 lines
4.4 KiB
PHP
142 lines
4.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Enums\User\Setup;
|
|
use App\Models\Media;
|
|
use App\Models\Post;
|
|
use App\Models\PostPlatform;
|
|
use App\Models\SocialAccount;
|
|
use App\Models\User;
|
|
use App\Models\Workspace;
|
|
use Illuminate\Http\UploadedFile;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
beforeEach(function () {
|
|
Storage::fake('local');
|
|
$this->user = User::factory()->create(['setup' => Setup::Completed]);
|
|
$this->workspace = Workspace::factory()->create(['user_id' => $this->user->id]);
|
|
$this->user->update(['current_workspace_id' => $this->workspace->id]);
|
|
|
|
$this->socialAccount = SocialAccount::factory()->create(['workspace_id' => $this->workspace->id]);
|
|
$this->post = Post::factory()->create([
|
|
'workspace_id' => $this->workspace->id,
|
|
'user_id' => $this->user->id,
|
|
]);
|
|
$this->postPlatform = PostPlatform::factory()->create([
|
|
'post_id' => $this->post->id,
|
|
'social_account_id' => $this->socialAccount->id,
|
|
]);
|
|
});
|
|
|
|
// Store tests
|
|
test('store media requires authentication', function () {
|
|
$response = $this->post(route('app.medias.store'), [
|
|
'model' => 'postPlatform',
|
|
'model_id' => $this->postPlatform->id,
|
|
'media' => UploadedFile::fake()->image('test.jpg'),
|
|
]);
|
|
|
|
$response->assertRedirect(route('login'));
|
|
});
|
|
|
|
test('store media uploads file', function () {
|
|
$response = $this->actingAs($this->user)->post(route('app.medias.store'), [
|
|
'model' => 'postPlatform',
|
|
'model_id' => $this->postPlatform->id,
|
|
'media' => UploadedFile::fake()->image('test.jpg'),
|
|
]);
|
|
|
|
$response->assertOk();
|
|
$response->assertJsonStructure(['id', 'url', 'type', 'original_filename']);
|
|
});
|
|
|
|
test('store media validates required fields', function () {
|
|
$response = $this->actingAs($this->user)->post(route('app.medias.store'), [
|
|
'model' => '',
|
|
'model_id' => '',
|
|
]);
|
|
|
|
$response->assertSessionHasErrors(['model', 'model_id', 'media']);
|
|
});
|
|
|
|
// Destroy tests
|
|
test('destroy media requires authentication', function () {
|
|
$media = Media::factory()->create([
|
|
'mediable_id' => $this->postPlatform->id,
|
|
'mediable_type' => 'postPlatform',
|
|
]);
|
|
|
|
$response = $this->delete(route('app.medias.destroy', [$this->postPlatform->id, $media]));
|
|
|
|
$response->assertRedirect(route('login'));
|
|
});
|
|
|
|
test('destroy media deletes the media', function () {
|
|
$media = Media::factory()->create([
|
|
'mediable_id' => $this->postPlatform->id,
|
|
'mediable_type' => 'postPlatform',
|
|
]);
|
|
|
|
$response = $this->actingAs($this->user)->delete(route('app.medias.destroy', [$this->postPlatform->id, $media]));
|
|
|
|
$response->assertOk();
|
|
$response->assertJson(['success' => true]);
|
|
expect(Media::find($media->id))->toBeNull();
|
|
});
|
|
|
|
test('destroy media returns 403 for mismatched model', function () {
|
|
$otherPostPlatform = PostPlatform::factory()->create([
|
|
'post_id' => $this->post->id,
|
|
'social_account_id' => $this->socialAccount->id,
|
|
]);
|
|
|
|
$media = Media::factory()->create([
|
|
'mediable_id' => $otherPostPlatform->id,
|
|
'mediable_type' => 'postPlatform',
|
|
]);
|
|
|
|
$response = $this->actingAs($this->user)->delete(route('app.medias.destroy', [$this->postPlatform->id, $media]));
|
|
|
|
$response->assertForbidden();
|
|
});
|
|
|
|
// Duplicate tests
|
|
test('duplicate media requires authentication', function () {
|
|
$media = Media::factory()->create([
|
|
'mediable_id' => $this->postPlatform->id,
|
|
'mediable_type' => 'postPlatform',
|
|
]);
|
|
|
|
$response = $this->post(route('app.medias.duplicate', $media), [
|
|
'targets' => [],
|
|
]);
|
|
|
|
$response->assertRedirect(route('login'));
|
|
});
|
|
|
|
test('duplicate media creates copies', function () {
|
|
$media = Media::factory()->create([
|
|
'mediable_id' => $this->postPlatform->id,
|
|
'mediable_type' => 'postPlatform',
|
|
]);
|
|
|
|
$otherPostPlatform = PostPlatform::factory()->create([
|
|
'post_id' => $this->post->id,
|
|
'social_account_id' => $this->socialAccount->id,
|
|
]);
|
|
|
|
$response = $this->actingAs($this->user)->post(route('app.medias.duplicate', $media), [
|
|
'targets' => [
|
|
[
|
|
'model' => 'postPlatform',
|
|
'model_id' => $otherPostPlatform->id,
|
|
],
|
|
],
|
|
]);
|
|
|
|
$response->assertOk();
|
|
$response->assertJsonCount(1);
|
|
|
|
expect(Media::where('mediable_id', $otherPostPlatform->id)->count())->toBe(1);
|
|
});
|