From 25bcd71d029dd301321f797710d6e628540adb04 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 7 Nov 2016 15:08:56 +0100 Subject: add activity if a file was shared by mail Signed-off-by: Bjoern Schiessle --- apps/sharebymail/tests/ActivityTest.php | 68 ++++++++++++++++++++++ apps/sharebymail/tests/ShareByMailProviderTest.php | 17 ++++-- 2 files changed, 80 insertions(+), 5 deletions(-) create mode 100644 apps/sharebymail/tests/ActivityTest.php (limited to 'apps/sharebymail/tests') diff --git a/apps/sharebymail/tests/ActivityTest.php b/apps/sharebymail/tests/ActivityTest.php new file mode 100644 index 00000000000..9bc8c827da9 --- /dev/null +++ b/apps/sharebymail/tests/ActivityTest.php @@ -0,0 +1,68 @@ + + * + * @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 . + * + */ + + +namespace OCA\ShareByMail\Tests; + + +use OCA\ShareByMail\Activity; + +class ActivityTest extends \Test\TestCase { + + /** + * @var \OCA\ShareByMail\Activity + */ + private $activity; + + protected function setUp() { + parent::setUp(); + $this->activity = new Activity( + $this->getMockBuilder('OCP\L10N\IFactory') + ->disableOriginalConstructor() + ->getMock(), + $this->getMockBuilder('OCP\Activity\IManager') + ->disableOriginalConstructor() + ->getMock() + ); + } + + /** + * @dataProvider dataTestGetSpecialParameterList + * + */ + public function testGetSpecialParameterList($app, $text, $expected) { + $result = $this->activity->getSpecialParameterList($app, $text); + $this->assertSame($expected, $result); + } + + public function dataTestGetSpecialParameterList() { + return [ + ['sharebymail', Activity::SUBJECT_SHARED_EMAIL_SELF, [0 => 'file', 1 => 'email']], + ['sharebymail', Activity::SUBJECT_SHARED_EMAIL_BY, [0 => 'file', 1 => 'email', 2 => 'user']], + ['sharebymail', 'unknown', false], + ['randomApp', Activity::SUBJECT_SHARED_EMAIL_SELF, false], + ['randomApp', Activity::SUBJECT_SHARED_EMAIL_BY, false], + + ]; + } + +} + diff --git a/apps/sharebymail/tests/ShareByMailProviderTest.php b/apps/sharebymail/tests/ShareByMailProviderTest.php index eedce286a03..65eded3eb7d 100644 --- a/apps/sharebymail/tests/ShareByMailProviderTest.php +++ b/apps/sharebymail/tests/ShareByMailProviderTest.php @@ -76,6 +76,9 @@ class ShareByMailProviderTest extends TestCase { /** @var IShare | \PHPUnit_Framework_MockObject_MockObject */ private $share; + /** @var \OCP\Activity\IManager | \PHPUnit_Framework_MockObject_MockObject */ + private $activityManager; + public function setUp() { parent::setUp(); @@ -94,6 +97,7 @@ class ShareByMailProviderTest extends TestCase { $this->mailer = $this->getMockBuilder('\OCP\Mail\IMailer')->getMock(); $this->urlGenerator = $this->getMockBuilder('\OCP\IUrlGenerator')->getMock(); $this->share = $this->getMockBuilder('\OCP\Share\IShare')->getMock(); + $this->activityManager = $this->getMockBuilder('OCP\Activity\IManager')->getMock(); $this->userManager->expects($this->any())->method('userExists')->willReturn(true); } @@ -116,7 +120,8 @@ class ShareByMailProviderTest extends TestCase { $this->l, $this->logger, $this->mailer, - $this->urlGenerator + $this->urlGenerator, + $this->activityManager ] ); @@ -133,7 +138,8 @@ class ShareByMailProviderTest extends TestCase { $this->l, $this->logger, $this->mailer, - $this->urlGenerator + $this->urlGenerator, + $this->activityManager ); } @@ -148,10 +154,11 @@ class ShareByMailProviderTest extends TestCase { $share = $this->getMockBuilder('\OCP\Share\IShare')->getMock(); $share->expects($this->once())->method('getSharedWith')->willReturn('user1'); - $instance = $this->getInstance(['getSharedWith', 'createMailShare', 'getRawShare', 'createShareObject']); + $instance = $this->getInstance(['getSharedWith', 'createMailShare', 'getRawShare', 'createShareObject', 'createActivity']); $instance->expects($this->once())->method('getSharedWith')->willReturn([]); $instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42); + $instance->expects($this->once())->method('createActivity')->with($share); $instance->expects($this->once())->method('getRawShare')->with(42)->willReturn('rawShare'); $instance->expects($this->once())->method('createShareObject')->with('rawShare')->willReturn('shareObject'); @@ -614,7 +621,7 @@ class ShareByMailProviderTest extends TestCase { $userManager = \OC::$server->getUserManager(); $rootFolder = \OC::$server->getRootFolder(); - $provider = $this->getInstance(['sendMailNotification']); + $provider = $this->getInstance(['sendMailNotification', 'createActivity']); $u1 = $userManager->createUser('testFed', md5(time())); $u2 = $userManager->createUser('testFed2', md5(time())); @@ -651,5 +658,5 @@ class ShareByMailProviderTest extends TestCase { $u1->delete(); $u2->delete(); } - + } -- cgit v1.2.3