2026-01-18 18:56:51 +00:00
|
|
|
<?php
|
|
|
|
|
|
refactor: settings redesign, Spanish translations, language system, strict_types
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.
2026-03-30 03:20:43 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2026-01-18 18:56:51 +00:00
|
|
|
use App\Enums\SocialAccount\Platform;
|
|
|
|
|
use App\Enums\SocialAccount\Status;
|
2026-03-31 03:40:18 +00:00
|
|
|
use App\Enums\UserWorkspace\Role;
|
2026-01-18 18:56:51 +00:00
|
|
|
use App\Models\SocialAccount;
|
|
|
|
|
use App\Models\User;
|
|
|
|
|
use App\Models\Workspace;
|
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
|
use Laravel\Socialite\Facades\Socialite;
|
|
|
|
|
use Laravel\Socialite\Two\User as SocialiteUser;
|
|
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
|
$this->user = User::factory()->create();
|
|
|
|
|
$this->workspace = Workspace::factory()->create(['user_id' => $this->user->id]);
|
|
|
|
|
$this->user->update(['current_workspace_id' => $this->workspace->id]);
|
2026-04-15 01:22:04 +00:00
|
|
|
$this->workspace->members()->attach($this->user->id, ['role' => Role::Member->value]);
|
2026-01-18 18:56:51 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('linkedin connect redirects to oauth provider', function () {
|
2026-04-14 17:44:15 +00:00
|
|
|
$driverMock = Mockery::mock();
|
|
|
|
|
$driverMock->shouldReceive('scopes')->andReturnSelf();
|
|
|
|
|
$driverMock->shouldReceive('redirect')->andReturn(Mockery::mock([
|
|
|
|
|
'getTargetUrl' => 'https://www.linkedin.com/oauth/v2/authorization?test=1',
|
|
|
|
|
]));
|
|
|
|
|
|
2026-01-18 18:56:51 +00:00
|
|
|
Socialite::shouldReceive('driver')
|
|
|
|
|
->with('linkedin')
|
2026-04-14 17:44:15 +00:00
|
|
|
->andReturn($driverMock);
|
2026-01-18 18:56:51 +00:00
|
|
|
|
|
|
|
|
$response = $this->actingAs($this->user)
|
|
|
|
|
->withHeader('X-Inertia', 'true')
|
2026-03-29 22:24:28 +00:00
|
|
|
->get(route('app.social.linkedin.connect'));
|
2026-01-18 18:56:51 +00:00
|
|
|
|
|
|
|
|
$response->assertStatus(409); // Inertia::location returns 409 with X-Inertia header
|
|
|
|
|
|
|
|
|
|
expect(session('social_connect_workspace'))->toBe($this->workspace->id);
|
|
|
|
|
});
|
|
|
|
|
|
2026-06-10 17:56:44 +00:00
|
|
|
/**
|
|
|
|
|
* Mock the LinkedIn Socialite driver, hit /connect, and return the scopes
|
|
|
|
|
* the controller requested.
|
|
|
|
|
*
|
|
|
|
|
* @return array<int, string>
|
|
|
|
|
*/
|
|
|
|
|
$captureConnectScopes = function (object $test): array {
|
2026-05-28 03:54:26 +00:00
|
|
|
$captured = [];
|
|
|
|
|
|
|
|
|
|
$driverMock = Mockery::mock();
|
|
|
|
|
$driverMock->shouldReceive('scopes')
|
|
|
|
|
->withArgs(function (array $scopes) use (&$captured) {
|
|
|
|
|
$captured = $scopes;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
})
|
|
|
|
|
->andReturnSelf();
|
|
|
|
|
$driverMock->shouldReceive('redirect')->andReturn(Mockery::mock([
|
|
|
|
|
'getTargetUrl' => 'https://www.linkedin.com/oauth/v2/authorization?test=1',
|
|
|
|
|
]));
|
|
|
|
|
|
|
|
|
|
Socialite::shouldReceive('driver')
|
|
|
|
|
->with('linkedin')
|
|
|
|
|
->andReturn($driverMock);
|
|
|
|
|
|
2026-06-10 17:56:44 +00:00
|
|
|
$test->actingAs($test->user)
|
2026-05-28 03:54:26 +00:00
|
|
|
->withHeader('X-Inertia', 'true')
|
|
|
|
|
->get(route('app.social.linkedin.connect'));
|
|
|
|
|
|
2026-06-10 17:56:44 +00:00
|
|
|
return $captured;
|
|
|
|
|
};
|
|
|
|
|
|
2026-06-10 18:02:00 +00:00
|
|
|
test('linkedin connect requests the default scope set', function () use ($captureConnectScopes) {
|
|
|
|
|
config(['trypost.platforms.linkedin.scopes' => ['openid', 'profile', 'email', 'w_member_social']]);
|
2026-06-10 17:56:44 +00:00
|
|
|
|
|
|
|
|
expect($captureConnectScopes($this))->toEqualCanonicalizing([
|
2026-05-28 03:54:26 +00:00
|
|
|
'openid', 'profile', 'email', 'w_member_social',
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
2026-06-10 18:02:00 +00:00
|
|
|
test('linkedin connect requests the scopes configured via LINKEDIN_SCOPES', function () use ($captureConnectScopes) {
|
|
|
|
|
// Operators whose LinkedIn app has legacy/enterprise products approved
|
|
|
|
|
// override the default set via LINKEDIN_SCOPES (exploded into the config
|
|
|
|
|
// array), e.g. re-adding r_basicprofile to restore the vanityName lookup.
|
|
|
|
|
config(['trypost.platforms.linkedin.scopes' => ['openid', 'profile', 'email', 'w_member_social', 'r_basicprofile']]);
|
2026-05-28 03:54:26 +00:00
|
|
|
|
2026-06-10 17:56:44 +00:00
|
|
|
expect($captureConnectScopes($this))->toEqualCanonicalizing([
|
2026-06-10 18:02:00 +00:00
|
|
|
'openid', 'profile', 'email', 'w_member_social', 'r_basicprofile',
|
2026-05-28 03:54:26 +00:00
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-18 18:56:51 +00:00
|
|
|
test('linkedin oauth callback creates account', function () {
|
|
|
|
|
session([
|
|
|
|
|
'social_connect_workspace' => $this->workspace->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$socialiteUser = Mockery::mock(SocialiteUser::class);
|
|
|
|
|
$socialiteUser->shouldReceive('getId')->andReturn('abc123xyz');
|
|
|
|
|
$socialiteUser->shouldReceive('getNickname')->andReturn(null);
|
|
|
|
|
$socialiteUser->shouldReceive('getName')->andReturn('John Doe');
|
|
|
|
|
$socialiteUser->shouldReceive('getAvatar')->andReturn(null);
|
|
|
|
|
$socialiteUser->token = 'test-access-token';
|
|
|
|
|
$socialiteUser->refreshToken = 'test-refresh-token';
|
|
|
|
|
$socialiteUser->expiresIn = 5184000; // 60 days
|
|
|
|
|
$socialiteUser->approvedScopes = ['openid', 'profile', 'email', 'w_member_social'];
|
|
|
|
|
|
|
|
|
|
Socialite::shouldReceive('driver')
|
|
|
|
|
->with('linkedin')
|
|
|
|
|
->andReturn(Mockery::mock([
|
|
|
|
|
'user' => $socialiteUser,
|
|
|
|
|
]));
|
|
|
|
|
|
|
|
|
|
Http::fake([
|
|
|
|
|
'https://api.linkedin.com/v2/me*' => Http::response([
|
|
|
|
|
'id' => 'abc123xyz',
|
|
|
|
|
'vanityName' => 'johndoe',
|
|
|
|
|
'localizedFirstName' => 'John',
|
|
|
|
|
'localizedLastName' => 'Doe',
|
|
|
|
|
], 200),
|
|
|
|
|
]);
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->actingAs($this->user)->get(route('app.social.linkedin.callback'));
|
2026-01-18 18:56:51 +00:00
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertViewIs('auth.social-callback');
|
|
|
|
|
$response->assertViewHas('success', true);
|
|
|
|
|
|
|
|
|
|
$this->assertDatabaseHas('social_accounts', [
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'platform' => Platform::LinkedIn->value,
|
|
|
|
|
'platform_user_id' => 'abc123xyz',
|
|
|
|
|
'username' => 'johndoe',
|
|
|
|
|
'status' => Status::Connected->value,
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
fix(linkedin,pinterest): split CSV/space-joined OAuth scopes before saving
LinkedIn and Pinterest's OAuth providers return the granted scope list
joined by comma (LinkedIn) or space-in-one-element (Pinterest), but
Socialite's scope splitter doesn't match either, so 'approvedScopes'
lands as a single-element array containing the whole list:
LinkedIn: ['email,openid,profile,r_basicprofile,w_member_social']
Pinterest: ['boards:read boards:write pins:read pins:write user_accounts:read']
That breaks the publish-time scope check in PublishToSocialPlatform
(array_diff does exact string compare), surfacing as
'Missing permissions: w_member_social. Please reconnect your account'
even though the scopes were actually granted at the provider.
Fix is inline at each callback — re-split before saving. Each provider
has its own quirk (LinkedIn = comma, Pinterest = space), so each
controller handles its own separator.
Tests added: callback splits the joined approvedScopes into individual
tokens for both providers.
2026-05-14 13:55:53 +00:00
|
|
|
test('linkedin oauth callback splits comma-separated approvedScopes before saving', function () {
|
|
|
|
|
session(['social_connect_workspace' => $this->workspace->id]);
|
|
|
|
|
|
|
|
|
|
$socialiteUser = Mockery::mock(SocialiteUser::class);
|
|
|
|
|
$socialiteUser->shouldReceive('getId')->andReturn('abc123xyz');
|
|
|
|
|
$socialiteUser->shouldReceive('getNickname')->andReturn(null);
|
|
|
|
|
$socialiteUser->shouldReceive('getName')->andReturn('John Doe');
|
|
|
|
|
$socialiteUser->shouldReceive('getAvatar')->andReturn(null);
|
|
|
|
|
$socialiteUser->token = 'test-access-token';
|
|
|
|
|
$socialiteUser->refreshToken = 'test-refresh-token';
|
|
|
|
|
$socialiteUser->expiresIn = 5184000;
|
|
|
|
|
// LinkedIn returns scopes comma-separated; Socialite's LinkedInProvider
|
|
|
|
|
// splits on space (the OAuth 2.0 default), so approvedScopes lands as
|
|
|
|
|
// a single-element array with the whole CSV inside. The save path
|
|
|
|
|
// must normalize back to individual tokens.
|
2026-05-28 03:54:26 +00:00
|
|
|
$socialiteUser->approvedScopes = ['email,openid,profile,w_member_social'];
|
fix(linkedin,pinterest): split CSV/space-joined OAuth scopes before saving
LinkedIn and Pinterest's OAuth providers return the granted scope list
joined by comma (LinkedIn) or space-in-one-element (Pinterest), but
Socialite's scope splitter doesn't match either, so 'approvedScopes'
lands as a single-element array containing the whole list:
LinkedIn: ['email,openid,profile,r_basicprofile,w_member_social']
Pinterest: ['boards:read boards:write pins:read pins:write user_accounts:read']
That breaks the publish-time scope check in PublishToSocialPlatform
(array_diff does exact string compare), surfacing as
'Missing permissions: w_member_social. Please reconnect your account'
even though the scopes were actually granted at the provider.
Fix is inline at each callback — re-split before saving. Each provider
has its own quirk (LinkedIn = comma, Pinterest = space), so each
controller handles its own separator.
Tests added: callback splits the joined approvedScopes into individual
tokens for both providers.
2026-05-14 13:55:53 +00:00
|
|
|
|
|
|
|
|
Socialite::shouldReceive('driver')
|
|
|
|
|
->with('linkedin')
|
|
|
|
|
->andReturn(Mockery::mock(['user' => $socialiteUser]));
|
|
|
|
|
|
|
|
|
|
Http::fake([
|
|
|
|
|
'https://api.linkedin.com/v2/me*' => Http::response([
|
|
|
|
|
'id' => 'abc123xyz',
|
|
|
|
|
'vanityName' => 'johndoe',
|
|
|
|
|
], 200),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->actingAs($this->user)->get(route('app.social.linkedin.callback'));
|
|
|
|
|
|
|
|
|
|
$account = SocialAccount::where('platform_user_id', 'abc123xyz')->first();
|
|
|
|
|
expect($account->scopes)->toEqualCanonicalizing([
|
2026-05-28 03:54:26 +00:00
|
|
|
'email', 'openid', 'profile', 'w_member_social',
|
fix(linkedin,pinterest): split CSV/space-joined OAuth scopes before saving
LinkedIn and Pinterest's OAuth providers return the granted scope list
joined by comma (LinkedIn) or space-in-one-element (Pinterest), but
Socialite's scope splitter doesn't match either, so 'approvedScopes'
lands as a single-element array containing the whole list:
LinkedIn: ['email,openid,profile,r_basicprofile,w_member_social']
Pinterest: ['boards:read boards:write pins:read pins:write user_accounts:read']
That breaks the publish-time scope check in PublishToSocialPlatform
(array_diff does exact string compare), surfacing as
'Missing permissions: w_member_social. Please reconnect your account'
even though the scopes were actually granted at the provider.
Fix is inline at each callback — re-split before saving. Each provider
has its own quirk (LinkedIn = comma, Pinterest = space), so each
controller handles its own separator.
Tests added: callback splits the joined approvedScopes into individual
tokens for both providers.
2026-05-14 13:55:53 +00:00
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-18 18:56:51 +00:00
|
|
|
test('linkedin callback fails with expired session', function () {
|
|
|
|
|
// No session data - simulating expired session
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->actingAs($this->user)->get(route('app.social.linkedin.callback'));
|
2026-01-18 18:56:51 +00:00
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertViewHas('success', false);
|
|
|
|
|
$response->assertViewHas('message', 'Session expired. Please try again.');
|
|
|
|
|
});
|
|
|
|
|
|
2026-06-22 12:26:31 +00:00
|
|
|
test('user can connect multiple linkedin accounts in self-hosted mode', function () {
|
|
|
|
|
config()->set('trypost.self_hosted', true);
|
|
|
|
|
|
2026-01-18 18:56:51 +00:00
|
|
|
SocialAccount::factory()->linkedin()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'platform_user_id' => 'abc123xyz',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
session([
|
|
|
|
|
'social_connect_workspace' => $this->workspace->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$socialiteUser = Mockery::mock(SocialiteUser::class);
|
|
|
|
|
$socialiteUser->shouldReceive('getId')->andReturn('xyz789abc');
|
|
|
|
|
$socialiteUser->shouldReceive('getNickname')->andReturn(null);
|
|
|
|
|
$socialiteUser->shouldReceive('getName')->andReturn('Jane Doe');
|
|
|
|
|
$socialiteUser->shouldReceive('getAvatar')->andReturn(null);
|
|
|
|
|
$socialiteUser->token = 'new-access-token';
|
|
|
|
|
$socialiteUser->refreshToken = 'new-refresh-token';
|
|
|
|
|
$socialiteUser->expiresIn = 5184000;
|
|
|
|
|
$socialiteUser->approvedScopes = ['openid', 'profile', 'email', 'w_member_social'];
|
|
|
|
|
|
|
|
|
|
Socialite::shouldReceive('driver')
|
|
|
|
|
->with('linkedin')
|
|
|
|
|
->andReturn(Mockery::mock([
|
|
|
|
|
'user' => $socialiteUser,
|
|
|
|
|
]));
|
|
|
|
|
|
|
|
|
|
Http::fake([
|
|
|
|
|
'https://api.linkedin.com/v2/me*' => Http::response([
|
2026-04-14 22:48:35 +00:00
|
|
|
'vanityName' => 'janedoe',
|
2026-01-18 18:56:51 +00:00
|
|
|
], 200),
|
|
|
|
|
]);
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->actingAs($this->user)->get(route('app.social.linkedin.callback'));
|
2026-01-18 18:56:51 +00:00
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertViewHas('success', true);
|
|
|
|
|
|
2026-04-14 22:48:35 +00:00
|
|
|
expect($this->workspace->socialAccounts()->where('platform', Platform::LinkedIn)->count())->toBe(2);
|
2026-01-18 18:56:51 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('linkedin callback handles oauth errors gracefully', function () {
|
|
|
|
|
session([
|
|
|
|
|
'social_connect_workspace' => $this->workspace->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$mock = Mockery::mock();
|
2026-03-29 22:24:28 +00:00
|
|
|
$mock->shouldReceive('user')->andThrow(new Exception('OAuth error'));
|
2026-01-18 18:56:51 +00:00
|
|
|
|
|
|
|
|
Socialite::shouldReceive('driver')
|
|
|
|
|
->with('linkedin')
|
|
|
|
|
->andReturn($mock);
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->actingAs($this->user)->get(route('app.social.linkedin.callback'));
|
2026-01-18 18:56:51 +00:00
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertViewHas('success', false);
|
|
|
|
|
$response->assertViewHas('message', 'Error connecting account. Please try again.');
|
|
|
|
|
});
|