-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: update avatar route to check author of attachment (#7476)
Co-authored-by: Jon Waldstein <[email protected]>
- Loading branch information
1 parent
bbf81b5
commit a38b14c
Showing
4 changed files
with
158 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
tests/Unit/DonorDashboards/Repositories/TestProfile.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
|
||
namespace Give\Tests\Unit\DonorDashboards\Repositories; | ||
|
||
use Give\DonorDashboards\Profile; | ||
use Give\Donors\Models\Donor; | ||
use Give\Tests\TestCase; | ||
use Give\Tests\TestTraits\RefreshDatabase; | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
final class TestProfile extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
public function testAvatarBelongsToCurrentUserShouldReturnTrue(): void | ||
{ | ||
$user = self::factory()->user->create_and_get(); | ||
|
||
/** @var Donor $donor */ | ||
$donor = Donor::factory()->create([ | ||
'userId' => $user->ID, | ||
]); | ||
|
||
wp_set_current_user($donor->userId); | ||
|
||
$attachment = self::factory()->attachment->create_and_get([ | ||
'post_author' => $donor->userId, | ||
'post_title' => 'test', | ||
'post_content' => 'test', | ||
'post_status' => 'inherit', | ||
'post_mime_type' => 'image/jpeg', | ||
]); | ||
|
||
give()->donor_meta->update_meta($donor->id, '_give_donor_avatar_id', $attachment->ID); | ||
|
||
$profileRepository = new Profile(); | ||
|
||
$this->assertTrue($profileRepository->avatarBelongsToCurrentUser()); | ||
} | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
public function testAvatarBelongsToCurrentUserShouldReturnTrueWithAvatarParam(): void | ||
{ | ||
$user = self::factory()->user->create_and_get(); | ||
|
||
/** @var Donor $donor */ | ||
$donor = Donor::factory()->create([ | ||
'userId' => $user->ID, | ||
]); | ||
|
||
wp_set_current_user($donor->userId); | ||
|
||
$attachment = self::factory()->attachment->create_and_get([ | ||
'post_author' => $donor->userId, | ||
'post_title' => 'test', | ||
'post_content' => 'test', | ||
'post_status' => 'inherit', | ||
'post_mime_type' => 'image/jpeg', | ||
]); | ||
|
||
give()->donor_meta->update_meta($donor->id, '_give_donor_avatar_id', $attachment->ID); | ||
|
||
$profileRepository = new Profile(); | ||
|
||
$this->assertTrue($profileRepository->avatarBelongsToCurrentUser($attachment->ID)); | ||
} | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
public function testAvatarBelongsToCurrentUserShouldReturnFalse(): void | ||
{ | ||
$user = self::factory()->user->create_and_get(); | ||
|
||
/** @var Donor $donor */ | ||
$donor = Donor::factory()->create([ | ||
'userId' => $user->ID, | ||
]); | ||
|
||
wp_set_current_user($donor->userId); | ||
|
||
$attachment = self::factory()->attachment->create_and_get([ | ||
'post_author' => $donor->userId + 1, // Different user | ||
'post_title' => 'test', | ||
'post_content' => 'test', | ||
'post_status' => 'inherit', | ||
'post_mime_type' => 'image/jpeg', | ||
]); | ||
|
||
give()->donor_meta->update_meta($donor->id, '_give_donor_avatar_id', $attachment->ID); | ||
|
||
|
||
$profileRepository = new Profile(); | ||
|
||
$this->assertFalse($profileRepository->avatarBelongsToCurrentUser()); | ||
} | ||
} |