PageRenderTime 25ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/DevApp/library/ServerLibraries/ZendFramework/1.7/tests/Zend/Validate/File/UploadTest.php

http://firephp.googlecode.com/
PHP | 264 lines | 182 code | 27 blank | 55 comment | 3 complexity | af8117b5452c42f8a84c9f770a04b88b MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, MIT, Apache-2.0
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Validate_File
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: UploadTest.php 12004 2008-10-18 14:29:41Z mikaelkael $
  21. */
  22. // Call Zend_Validate_File_UploadTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_Validate_File_UploadTest::main");
  25. }
  26. /**
  27. * Test helper
  28. */
  29. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  30. /**
  31. * @see Zend_Validate_File_Upload
  32. */
  33. require_once 'Zend/Validate/File/Upload.php';
  34. /**
  35. * @category Zend
  36. * @package Zend_Validate_File
  37. * @subpackage UnitTests
  38. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  39. * @license http://framework.zend.com/license/new-bsd New BSD License
  40. */
  41. class Zend_Validate_File_UploadTest extends PHPUnit_Framework_TestCase
  42. {
  43. /**
  44. * Runs the test methods of this class.
  45. *
  46. * @return void
  47. */
  48. public static function main()
  49. {
  50. $suite = new PHPUnit_Framework_TestSuite("Zend_Validate_File_UploadTest");
  51. $result = PHPUnit_TextUI_TestRunner::run($suite);
  52. }
  53. /**
  54. * Ensures that the validator follows expected behavior
  55. *
  56. * @return void
  57. */
  58. public function testBasic()
  59. {
  60. $_FILES = array(
  61. 'test' => array(
  62. 'name' => 'test1',
  63. 'type' => 'text',
  64. 'size' => 200,
  65. 'tmp_name' => 'tmp_test1',
  66. 'error' => 0),
  67. 'test2' => array(
  68. 'name' => 'test2',
  69. 'type' => 'text2',
  70. 'size' => 202,
  71. 'tmp_name' => 'tmp_test2',
  72. 'error' => 1),
  73. 'test3' => array(
  74. 'name' => 'test3',
  75. 'type' => 'text3',
  76. 'size' => 203,
  77. 'tmp_name' => 'tmp_test3',
  78. 'error' => 2),
  79. 'test4' => array(
  80. 'name' => 'test4',
  81. 'type' => 'text4',
  82. 'size' => 204,
  83. 'tmp_name' => 'tmp_test4',
  84. 'error' => 3),
  85. 'test5' => array(
  86. 'name' => 'test5',
  87. 'type' => 'text5',
  88. 'size' => 205,
  89. 'tmp_name' => 'tmp_test5',
  90. 'error' => 4),
  91. 'test6' => array(
  92. 'name' => 'test6',
  93. 'type' => 'text6',
  94. 'size' => 206,
  95. 'tmp_name' => 'tmp_test6',
  96. 'error' => 5),
  97. 'test7' => array(
  98. 'name' => 'test7',
  99. 'type' => 'text7',
  100. 'size' => 207,
  101. 'tmp_name' => 'tmp_test7',
  102. 'error' => 6),
  103. 'test8' => array(
  104. 'name' => 'test8',
  105. 'type' => 'text8',
  106. 'size' => 208,
  107. 'tmp_name' => 'tmp_test8',
  108. 'error' => 7),
  109. 'test9' => array(
  110. 'name' => 'test9',
  111. 'type' => 'text9',
  112. 'size' => 209,
  113. 'tmp_name' => 'tmp_test9',
  114. 'error' => 8)
  115. );
  116. $validator = new Zend_Validate_File_Upload();
  117. $this->assertFalse($validator->isValid('test'));
  118. $this->assertTrue(array_key_exists('fileUploadErrorAttack', $validator->getMessages()));
  119. $validator = new Zend_Validate_File_Upload();
  120. $this->assertFalse($validator->isValid('test2'));
  121. $this->assertTrue(array_key_exists('fileUploadErrorIniSize', $validator->getMessages()));
  122. $validator = new Zend_Validate_File_Upload();
  123. $this->assertFalse($validator->isValid('test3'));
  124. $this->assertTrue(array_key_exists('fileUploadErrorFormSize', $validator->getMessages()));
  125. $validator = new Zend_Validate_File_Upload();
  126. $this->assertFalse($validator->isValid('test4'));
  127. $this->assertTrue(array_key_exists('fileUploadErrorPartial', $validator->getMessages()));
  128. $validator = new Zend_Validate_File_Upload();
  129. $this->assertFalse($validator->isValid('test5'));
  130. $this->assertTrue(array_key_exists('fileUploadErrorNoFile', $validator->getMessages()));
  131. $validator = new Zend_Validate_File_Upload();
  132. $this->assertFalse($validator->isValid('test6'));
  133. $this->assertTrue(array_key_exists('fileUploadErrorUnknown', $validator->getMessages()));
  134. $validator = new Zend_Validate_File_Upload();
  135. $this->assertFalse($validator->isValid('test7'));
  136. $this->assertTrue(array_key_exists('fileUploadErrorNoTmpDir', $validator->getMessages()));
  137. $validator = new Zend_Validate_File_Upload();
  138. $this->assertFalse($validator->isValid('test8'));
  139. $this->assertTrue(array_key_exists('fileUploadErrorCantWrite', $validator->getMessages()));
  140. $validator = new Zend_Validate_File_Upload();
  141. $this->assertFalse($validator->isValid('test9'));
  142. $this->assertTrue(array_key_exists('fileUploadErrorExtension', $validator->getMessages()));
  143. $validator = new Zend_Validate_File_Upload();
  144. $this->assertFalse($validator->isValid('test1'));
  145. $this->assertTrue(array_key_exists('fileUploadErrorAttack', $validator->getMessages()));
  146. $validator = new Zend_Validate_File_Upload();
  147. $this->assertFalse($validator->isValid('tmp_test1'));
  148. $this->assertTrue(array_key_exists('fileUploadErrorAttack', $validator->getMessages()));
  149. $validator = new Zend_Validate_File_Upload();
  150. $this->assertFalse($validator->isValid('test000'));
  151. $this->assertTrue(array_key_exists('fileUploadErrorFileNotFound', $validator->getMessages()));
  152. }
  153. /**
  154. * Ensures that getFiles() returns expected value
  155. *
  156. * @return void
  157. */
  158. public function testGetFiles()
  159. {
  160. $_FILES = array(
  161. 'test' => array(
  162. 'name' => 'test1',
  163. 'type' => 'text',
  164. 'size' => 200,
  165. 'tmp_name' => 'tmp_test1',
  166. 'error' => 0),
  167. 'test2' => array(
  168. 'name' => 'test3',
  169. 'type' => 'text2',
  170. 'size' => 202,
  171. 'tmp_name' => 'tmp_test2',
  172. 'error' => 1));
  173. $files = array(
  174. 'test' => array(
  175. 'name' => 'test1',
  176. 'type' => 'text',
  177. 'size' => 200,
  178. 'tmp_name' => 'tmp_test1',
  179. 'error' => 0));
  180. $files1 = array(
  181. 'test2' => array(
  182. 'name' => 'test3',
  183. 'type' => 'text2',
  184. 'size' => 202,
  185. 'tmp_name' => 'tmp_test2',
  186. 'error' => 1));
  187. $validator = new Zend_Validate_File_Upload();
  188. $this->assertEquals($files, $validator->getFiles('test'));
  189. $this->assertEquals($files, $validator->getFiles('test1'));
  190. $this->assertEquals($files1, $validator->getFiles('test3'));
  191. try {
  192. $this->assertEquals(array(), $validator->getFiles('test5'));
  193. $this->fail("Missing exception");
  194. } catch (Zend_Validate_Exception $e) {
  195. $this->assertContains("was not found", $e->getMessage());
  196. }
  197. }
  198. /**
  199. * Ensures that setFiles() returns expected value
  200. *
  201. * @return void
  202. */
  203. public function testSetFiles()
  204. {
  205. $files = array(
  206. 'test' => array(
  207. 'name' => 'test1',
  208. 'type' => 'text',
  209. 'size' => 200,
  210. 'tmp_name' => 'tmp_test1',
  211. 'error' => 0),
  212. 'test2' => array(
  213. 'name' => 'test2',
  214. 'type' => 'text2',
  215. 'size' => 202,
  216. 'tmp_name' => 'tmp_test2',
  217. 'error' => 1));
  218. $_FILES = array(
  219. 'test' => array(
  220. 'name' => 'test3',
  221. 'type' => 'text3',
  222. 'size' => 203,
  223. 'tmp_name' => 'tmp_test3',
  224. 'error' => 2));
  225. $validator = new Zend_Validate_File_Upload();
  226. $validator->setFiles(array());
  227. $this->assertEquals($_FILES, $validator->getFiles());
  228. $validator->setFiles();
  229. $this->assertEquals($_FILES, $validator->getFiles());
  230. $validator->setFiles($files);
  231. $this->assertEquals($files, $validator->getFiles());
  232. }
  233. }
  234. // Call Zend_Validate_File_UploadTest::main() if this source file is executed directly.
  235. if (PHPUnit_MAIN_METHOD == "Zend_Validate_File_UploadTest::main") {
  236. Zend_Validate_File_UploadTest::main();
  237. }