summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@owncloud.com>2016-02-05 20:00:07 +0100
committerRoeland Jago Douma <rullzer@owncloud.com>2016-02-06 13:31:54 +0100
commit8486d617645a5ef75da34df10ed663ef77bed257 (patch)
tree5d42cc3c1b68139827e8cb0f90447664050b784f /tests
parent3028ec5440a3c4d448bbaf8a6b246391bea22317 (diff)
downloadnextcloud-server-8486d617645a5ef75da34df10ed663ef77bed257.tar.gz
nextcloud-server-8486d617645a5ef75da34df10ed663ef77bed257.zip
getSharesBy should also expire link shares
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/share20/managertest.php103
1 files changed, 103 insertions, 0 deletions
diff --git a/tests/lib/share20/managertest.php b/tests/lib/share20/managertest.php
index 55c13f03f8c..ea0fb1838d7 100644
--- a/tests/lib/share20/managertest.php
+++ b/tests/lib/share20/managertest.php
@@ -1700,6 +1700,109 @@ class ManagerTest extends \Test\TestCase {
$manager->createShare($share);
}
+ public function testGetSharesBy() {
+ $share = $this->manager->newShare();
+
+ $node = $this->getMock('OCP\Files\Folder');
+
+ $this->defaultProvider->expects($this->once())
+ ->method('getSharesBy')
+ ->with(
+ $this->equalTo('user'),
+ $this->equalTo(\OCP\Share::SHARE_TYPE_USER),
+ $this->equalTo($node),
+ $this->equalTo(true),
+ $this->equalTo(1),
+ $this->equalTo(1)
+ )->willReturn([$share]);
+
+ $shares = $this->manager->getSharesBy('user', \OCP\Share::SHARE_TYPE_USER, $node, true, 1, 1);
+
+ $this->assertCount(1, $shares);
+ $this->assertSame($share, $shares[0]);
+ }
+
+ /**
+ * Test to ensure we correctly remove expired link shares
+ *
+ * We have 8 Shares and we want the 3 first valid shares.
+ * share 3-6 and 8 are expired. Thus at the end of this test we should
+ * have received share 1,2 and 7. And from the manager. Share 3-6 should be
+ * deleted (as they are evaluated). but share 8 should still be there.
+ */
+ public function testGetSharesByExpiredLinkShares() {
+ $manager = $this->createManagerMock()
+ ->setMethods(['deleteShare'])
+ ->getMock();
+
+ /** @var \OCP\Share\IShare[] $shares */
+ $shares = [];
+
+ /*
+ * This results in an array of 8 IShare elements
+ */
+ for ($i = 0; $i < 8; $i++) {
+ $share = $this->manager->newShare();
+ $share->setId($i);
+ $shares[] = $share;
+ }
+
+ $today = new \DateTime();
+ $today->setTime(0,0,0);
+
+ /*
+ * Set the expiration date to today for some shares
+ */
+ $shares[2]->setExpirationDate($today);
+ $shares[3]->setExpirationDate($today);
+ $shares[4]->setExpirationDate($today);
+ $shares[5]->setExpirationDate($today);
+
+ /** @var \OCP\Share\IShare[] $i */
+ $shares2 = [];
+ for ($i = 0; $i < 8; $i++) {
+ $shares2[] = clone $shares[$i];
+ }
+
+ $node = $this->getMock('OCP\Files\File');
+
+ /*
+ * Simulate the getSharesBy call.
+ */
+ $this->defaultProvider
+ ->method('getSharesBy')
+ ->will($this->returnCallback(function($uid, $type, $node, $reshares, $limit, $offset) use (&$shares2) {
+ return array_slice($shares2, $offset, $limit);
+ }));
+
+ /*
+ * Simulate the deleteShare call.
+ */
+ $manager->method('deleteShare')
+ ->will($this->returnCallback(function($share) use (&$shares2) {
+ for($i = 0; $i < count($shares2); $i++) {
+ if ($shares2[$i]->getId() === $share->getId()) {
+ array_splice($shares2, $i, 1);
+ break;
+ }
+ }
+ }));
+
+ $res = $manager->getSharesBy('user', \OCP\Share::SHARE_TYPE_LINK, $node, true, 3, 0);
+
+ $this->assertCount(3, $res);
+ $this->assertEquals($shares[0]->getId(), $res[0]->getId());
+ $this->assertEquals($shares[1]->getId(), $res[1]->getId());
+ $this->assertEquals($shares[6]->getId(), $res[2]->getId());
+
+ $this->assertCount(4, $shares2);
+ $this->assertEquals(0, $shares2[0]->getId());
+ $this->assertEquals(1, $shares2[1]->getId());
+ $this->assertEquals(6, $shares2[2]->getId());
+ $this->assertEquals(7, $shares2[3]->getId());
+ $this->assertSame($today, $shares[3]->getExpirationDate());
+ }
+
public function testGetShareByToken() {
$factory = $this->getMock('\OCP\Share\IProviderFactory');