@@ -73,40 +73,108 @@ protected function tearDown() {
7373 /**
7474 * @medium
7575 */
76- function testCreateShare () {
76+ function testCreateShareUserFile () {
77+ // simulate a post request
78+ $ _POST ['path ' ] = $ this ->filename ;
79+ $ _POST ['shareWith ' ] = \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2 ;
80+ $ _POST ['shareType ' ] = \OCP \Share::SHARE_TYPE_USER ;
81+
82+ $ result = \OCA \Files_Sharing \API \Local::createShare ([]);
83+
84+ $ this ->assertTrue ($ result ->succeeded ());
85+ $ data = $ result ->getData ();
86+ $ this ->assertEquals (23 , $ data ['permissions ' ]);
87+ $ this ->assertEmpty ($ data ['expiration ' ]);
88+
89+ $ share = $ this ->getShareFromId ($ data ['id ' ]);
90+ $ items = \OCP \Share::getItemShared ('file ' , $ share ['item_source ' ]);
91+ $ this ->assertTrue (!empty ($ items ));
7792
78- // share to user
93+ $ fileinfo = $ this ->view ->getFileInfo ($ this ->filename );
94+ \OCP \Share::unshare ('file ' , $ fileinfo ['fileid ' ], \OCP \Share::SHARE_TYPE_USER ,
95+ \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2 );
96+ }
7997
98+ function testCreateShareUserFolder () {
8099 // simulate a post request
81- $ _POST ['path ' ] = $ this ->filename ;
100+ $ _POST ['path ' ] = $ this ->folder ;
82101 $ _POST ['shareWith ' ] = \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2 ;
83102 $ _POST ['shareType ' ] = \OCP \Share::SHARE_TYPE_USER ;
84103
85- $ result = \OCA \Files_Sharing \API \Local::createShare (array () );
104+ $ result = \OCA \Files_Sharing \API \Local::createShare ([] );
86105
87106 $ this ->assertTrue ($ result ->succeeded ());
88107 $ data = $ result ->getData ();
108+ $ this ->assertEquals (31 , $ data ['permissions ' ]);
109+ $ this ->assertEmpty ($ data ['expiration ' ]);
89110
90111 $ share = $ this ->getShareFromId ($ data ['id ' ]);
112+ $ items = \OCP \Share::getItemShared ('file ' , $ share ['item_source ' ]);
113+ $ this ->assertTrue (!empty ($ items ));
114+
115+ $ fileinfo = $ this ->view ->getFileInfo ($ this ->folder );
116+ \OCP \Share::unshare ('folder ' , $ fileinfo ['fileid ' ], \OCP \Share::SHARE_TYPE_USER ,
117+ \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2 );
118+ }
119+
120+
121+ function testCreateShareGroupFile () {
122+ // simulate a post request
123+ $ _POST ['path ' ] = $ this ->filename ;
124+ $ _POST ['shareWith ' ] = \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_GROUP1 ;
125+ $ _POST ['shareType ' ] = \OCP \Share::SHARE_TYPE_GROUP ;
126+
127+ $ result = \OCA \Files_Sharing \API \Local::createShare ([]);
91128
129+ $ this ->assertTrue ($ result ->succeeded ());
130+ $ data = $ result ->getData ();
131+ $ this ->assertEquals (23 , $ data ['permissions ' ]);
132+ $ this ->assertEmpty ($ data ['expiration ' ]);
133+
134+ $ share = $ this ->getShareFromId ($ data ['id ' ]);
92135 $ items = \OCP \Share::getItemShared ('file ' , $ share ['item_source ' ]);
136+ $ this ->assertTrue (!empty ($ items ));
137+
138+ $ fileinfo = $ this ->view ->getFileInfo ($ this ->filename );
139+ \OCP \Share::unshare ('file ' , $ fileinfo ['fileid ' ], \OCP \Share::SHARE_TYPE_GROUP ,
140+ \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_GROUP1 );
141+ }
142+
143+ function testCreateShareGroupFolder () {
144+ // simulate a post request
145+ $ _POST ['path ' ] = $ this ->folder ;
146+ $ _POST ['shareWith ' ] = \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_GROUP1 ;
147+ $ _POST ['shareType ' ] = \OCP \Share::SHARE_TYPE_GROUP ;
148+
149+ $ result = \OCA \Files_Sharing \API \Local::createShare ([]);
150+
151+ $ this ->assertTrue ($ result ->succeeded ());
152+ $ data = $ result ->getData ();
153+ $ this ->assertEquals (31 , $ data ['permissions ' ]);
154+ $ this ->assertEmpty ($ data ['expiration ' ]);
93155
156+ $ share = $ this ->getShareFromId ($ data ['id ' ]);
157+ $ items = \OCP \Share::getItemShared ('file ' , $ share ['item_source ' ]);
94158 $ this ->assertTrue (!empty ($ items ));
95159
96- // share link
160+ $ fileinfo = $ this ->view ->getFileInfo ($ this ->folder );
161+ \OCP \Share::unshare ('folder ' , $ fileinfo ['fileid ' ], \OCP \Share::SHARE_TYPE_GROUP ,
162+ \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_GROUP1 );
163+ }
97164
165+ public function testCreateShareLink () {
98166 // simulate a post request
99167 $ _POST ['path ' ] = $ this ->folder ;
100168 $ _POST ['shareType ' ] = \OCP \Share::SHARE_TYPE_LINK ;
101169
102- $ result = \OCA \Files_Sharing \API \Local::createShare (array () );
170+ $ result = \OCA \Files_Sharing \API \Local::createShare ([] );
103171
104172 // check if API call was successful
105173 $ this ->assertTrue ($ result ->succeeded ());
106174
107175 $ data = $ result ->getData ();
108-
109- // check if we have a token
176+ $ this -> assertEquals ( 1 , $ data [ ' permissions ' ]);
177+ $ this -> assertEmpty ( $ data [ ' expiration ' ]);
110178 $ this ->assertTrue (is_string ($ data ['token ' ]));
111179
112180 // check for correct link
@@ -115,18 +183,39 @@ function testCreateShare() {
115183
116184
117185 $ share = $ this ->getShareFromId ($ data ['id ' ]);
118-
119186 $ items = \OCP \Share::getItemShared ('file ' , $ share ['item_source ' ]);
120-
121187 $ this ->assertTrue (!empty ($ items ));
122188
123- $ fileinfo = $ this ->view ->getFileInfo ($ this ->filename );
189+ $ fileinfo = $ this ->view ->getFileInfo ($ this ->folder );
190+ \OCP \Share::unshare ('folder ' , $ fileinfo ['fileid ' ], \OCP \Share::SHARE_TYPE_LINK , null );
191+ }
124192
125- \OCP \Share::unshare ('file ' , $ fileinfo ['fileid ' ], \OCP \Share::SHARE_TYPE_USER ,
126- \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2 );
193+ public function testCreateShareLinkPublicUpload () {
194+ // simulate a post request
195+ $ _POST ['path ' ] = $ this ->folder ;
196+ $ _POST ['shareType ' ] = \OCP \Share::SHARE_TYPE_LINK ;
197+ $ _POST ['publicUpload ' ] = 'true ' ;
127198
128- $ fileinfo = $ this ->view ->getFileInfo ($ this ->folder );
199+ $ result = \OCA \Files_Sharing \API \Local::createShare (array ());
200+
201+ // check if API call was successful
202+ $ this ->assertTrue ($ result ->succeeded ());
203+
204+ $ data = $ result ->getData ();
205+ $ this ->assertEquals (7 , $ data ['permissions ' ]);
206+ $ this ->assertEmpty ($ data ['expiration ' ]);
207+ $ this ->assertTrue (is_string ($ data ['token ' ]));
129208
209+ // check for correct link
210+ $ url = \OC ::$ server ->getURLGenerator ()->getAbsoluteURL ('/index.php/s/ ' . $ data ['token ' ]);
211+ $ this ->assertEquals ($ url , $ data ['url ' ]);
212+
213+
214+ $ share = $ this ->getShareFromId ($ data ['id ' ]);
215+ $ items = \OCP \Share::getItemShared ('file ' , $ share ['item_source ' ]);
216+ $ this ->assertTrue (!empty ($ items ));
217+
218+ $ fileinfo = $ this ->view ->getFileInfo ($ this ->folder );
130219 \OCP \Share::unshare ('folder ' , $ fileinfo ['fileid ' ], \OCP \Share::SHARE_TYPE_LINK , null );
131220 }
132221
@@ -287,7 +376,7 @@ function testSharePermissions() {
287376
288377 /**
289378 * @medium
290- * @depends testCreateShare
379+ * @depends testCreateShareUserFile
291380 */
292381 function testGetAllShares () {
293382
@@ -334,7 +423,7 @@ function testGetAllSharesWithMe() {
334423
335424 /**
336425 * @medium
337- * @depends testCreateShare
426+ * @depends testCreateShareLink
338427 */
339428 function testPublicLinkUrl () {
340429 // simulate a post request
@@ -379,7 +468,8 @@ function testPublicLinkUrl() {
379468
380469 /**
381470 * @medium
382- * @depends testCreateShare
471+ * @depends testCreateShareUserFile
472+ * @depends testCreateShareLink
383473 */
384474 function testGetShareFromSource () {
385475
@@ -409,7 +499,8 @@ function testGetShareFromSource() {
409499
410500 /**
411501 * @medium
412- * @depends testCreateShare
502+ * @depends testCreateShareUserFile
503+ * @depends testCreateShareLink
413504 */
414505 function testGetShareFromSourceWithReshares () {
415506
@@ -463,7 +554,7 @@ function testGetShareFromSourceWithReshares() {
463554
464555 /**
465556 * @medium
466- * @depends testCreateShare
557+ * @depends testCreateShareUserFile
467558 */
468559 function testGetShareFromId () {
469560
@@ -911,7 +1002,8 @@ function testGetShareFromUnknownId() {
9111002
9121003 /**
9131004 * @medium
914- * @depends testCreateShare
1005+ * @depends testCreateShareUserFile
1006+ * @depends testCreateShareLink
9151007 */
9161008 function testUpdateShare () {
9171009
@@ -1037,7 +1129,7 @@ function testUpdateShare() {
10371129
10381130 /**
10391131 * @medium
1040- * @depends testCreateShare
1132+ * @depends testCreateShareUserFile
10411133 */
10421134 public function testUpdateShareInvalidPermissions () {
10431135
@@ -1232,7 +1324,7 @@ function testUpdateShareExpireDate() {
12321324
12331325 /**
12341326 * @medium
1235- * @depends testCreateShare
1327+ * @depends testCreateShareUserFile
12361328 */
12371329 function testDeleteShare () {
12381330
@@ -1526,6 +1618,7 @@ public function testPublicLinkExpireDate($date, $valid) {
15261618
15271619 $ data = $ result ->getData ();
15281620 $ this ->assertTrue (is_string ($ data ['token ' ]));
1621+ $ this ->assertEquals ($ date , substr ($ data ['expiration ' ], 0 , 10 ));
15291622
15301623 // check for correct link
15311624 $ url = \OC ::$ server ->getURLGenerator ()->getAbsoluteURL ('/index.php/s/ ' . $ data ['token ' ]);
@@ -1564,6 +1657,7 @@ public function testCreatePublicLinkExpireDateValid() {
15641657
15651658 $ data = $ result ->getData ();
15661659 $ this ->assertTrue (is_string ($ data ['token ' ]));
1660+ $ this ->assertEquals ($ date ->format ('Y-m-d ' ) . ' 00:00:00 ' , $ data ['expiration ' ]);
15671661
15681662 // check for correct link
15691663 $ url = \OC ::$ server ->getURLGenerator ()->getAbsoluteURL ('/index.php/s/ ' . $ data ['token ' ]);
0 commit comments