PageRenderTime 43ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/lib/Tests/Zikula/FileSystem/FileSystem_FtpTest.php

https://github.com/ThiloWitt/core
PHP | 436 lines | 303 code | 61 blank | 72 comment | 0 complexity | adff8e8927830a90c4fff58803bd5774 MD5 | raw file
  1. <?php
  2. require_once dirname(__FILE__) . '/../../../../bootstrap.php';
  3. // exclude the following file from code coverage reports.
  4. PHP_CodeCoverage_Filter::getInstance()->addFileToBlacklist(dirname(__FILE__). '/../../../../../src/lib/Zikula/FileSystem/Facade/Ftp.php');
  5. /**
  6. * Zikula_FileSystem_Ftp test case.
  7. */
  8. class Zikula_FileSystem_FtpTest extends PHPUnit_Framework_TestCase
  9. {
  10. /**
  11. * @var Zikula_FileSystem_Ftp
  12. */
  13. private $Zikula_FileSystem_Ftp;
  14. /**
  15. * Prepares the environment before running a test.
  16. */
  17. protected function setUp()
  18. {
  19. parent::setUp();
  20. $config = new Zikula_FileSystem_Configuration_Ftp();
  21. $this->Zikula_FileSystem_Ftp = new Zikula_FileSystem_Ftp($config);
  22. }
  23. /**
  24. * Cleans up the environment after running a test.
  25. */
  26. protected function tearDown()
  27. {
  28. $this->Zikula_FileSystem_Ftp = null;
  29. parent::tearDown();
  30. }
  31. /**
  32. * Tests Zikula_FileSystem_Ftp->connect()
  33. */
  34. public function testConnect()
  35. {
  36. $config = new Zikula_FileSystem_Configuration_Ftp(1,2,3,4,5,6,true);
  37. $fs = new Zikula_FileSystem_Ftp($config);
  38. $stub = $this->getMock('Zikula_FileSystem_Facade_Ftp');
  39. $stub->expects($this->any())
  40. ->method('ssl_connect')
  41. ->will($this->returnValue(true));
  42. $stub->expects($this->any())
  43. ->method('login')
  44. ->will($this->returnValue(true));
  45. $stub->expects($this->any())
  46. ->method('pasv')
  47. ->will($this->returnValue(true));
  48. $stub->expects($this->any())
  49. ->method('chdir')
  50. ->will($this->returnValue(true));
  51. $fs->setDriver($stub);
  52. $this->assertEquals(true, $fs->connect());
  53. $config = new Zikula_FileSystem_Configuration_Ftp();
  54. $fs = new Zikula_FileSystem_Ftp($config);
  55. $stub = $this->getMock('Zikula_FileSystem_Facade_Ftp');
  56. $stub->expects($this->any())
  57. ->method('connect')
  58. ->will($this->returnValue(true));
  59. $stub->expects($this->any())
  60. ->method('login')
  61. ->will($this->returnValue(true));
  62. $stub->expects($this->any())
  63. ->method('pasv')
  64. ->will($this->returnValue(true));
  65. $stub->expects($this->any())
  66. ->method('chdir')
  67. ->will($this->returnValue(true));
  68. $fs->setDriver($stub);
  69. $this->assertEquals(true, $fs->connect());
  70. $config = new Zikula_FileSystem_Configuration_Ftp();
  71. $fs = new Zikula_FileSystem_Ftp($config);
  72. $stub = $this->getMock('Zikula_FileSystem_Facade_Ftp');
  73. $stub->expects($this->any())
  74. ->method('connect')
  75. ->will($this->returnValue(false));
  76. $stub->expects($this->any())
  77. ->method('login')
  78. ->will($this->returnValue(true));
  79. $stub->expects($this->any())
  80. ->method('pasv')
  81. ->will($this->returnValue(true));
  82. $stub->expects($this->any())
  83. ->method('chdir')
  84. ->will($this->returnValue(true));
  85. $fs->setDriver($stub);
  86. $this->assertEquals(false, $fs->connect());
  87. $config = new Zikula_FileSystem_Configuration_Ftp();
  88. $fs = new Zikula_FileSystem_Ftp($config);
  89. $stub = $this->getMock('Zikula_FileSystem_Facade_Ftp');
  90. $stub->expects($this->any())
  91. ->method('connect')
  92. ->will($this->returnValue(true));
  93. $stub->expects($this->any())
  94. ->method('login')
  95. ->will($this->returnValue(false));
  96. $stub->expects($this->any())
  97. ->method('pasv')
  98. ->will($this->returnValue(true));
  99. $stub->expects($this->any())
  100. ->method('chdir')
  101. ->will($this->returnValue(true));
  102. $fs->setDriver($stub);
  103. $this->assertEquals(false, $fs->connect());
  104. $config = new Zikula_FileSystem_Configuration_Ftp();
  105. $fs = new Zikula_FileSystem_Ftp($config);
  106. $stub = $this->getMock('Zikula_FileSystem_Facade_Ftp');
  107. $stub->expects($this->any())
  108. ->method('connect')
  109. ->will($this->returnValue(true));
  110. $stub->expects($this->any())
  111. ->method('login')
  112. ->will($this->returnValue(true));
  113. $stub->expects($this->any())
  114. ->method('pasv')
  115. ->will($this->returnValue(false));
  116. $stub->expects($this->any())
  117. ->method('chdir')
  118. ->will($this->returnValue(true));
  119. $fs->setDriver($stub);
  120. $this->assertEquals(false, $fs->connect());
  121. $config = new Zikula_FileSystem_Configuration_Ftp();
  122. $fs = new Zikula_FileSystem_Ftp($config);
  123. $stub = $this->getMock('Zikula_FileSystem_Facade_Ftp');
  124. $stub->expects($this->any())
  125. ->method('connect')
  126. ->will($this->returnValue(true));
  127. $stub->expects($this->any())
  128. ->method('login')
  129. ->will($this->returnValue(true));
  130. $stub->expects($this->any())
  131. ->method('pasv')
  132. ->will($this->returnValue(true));
  133. $stub->expects($this->any())
  134. ->method('chdir')
  135. ->will($this->returnValue(false));
  136. $fs->setDriver($stub);
  137. $this->assertEquals(false, $fs->connect());
  138. }
  139. /**
  140. * Tests Zikula_FileSystem_Ftp->put()
  141. */
  142. public function testPut()
  143. {
  144. // Configure the stub.
  145. $stub = $this->getMock('Zikula_FileSystem_Facade_Ftp');
  146. $stub->expects($this->any())
  147. ->method('put')
  148. ->will($this->returnValue(true));
  149. $this->Zikula_FileSystem_Ftp->setDriver($stub);
  150. $this->assertEquals(true, $this->Zikula_FileSystem_Ftp->put(1,2));
  151. // Configure the stub.
  152. $stub = $this->getMock('Zikula_FileSystem_Facade_Ftp');
  153. $stub->expects($this->any())
  154. ->method('put')
  155. ->will($this->returnValue(false));
  156. $this->Zikula_FileSystem_Ftp->setDriver($stub);
  157. $this->assertEquals(false, $this->Zikula_FileSystem_Ftp->put(1,2));
  158. }
  159. /**
  160. * Tests Zikula_FileSystem_Ftp->fput()
  161. */
  162. public function testFput()
  163. {
  164. /// Configure the stub.
  165. $stub = $this->getMock('Zikula_FileSystem_Facade_Ftp');
  166. $stub->expects($this->any())
  167. ->method('fput')
  168. ->will($this->returnValue(true));
  169. $this->Zikula_FileSystem_Ftp->setDriver($stub);
  170. $this->assertEquals(true, $this->Zikula_FileSystem_Ftp->fput(1,2));
  171. // Configure the stub.
  172. $stub = $this->getMock('Zikula_FileSystem_Facade_Ftp');
  173. $stub->expects($this->any())
  174. ->method('fput')
  175. ->will($this->returnValue(false));
  176. $this->Zikula_FileSystem_Ftp->setDriver($stub);
  177. $this->assertEquals(false, $this->Zikula_FileSystem_Ftp->fput(1,2));
  178. }
  179. /**
  180. * Tests Zikula_FileSystem_Ftp->get()
  181. */
  182. public function testGet()
  183. {
  184. // Configure the stub.
  185. $stub = $this->getMock('Zikula_FileSystem_Facade_Ftp');
  186. $stub->expects($this->any())
  187. ->method('get')
  188. ->will($this->returnValue(true));
  189. $this->Zikula_FileSystem_Ftp->setDriver($stub);
  190. $this->assertEquals(true, $this->Zikula_FileSystem_Ftp->get(1,2));
  191. // Configure the stub.
  192. $stub = $this->getMock('Zikula_FileSystem_Facade_Ftp');
  193. $stub->expects($this->any())
  194. ->method('get')
  195. ->will($this->returnValue(false));
  196. $this->Zikula_FileSystem_Ftp->setDriver($stub);
  197. $this->assertEquals(false, $this->Zikula_FileSystem_Ftp->get(1,2));
  198. }
  199. /**
  200. * Tests Zikula_FileSystem_Ftp->fget()
  201. */
  202. public function testFget()
  203. {
  204. // Configure the stub.
  205. $stub = $this->getMock('Zikula_FileSystem_Facade_Ftp');
  206. $stub->expects($this->any())
  207. ->method('fget')
  208. ->will($this->returnValue(true));
  209. $this->Zikula_FileSystem_Ftp->setDriver($stub);
  210. $this->assertInternalType('resource', $this->Zikula_FileSystem_Ftp->fget(1));
  211. // Configure the stub.
  212. $stub = $this->getMock('Zikula_FileSystem_Facade_Ftp');
  213. $stub->expects($this->any())
  214. ->method('fget')
  215. ->will($this->returnValue(false));
  216. $this->Zikula_FileSystem_Ftp->setDriver($stub);
  217. $this->assertEquals(false, $this->Zikula_FileSystem_Ftp->fget(1));
  218. }
  219. /**
  220. * Tests Zikula_FileSystem_Ftp->chmod()
  221. */
  222. public function testChmod()
  223. {
  224. // Configure the stub.
  225. $perm = '777';
  226. $stub = $this->getMock('Zikula_FileSystem_Facade_Ftp');
  227. $stub->expects($this->any())
  228. ->method('chmod')
  229. ->will($this->returnValue((int)octdec(str_pad($perm, 4, '0', STR_PAD_LEFT))));
  230. $this->Zikula_FileSystem_Ftp->setDriver($stub);
  231. $this->assertEquals($perm, $this->Zikula_FileSystem_Ftp->chmod($perm,2));
  232. // Configure the stub.
  233. $stub = $this->getMock('Zikula_FileSystem_Facade_Ftp');
  234. $stub->expects($this->any())
  235. ->method('chmod')
  236. ->will($this->returnValue(false));
  237. $this->Zikula_FileSystem_Ftp->setDriver($stub);
  238. $this->assertEquals(false, $this->Zikula_FileSystem_Ftp->chmod(1,2));
  239. }
  240. /**
  241. * Tests Zikula_FileSystem_Ftp->ls()
  242. */
  243. public function testLs()
  244. {
  245. $array = array('1','2');
  246. // Configure the stub.
  247. $stub = $this->getMock('Zikula_FileSystem_Facade_Ftp');
  248. $stub->expects($this->any())
  249. ->method('nlist')
  250. ->will($this->returnValue($array));
  251. $this->Zikula_FileSystem_Ftp->setDriver($stub);
  252. $this->assertInternalType('array', $this->Zikula_FileSystem_Ftp->ls(1,2));
  253. // Configure the stub.
  254. $stub = $this->getMock('Zikula_FileSystem_Facade_Ftp');
  255. $stub->expects($this->any())
  256. ->method('nlist')
  257. ->will($this->returnValue(false));
  258. $this->Zikula_FileSystem_Ftp->setDriver($stub);
  259. $this->assertEquals(false, $this->Zikula_FileSystem_Ftp->ls(1,2));
  260. }
  261. /**
  262. * Tests Zikula_FileSystem_Ftp->cd()
  263. */
  264. public function testCd()
  265. {
  266. // Configure the stub.
  267. $stub = $this->getMock('Zikula_FileSystem_Facade_Ftp');
  268. $stub->expects($this->any())
  269. ->method('chdir')
  270. ->will($this->returnValue(true));
  271. $this->Zikula_FileSystem_Ftp->setDriver($stub);
  272. $this->assertEquals(true, $this->Zikula_FileSystem_Ftp->cd(1,2));
  273. // Configure the stub.
  274. $stub = $this->getMock('Zikula_FileSystem_Facade_Ftp');
  275. $stub->expects($this->any())
  276. ->method('chdir')
  277. ->will($this->returnValue(false));
  278. $this->Zikula_FileSystem_Ftp->setDriver($stub);
  279. $this->assertEquals(false, $this->Zikula_FileSystem_Ftp->cd(1,2));
  280. }
  281. /**
  282. * Tests Zikula_FileSystem_Ftp->mv()
  283. */
  284. public function testMv()
  285. {
  286. // Configure the stub.
  287. $stub = $this->getMock('Zikula_FileSystem_Facade_Ftp');
  288. $stub->expects($this->any())
  289. ->method('rename')
  290. ->will($this->returnValue(true));
  291. $this->Zikula_FileSystem_Ftp->setDriver($stub);
  292. $this->assertEquals(true, $this->Zikula_FileSystem_Ftp->mv(1,2));
  293. // Configure the stub.
  294. $stub = $this->getMock('Zikula_FileSystem_Facade_Ftp');
  295. $stub->expects($this->any())
  296. ->method('rename')
  297. ->will($this->returnValue(false));
  298. $this->Zikula_FileSystem_Ftp->setDriver($stub);
  299. $this->assertEquals(false, $this->Zikula_FileSystem_Ftp->mv(1,2));
  300. }
  301. /**
  302. * Tests Zikula_FileSystem_Ftp->cp()
  303. */
  304. public function testCp()
  305. {
  306. // Configure the stub.
  307. $handle = fopen('php://temp', 'r+');
  308. $stub = $this->getMock('Zikula_FileSystem_Facade_Ftp');
  309. $stub->expects($this->any())
  310. ->method('fget')
  311. ->will($this->returnValue($handle));
  312. $stub->expects($this->any())
  313. ->method('fput')
  314. ->will($this->returnValue(true));
  315. $this->Zikula_FileSystem_Ftp->setDriver($stub);
  316. $this->assertEquals(true, $this->Zikula_FileSystem_Ftp->cp(1,2));
  317. // Configure the stub.
  318. $stub = $this->getMock('Zikula_FileSystem_Facade_Ftp');
  319. $stub->expects($this->any())
  320. ->method('fget')
  321. ->will($this->returnValue(false));
  322. $this->Zikula_FileSystem_Ftp->setDriver($stub);
  323. $this->assertEquals(false, $this->Zikula_FileSystem_Ftp->cp(1,2));
  324. // Configure the stub.
  325. $stub = $this->getMock('Zikula_FileSystem_Facade_Ftp');
  326. $stub->expects($this->any())
  327. ->method('fget')
  328. ->will($this->returnValue($handle));
  329. $stub->expects($this->any())
  330. ->method('fput')
  331. ->will($this->returnValue(false));
  332. $this->Zikula_FileSystem_Ftp->setDriver($stub);
  333. $this->assertEquals(false, $this->Zikula_FileSystem_Ftp->cp(1,2));
  334. }
  335. /**
  336. * Tests Zikula_FileSystem_Ftp->rm()
  337. */
  338. public function testRm()
  339. {
  340. // Configure the stub.
  341. $stub = $this->getMock('Zikula_FileSystem_Facade_Ftp');
  342. $stub->expects($this->any())
  343. ->method('delete')
  344. ->will($this->returnValue(true));
  345. $this->Zikula_FileSystem_Ftp->setDriver($stub);
  346. $this->assertEquals(true, $this->Zikula_FileSystem_Ftp->rm(1,2));
  347. // Configure the stub.
  348. $stub = $this->getMock('Zikula_FileSystem_Facade_Ftp');
  349. $stub->expects($this->any())
  350. ->method('delete')
  351. ->will($this->returnValue(false));
  352. $this->Zikula_FileSystem_Ftp->setDriver($stub);
  353. $this->assertEquals(false, $this->Zikula_FileSystem_Ftp->rm(1,2));
  354. }
  355. /**
  356. * Tests Zikula_FileSystem_Ftp->isAlive()
  357. */
  358. public function testIsAlive()
  359. {
  360. // Configure the stub.
  361. $stub = $this->getMock('Zikula_FileSystem_Facade_Ftp');
  362. $stub->expects($this->any())
  363. ->method('systype')
  364. ->will($this->returnValue(true));
  365. $this->Zikula_FileSystem_Ftp->setDriver($stub);
  366. $this->assertEquals(true, $this->Zikula_FileSystem_Ftp->isAlive());
  367. // Configure the stub.
  368. $stub = $this->getMock('Zikula_FileSystem_Facade_Ftp');
  369. $stub->expects($this->any())
  370. ->method('systype')
  371. ->will($this->returnValue(false));
  372. $this->Zikula_FileSystem_Ftp->setDriver($stub);
  373. $this->assertEquals(false, $this->Zikula_FileSystem_Ftp->isAlive());
  374. }
  375. }