-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Fix comments (and systemtags) when involving users with numerical ids #8355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a5a0a93
test creating comments with numeric user ids
blizzz 023d028
fix creating comments when file is accessible to users with numeric ids
blizzz 011dab2
tests for systemtags related to numeric user ids
blizzz aeb7503
fix systemtags event with numeric user ids
blizzz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,187 @@ | ||
| <?php | ||
| /** | ||
| * @copyright Copyright (c) 2018 Arthur Schiwon <blizzz@arthur-schiwon.de> | ||
| * | ||
| * @author Arthur Schiwon <blizzz@arthur-schiwon.de> | ||
| * | ||
| * @license GNU AGPL version 3 or any later version | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
|
|
||
| namespace OCA\Comments\Tests\Unit\Activity; | ||
|
|
||
| use OCA\Comments\Activity\Listener; | ||
| use OCP\Activity\IEvent; | ||
| use OCP\Activity\IManager; | ||
| use OCP\App\IAppManager; | ||
| use OCP\Comments\CommentsEvent; | ||
| use OCP\Comments\IComment; | ||
| use OCP\Files\Config\ICachedMountFileInfo; | ||
| use OCP\Files\Config\IMountProviderCollection; | ||
| use OCP\Files\Config\IUserMountCache; | ||
| use OCP\Files\Folder; | ||
| use OCP\Files\IRootFolder; | ||
| use OCP\Files\Node; | ||
| use OCP\IUser; | ||
| use OCP\IUserSession; | ||
| use OCP\Share\IShareHelper; | ||
| use Test\TestCase; | ||
|
|
||
| class ListenerTest extends TestCase { | ||
|
|
||
| /** @var Listener */ | ||
| protected $listener; | ||
|
|
||
| /** @var IManager|\PHPUnit_Framework_MockObject_MockObject */ | ||
| protected $activityManager; | ||
|
|
||
| /** @var IUserSession|\PHPUnit_Framework_MockObject_MockObject */ | ||
| protected $session; | ||
|
|
||
| /** @var IAppManager|\PHPUnit_Framework_MockObject_MockObject */ | ||
| protected $appManager; | ||
|
|
||
| /** @var IMountProviderCollection|\PHPUnit_Framework_MockObject_MockObject */ | ||
| protected $mountProviderCollection; | ||
|
|
||
| /** @var IRootFolder|\PHPUnit_Framework_MockObject_MockObject */ | ||
| protected $rootFolder; | ||
|
|
||
| /** @var IShareHelper|\PHPUnit_Framework_MockObject_MockObject */ | ||
| protected $shareHelper; | ||
|
|
||
| protected function setUp() { | ||
| parent::setUp(); | ||
|
|
||
| $this->activityManager = $this->createMock(IManager::class); | ||
| $this->session = $this->createMock(IUserSession::class); | ||
| $this->appManager = $this->createMock(IAppManager::class); | ||
| $this->mountProviderCollection = $this->createMock(IMountProviderCollection::class); | ||
| $this->rootFolder = $this->createMock(IRootFolder::class); | ||
| $this->shareHelper = $this->createMock(IShareHelper::class); | ||
|
|
||
| $this->listener = new Listener( | ||
| $this->activityManager, | ||
| $this->session, | ||
| $this->appManager, | ||
| $this->mountProviderCollection, | ||
| $this->rootFolder, | ||
| $this->shareHelper | ||
| ); | ||
| } | ||
|
|
||
| public function testCommentEvent() { | ||
| $this->appManager->expects($this->any()) | ||
| ->method('isInstalled') | ||
| ->with('activity') | ||
| ->willReturn(true); | ||
|
|
||
| $comment = $this->createMock(IComment::class); | ||
| $comment->expects($this->any()) | ||
| ->method('getObjectType') | ||
| ->willReturn('files'); | ||
|
|
||
| /** @var CommentsEvent|\PHPUnit_Framework_MockObject_MockObject $event */ | ||
| $event = $this->createMock(CommentsEvent::class); | ||
| $event->expects($this->any()) | ||
| ->method('getComment') | ||
| ->willReturn($comment); | ||
| $event->expects($this->any()) | ||
| ->method('getEvent') | ||
| ->willReturn(CommentsEvent::EVENT_ADD); | ||
|
|
||
| /** @var IUser|\PHPUnit_Framework_MockObject_MockObject $ownerUser */ | ||
| $ownerUser = $this->createMock(IUser::class); | ||
| $ownerUser->expects($this->any()) | ||
| ->method('getUID') | ||
| ->willReturn('937393'); | ||
|
|
||
| /** @var \PHPUnit_Framework_MockObject_MockObject $mount */ | ||
| $mount = $this->createMock(ICachedMountFileInfo::class); | ||
| $mount->expects($this->any()) | ||
| ->method('getUser') | ||
| ->willReturn($ownerUser); // perhaps not the right user, but does not matter in this scenario | ||
|
|
||
| $mounts = [ $mount, $mount ]; // to make sure duplicates are dealt with | ||
|
|
||
| $userMountCache = $this->createMock(IUserMountCache::class); | ||
| $userMountCache->expects($this->any()) | ||
| ->method('getMountsForFileId') | ||
| ->willReturn($mounts); | ||
|
|
||
| $this->mountProviderCollection->expects($this->any()) | ||
| ->method('getMountCache') | ||
| ->willReturn($userMountCache); | ||
|
|
||
| $node = $this->createMock(Node::class); | ||
| $nodes = [ $node ]; | ||
|
|
||
| $ownerFolder = $this->createMock(Folder::class); | ||
| $ownerFolder->expects($this->any()) | ||
| ->method('getById') | ||
| ->willReturn($nodes); | ||
|
|
||
| $this->rootFolder->expects($this->any()) | ||
| ->method('getUserFolder') | ||
| ->willReturn($ownerFolder); | ||
|
|
||
| $al = [ 'users' => [ | ||
| '873304' => 'i/got/it/here', | ||
| '254342' => 'there/i/have/it', | ||
| 'sandra' => 'and/here/i/placed/it' | ||
| ]]; | ||
| $this->shareHelper->expects($this->any()) | ||
| ->method('getPathsForAccessList') | ||
| ->willReturn($al); | ||
|
|
||
| $this->session->expects($this->any()) | ||
| ->method('getUser') | ||
| ->willReturn($ownerUser); | ||
|
|
||
| /** @var \PHPUnit_Framework_MockObject_MockObject $activity */ | ||
| $activity = $this->createMock(IEvent::class); | ||
| $activity->expects($this->exactly(count($al['users']))) | ||
| ->method('setAffectedUser'); | ||
| $activity->expects($this->once()) | ||
| ->method('setApp') | ||
| ->with('comments') | ||
| ->willReturnSelf(); | ||
| $activity->expects($this->once()) | ||
| ->method('setType') | ||
| ->with('comments') | ||
| ->willReturnSelf(); | ||
| $activity->expects($this->once()) | ||
| ->method('setAuthor') | ||
| ->with($ownerUser->getUID()) | ||
| ->willReturnSelf(); | ||
| $activity->expects($this->once()) | ||
| ->method('setObject') | ||
| ->with('files', $this->anything()) | ||
| ->willReturnSelf(); | ||
| $activity->expects($this->once()) | ||
| ->method('setMessage') | ||
| ->with('add_comment_message', $this->anything()) | ||
| ->willReturnSelf(); | ||
|
|
||
| $this->activityManager->expects($this->once()) | ||
| ->method('generateEvent') | ||
| ->willReturn($activity); | ||
| $this->activityManager->expects($this->exactly(count($al['users']))) | ||
| ->method('publish'); | ||
|
|
||
| $this->listener->commentEvent($event); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that also means leading zeros will be a problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keys with leading zeros are handled as strings, provided that they are passed as strings. #consistencyftw