summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarco Nassabain <marco.nassabain@hotmail.com>2021-03-19 20:12:53 +0100
committerSean Molenaar <SMillerDev@users.noreply.github.com>2021-04-08 22:31:21 +0200
commit9e9bd24c5f865c5fc0275e39316b90a82231fca5 (patch)
treee10bcc38244dbd1badf52b992305fe76efdc3ff4 /tests
parent1a5ca7417249a991aaea4b36ab61e088cc827993 (diff)
✅ Add + update sharer display name tests
- added testMapSharedByDisplayNames - updated ItemController tests to expect call to function Signed-off-by: Marco Nassabain <marco.nassabain@hotmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/Unit/Controller/ItemControllerTest.php42
-rw-r--r--tests/Unit/Service/ShareServiceTest.php45
2 files changed, 84 insertions, 3 deletions
diff --git a/tests/Unit/Controller/ItemControllerTest.php b/tests/Unit/Controller/ItemControllerTest.php
index 0eae52a39..33488a338 100644
--- a/tests/Unit/Controller/ItemControllerTest.php
+++ b/tests/Unit/Controller/ItemControllerTest.php
@@ -293,6 +293,11 @@ class ItemControllerTest extends TestCase
->with('user', 2, 3, 0, false, false, [])
->will($this->returnValue($result['items']));
+ $this->shareService->expects($this->once())
+ ->method('mapSharedByDisplayNames')
+ ->with($result['items'])
+ ->will($this->returnValue($result['items']));
+
$response = $this->controller->index(ListType::FEED, 2, 3);
$this->assertEquals($result, $response);
}
@@ -330,6 +335,11 @@ class ItemControllerTest extends TestCase
->with('user', 2, 3, 0, false, false, [])
->will($this->returnValue($result['items']));
+ $this->shareService->expects($this->once())
+ ->method('mapSharedByDisplayNames')
+ ->with($result['items'])
+ ->will($this->returnValue($result['items']));
+
$response = $this->controller->index(ListType::FOLDER, 2, 3);
$this->assertEquals($result, $response);
}
@@ -367,6 +377,11 @@ class ItemControllerTest extends TestCase
->with('user', 2, 3, 0, false, [])
->will($this->returnValue($result['items']));
+ $this->shareService->expects($this->once())
+ ->method('mapSharedByDisplayNames')
+ ->with($result['items'])
+ ->will($this->returnValue($result['items']));
+
$response = $this->controller->index(ListType::STARRED, 2, 3);
$this->assertEquals($result, $response);
}
@@ -404,6 +419,11 @@ class ItemControllerTest extends TestCase
->with('user', 2, 3, 0, false, false, ['test', 'search'])
->will($this->returnValue($result['items']));
+ $this->shareService->expects($this->once())
+ ->method('mapSharedByDisplayNames')
+ ->with($result['items'])
+ ->will($this->returnValue($result['items']));
+
$response = $this->controller->index(ListType::FEED, 2, 3, 0, null, null, 'test%20%20search%20');
$this->assertEquals($result, $response);
}
@@ -420,6 +440,11 @@ class ItemControllerTest extends TestCase
->with('user', 2, 3, 10, false, true)
->will($this->returnValue($result['items']));
+ $this->shareService->expects($this->once())
+ ->method('mapSharedByDisplayNames')
+ ->with($result['items'])
+ ->will($this->returnValue($result['items']));
+
$this->feedService->expects($this->never())
->method('findAllForUser');
@@ -477,6 +502,11 @@ class ItemControllerTest extends TestCase
->with('user', 2, 3, false)
->will($this->returnValue($result['items']));
+ $this->shareService->expects($this->once())
+ ->method('mapSharedByDisplayNames')
+ ->with($result['items'])
+ ->will($this->returnValue($result['items']));
+
$response = $this->controller->newItems(ListType::FEED, 2, 3);
$this->assertEquals($result, $response);
}
@@ -517,6 +547,11 @@ class ItemControllerTest extends TestCase
->with('user', 2, 3, false)
->will($this->returnValue($result['items']));
+ $this->shareService->expects($this->once())
+ ->method('mapSharedByDisplayNames')
+ ->with($result['items'])
+ ->will($this->returnValue($result['items']));
+
$response = $this->controller->newItems(ListType::FOLDER, 2, 3);
$this->assertEquals($result, $response);
}
@@ -557,6 +592,11 @@ class ItemControllerTest extends TestCase
->with('user', 6, 3)
->will($this->returnValue($result['items']));
+ $this->shareService->expects($this->once())
+ ->method('mapSharedByDisplayNames')
+ ->with($result['items'])
+ ->will($this->returnValue($result['items']));
+
$response = $this->controller->newItems(ListType::UNREAD, 2, 3);
$this->assertEquals($result, $response);
}
@@ -579,4 +619,4 @@ class ItemControllerTest extends TestCase
}
-} \ No newline at end of file
+}
diff --git a/tests/Unit/Service/ShareServiceTest.php b/tests/Unit/Service/ShareServiceTest.php
index 9dd49484d..a3c9d81d2 100644
--- a/tests/Unit/Service/ShareServiceTest.php
+++ b/tests/Unit/Service/ShareServiceTest.php
@@ -27,8 +27,10 @@ use OCA\News\Db\Feed;
use OCA\News\Db\Item;
use OCP\IURLGenerator;
+use OCP\IUserManager;
use OCP\IConfig;
use OCP\IL10N;
+use OCP\IUser;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
@@ -51,7 +53,12 @@ class ShareServiceTest extends TestCase
* @var MockObject|IURLGenerator
*/
private $urlGenerator;
-
+
+ /**
+ * @var MockObject|IUserManager
+ */
+ private $userManager;
+
/**
* @var MockObject|IL10N
*/
@@ -92,6 +99,10 @@ class ShareServiceTest extends TestCase
->getMockBuilder(IURLGenerator::class)
->disableOriginalConstructor()
->getMock();
+ $this->userManager = $this
+ ->getMockBuilder(IUserManager::class)
+ ->disableOriginalConstructor()
+ ->getMock();
$this->l = $this->getMockBuilder(IL10N::class)
->disableOriginalConstructor()
->getMock();
@@ -102,6 +113,7 @@ class ShareServiceTest extends TestCase
$this->feedService,
$this->itemService,
$this->urlGenerator,
+ $this->userManager,
$this->l,
$this->logger
);
@@ -153,7 +165,7 @@ class ShareServiceTest extends TestCase
$this->urlGenerator->expects($this->once())
->method('getBaseUrl')
->will($this->returnValue('http://serverurl'));
-
+
$this->feedService->expects($this->once())
->method('findByUrl')
->with($this->recipient, $feedUrl)
@@ -247,4 +259,33 @@ class ShareServiceTest extends TestCase
$this->class->shareItemWithUser('sender', 1, 'recipient');
}
+
+
+ public function testMapSharedByDisplayNames()
+ {
+ $item1 = new Item();
+ $item1->setTitle('Item 1')
+ ->setSharedBy('sender');
+ $item2 = new Item();
+ $item2->setTitle('Item 2')
+ ->setSharedBy(null);
+
+ $items = [$item1, $item2];
+ $user = $this->getMockBuilder(IUser::class)
+ ->getMock();
+
+ $this->userManager->expects($this->once())
+ ->method('get')
+ ->with('sender')
+ ->will($this->returnValue($user));
+
+ $user->expects($this->once())
+ ->method('getDisplayName')
+ ->will($this->returnValue('Mr. Sender'));
+
+ $result = $this->class->mapSharedByDisplayNames($items);
+
+ $this->assertEquals('Mr. Sender', $result[0]->getSharedByDisplayName());
+ $this->assertEquals(null, $result[1]->getSharedByDisplayName());
+ }
}