11<?php 
22/** 
3- * ownCloud 
4- * 
5- * @author Robin Appelman 
6- * @copyright 2012 Robin Appelman icewind@owncloud.com 
7- * 
8- * This library is free software; you can redistribute it and/or 
9- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE 
10- * License as published by the Free Software Foundation; either 
11- * version 3 of the License, or any later version. 
12- * 
13- * This library is distributed in the hope that it will be useful, 
14- * but WITHOUT ANY WARRANTY; without even the implied warranty of 
15- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
16- * GNU AFFERO GENERAL PUBLIC LICENSE for more details. 
17- * 
18- * You should have received a copy of the GNU Affero General Public 
19- * License along with this library.  If not, see <http://www.gnu.org/licenses/>. 
20- * 
21- */ 
3+   * ownCloud
4+   *
5+   * @author Robin Appelman
6+   * @copyright 2012 Robin Appelman icewind@owncloud.com
7+   *
8+   * This library is free software; you can redistribute it and/or
9+   * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
10+   * License as published by the Free Software Foundation; either
11+   * version 3 of the License, or any later version.
12+   *
13+   * This library is distributed in the hope that it will be useful,
14+   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15+   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16+   * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
17+   *
18+   * You should have received a copy of the GNU Affero General Public
19+   * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
20+   *
21+   */
2222
2323namespace  Test \Files \Storage ;
2424
25+ use  OC \Files \Storage \Wrapper \Jail ;
26+ use  OC \Files \Storage \Wrapper \Wrapper ;
27+ use  PHPUnit \Framework \MockObject \MockObject ;
28+ 
2529/** 
2630 * Class CommonTest 
2731 * 
@@ -34,15 +38,88 @@ class CommonTest extends Storage {
3438	 * @var string tmpDir 
3539	 */ 
3640	private  $ tmpDir
41+ 
3742	protected  function  setUp () {
3843		parent ::setUp ();
3944
4045		$ this tmpDir  = \OC ::$ servergetTempManager ()->getTemporaryFolder ();
41- 		$ this instance = new  \OC \Files \Storage \CommonTest (array ( 'datadir ' => $ this tmpDir ) );
46+ 		$ this instance  =  new  \OC \Files \Storage \CommonTest ([ 'datadir '  =>  $ this tmpDir ] );
4247	}
4348
4449	protected  function  tearDown () {
4550		\OC_Helper::rmdirr ($ this tmpDir );
4651		parent ::tearDown ();
4752	}
53+ 
54+ 	public  function  testMoveFromStorageWrapped () {
55+ 		/** @var \OC\Files\Storage\CommonTest|MockObject $instance */ 
56+ 		$ instance$ this getMockBuilder (\OC \Files \Storage \CommonTest::class)
57+ 			->setMethods (['copyFromStorage ' , 'rmdir ' , 'unlink ' ])
58+ 			->setConstructorArgs ([['datadir '  => $ this tmpDir ]])
59+ 			->getMock ();
60+ 		$ instancemethod ('copyFromStorage ' )
61+ 			->willThrowException (new  \Exception ('copy ' ));
62+ 
63+ 		$ sourcenew  Wrapper ([
64+ 			'storage '  => $ instance
65+ 		]);
66+ 
67+ 		$ instancefile_put_contents ('foo.txt ' , 'bar ' );
68+ 		$ instancemoveFromStorage ($ source'foo.txt ' , 'bar.txt ' );
69+ 		$ this assertTrue ($ instancefile_exists ('bar.txt ' ));
70+ 	}
71+ 
72+ 	public  function  testMoveFromStorageJailed () {
73+ 		/** @var \OC\Files\Storage\CommonTest|MockObject $instance */ 
74+ 		$ instance$ this getMockBuilder (\OC \Files \Storage \CommonTest::class)
75+ 			->setMethods (['copyFromStorage ' , 'rmdir ' , 'unlink ' ])
76+ 			->setConstructorArgs ([['datadir '  => $ this tmpDir ]])
77+ 			->getMock ();
78+ 		$ instancemethod ('copyFromStorage ' )
79+ 			->willThrowException (new  \Exception ('copy ' ));
80+ 
81+ 		$ sourcenew  Jail ([
82+ 			'storage '  => $ instance
83+ 			'root '  => 'foo ' 
84+ 		]);
85+ 		$ sourcenew  Wrapper ([
86+ 			'storage '  => $ source
87+ 		]);
88+ 
89+ 		$ instancemkdir ('foo ' );
90+ 		$ instancefile_put_contents ('foo/foo.txt ' , 'bar ' );
91+ 		$ instancemoveFromStorage ($ source'foo.txt ' , 'bar.txt ' );
92+ 		$ this assertTrue ($ instancefile_exists ('bar.txt ' ));
93+ 	}
94+ 
95+ 	public  function  testMoveFromStorageNestedJail () {
96+ 		/** @var \OC\Files\Storage\CommonTest|MockObject $instance */ 
97+ 		$ instance$ this getMockBuilder (\OC \Files \Storage \CommonTest::class)
98+ 			->setMethods (['copyFromStorage ' , 'rmdir ' , 'unlink ' ])
99+ 			->setConstructorArgs ([['datadir '  => $ this tmpDir ]])
100+ 			->getMock ();
101+ 		$ instancemethod ('copyFromStorage ' )
102+ 			->willThrowException (new  \Exception ('copy ' ));
103+ 
104+ 		$ sourcenew  Jail ([
105+ 			'storage '  => $ instance
106+ 			'root '  => 'foo ' 
107+ 		]);
108+ 		$ sourcenew  Wrapper ([
109+ 			'storage '  => $ source
110+ 		]);
111+ 		$ sourcenew  Jail ([
112+ 			'storage '  => $ source
113+ 			'root '  => 'bar ' 
114+ 		]);
115+ 		$ sourcenew  Wrapper ([
116+ 			'storage '  => $ source
117+ 		]);
118+ 
119+ 		$ instancemkdir ('foo ' );
120+ 		$ instancemkdir ('foo/bar ' );
121+ 		$ instancefile_put_contents ('foo/bar/foo.txt ' , 'bar ' );
122+ 		$ instancemoveFromStorage ($ source'foo.txt ' , 'bar.txt ' );
123+ 		$ this assertTrue ($ instancefile_exists ('bar.txt ' ));
124+ 	}
48125}
0 commit comments