CountTest.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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: CountTest.php 12004 2008-10-18 14:29:41Z mikaelkael $
  21. */
  22. // Call Zend_Validate_File_CountTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_Validate_File_CountTest::main");
  25. }
  26. /**
  27. * Test helper
  28. */
  29. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  30. /**
  31. * @see Zend_Validate_File_Count
  32. */
  33. require_once 'Zend/Validate/File/Count.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_CountTest 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_CountTest");
  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. $valuesExpected = array(
  61. array(5, true, true, true, true),
  62. array(array('min' => 0, 'max' => 3), true, true, true, false),
  63. array(array('min' => 2, 'max' => 3), false, true, true, false),
  64. array(array('min' => 2), false, true, true, true),
  65. array(array('max' => 5), true, true, true, true),
  66. );
  67. foreach ($valuesExpected as $element) {
  68. $validator = new Zend_Validate_File_Count($element[0]);
  69. $this->assertEquals(
  70. $element[1],
  71. $validator->isValid(dirname(__FILE__) . '/_files/testsize.mo'),
  72. "Tested with " . var_export($element, 1)
  73. );
  74. $this->assertEquals(
  75. $element[2],
  76. $validator->isValid(dirname(__FILE__) . '/_files/testsize2.mo'),
  77. "Tested with " . var_export($element, 1)
  78. );
  79. $this->assertEquals(
  80. $element[3],
  81. $validator->isValid(dirname(__FILE__) . '/_files/testsize3.mo'),
  82. "Tested with " . var_export($element, 1)
  83. );
  84. $this->assertEquals(
  85. $element[4],
  86. $validator->isValid(dirname(__FILE__) . '/_files/testsize4.mo'),
  87. "Tested with " . var_export($element, 1)
  88. );
  89. }
  90. }
  91. /**
  92. * Ensures that getMin() returns expected value
  93. *
  94. * @return void
  95. */
  96. public function testGetMin()
  97. {
  98. $validator = new Zend_Validate_File_Count(array('min' => 1, 'max' => 5));
  99. $this->assertEquals(1, $validator->getMin());
  100. try {
  101. $validator = new Zend_Validate_File_Count(array('min' => 5, 'max' => 1));
  102. $this->fail("Missing exception");
  103. } catch (Zend_Validate_Exception $e) {
  104. $this->assertContains("greater than or equal", $e->getMessage());
  105. }
  106. $validator = new Zend_Validate_File_Count(array('min' => 1, 'max' => 5));
  107. $this->assertEquals(1, $validator->getMin());
  108. try {
  109. $validator = new Zend_Validate_File_Count(array('min' => 5, 'max' => 1));
  110. $this->fail("Missing exception");
  111. } catch (Zend_Validate_Exception $e) {
  112. $this->assertContains("greater than or equal", $e->getMessage());
  113. }
  114. }
  115. /**
  116. * Ensures that setMin() returns expected value
  117. *
  118. * @return void
  119. */
  120. public function testSetMin()
  121. {
  122. $validator = new Zend_Validate_File_Count(array('min' => 1000, 'max' => 10000));
  123. $validator->setMin(100);
  124. $this->assertEquals(100, $validator->getMin());
  125. try {
  126. $validator->setMin(20000);
  127. $this->fail("Missing exception");
  128. } catch (Zend_Validate_Exception $e) {
  129. $this->assertContains("less than or equal", $e->getMessage());
  130. }
  131. }
  132. /**
  133. * Ensures that getMax() returns expected value
  134. *
  135. * @return void
  136. */
  137. public function testGetMax()
  138. {
  139. $validator = new Zend_Validate_File_Count(array('min' => 1, 'max' => 100));
  140. $this->assertEquals(100, $validator->getMax());
  141. try {
  142. $validator = new Zend_Validate_File_Count(array('min' => 5, 'max' => 1));
  143. $this->fail("Missing exception");
  144. } catch (Zend_Validate_Exception $e) {
  145. $this->assertContains("greater than or equal", $e->getMessage());
  146. }
  147. }
  148. /**
  149. * Ensures that setMax() returns expected value
  150. *
  151. * @return void
  152. */
  153. public function testSetMax()
  154. {
  155. $validator = new Zend_Validate_File_Count(array('min' => 1000, 'max' => 10000));
  156. $validator->setMax(1000000);
  157. $this->assertEquals(1000000, $validator->getMax());
  158. $validator->setMin(100);
  159. $this->assertEquals(1000000, $validator->getMax());
  160. }
  161. }
  162. // Call Zend_Validate_File_CountTest::main() if this source file is executed directly.
  163. if (PHPUnit_MAIN_METHOD == "Zend_Validate_File_CountTest::main") {
  164. Zend_Validate_File_CountTest::main();
  165. }