CountTest.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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-2010 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  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-2010 Zend Technologies USA Inc. (http://www.zend.com)
  39. * @license http://framework.zend.com/license/new-bsd New BSD License
  40. * @group Zend_Validate
  41. */
  42. class Zend_Validate_File_CountTest extends PHPUnit_Framework_TestCase
  43. {
  44. /**
  45. * Runs the test methods of this class.
  46. *
  47. * @return void
  48. */
  49. public static function main()
  50. {
  51. $suite = new PHPUnit_Framework_TestSuite("Zend_Validate_File_CountTest");
  52. $result = PHPUnit_TextUI_TestRunner::run($suite);
  53. }
  54. /**
  55. * Ensures that the validator follows expected behavior
  56. *
  57. * @return void
  58. */
  59. public function testBasic()
  60. {
  61. $valuesExpected = array(
  62. array(5, true, true, true, true),
  63. array(array('min' => 0, 'max' => 3), true, true, true, false),
  64. array(array('min' => 2, 'max' => 3), false, true, true, false),
  65. array(array('min' => 2), false, true, true, true),
  66. array(array('max' => 5), true, true, true, true),
  67. );
  68. foreach ($valuesExpected as $element) {
  69. $validator = new Zend_Validate_File_Count($element[0]);
  70. $this->assertEquals(
  71. $element[1],
  72. $validator->isValid(dirname(__FILE__) . '/_files/testsize.mo'),
  73. "Tested with " . var_export($element, 1)
  74. );
  75. $this->assertEquals(
  76. $element[2],
  77. $validator->isValid(dirname(__FILE__) . '/_files/testsize2.mo'),
  78. "Tested with " . var_export($element, 1)
  79. );
  80. $this->assertEquals(
  81. $element[3],
  82. $validator->isValid(dirname(__FILE__) . '/_files/testsize3.mo'),
  83. "Tested with " . var_export($element, 1)
  84. );
  85. $this->assertEquals(
  86. $element[4],
  87. $validator->isValid(dirname(__FILE__) . '/_files/testsize4.mo'),
  88. "Tested with " . var_export($element, 1)
  89. );
  90. }
  91. }
  92. /**
  93. * Ensures that getMin() returns expected value
  94. *
  95. * @return void
  96. */
  97. public function testGetMin()
  98. {
  99. $validator = new Zend_Validate_File_Count(array('min' => 1, 'max' => 5));
  100. $this->assertEquals(1, $validator->getMin());
  101. try {
  102. $validator = new Zend_Validate_File_Count(array('min' => 5, 'max' => 1));
  103. $this->fail("Missing exception");
  104. } catch (Zend_Validate_Exception $e) {
  105. $this->assertContains("greater than or equal", $e->getMessage());
  106. }
  107. $validator = new Zend_Validate_File_Count(array('min' => 1, 'max' => 5));
  108. $this->assertEquals(1, $validator->getMin());
  109. try {
  110. $validator = new Zend_Validate_File_Count(array('min' => 5, 'max' => 1));
  111. $this->fail("Missing exception");
  112. } catch (Zend_Validate_Exception $e) {
  113. $this->assertContains("greater than or equal", $e->getMessage());
  114. }
  115. }
  116. /**
  117. * Ensures that setMin() returns expected value
  118. *
  119. * @return void
  120. */
  121. public function testSetMin()
  122. {
  123. $validator = new Zend_Validate_File_Count(array('min' => 1000, 'max' => 10000));
  124. $validator->setMin(100);
  125. $this->assertEquals(100, $validator->getMin());
  126. try {
  127. $validator->setMin(20000);
  128. $this->fail("Missing exception");
  129. } catch (Zend_Validate_Exception $e) {
  130. $this->assertContains("less than or equal", $e->getMessage());
  131. }
  132. }
  133. /**
  134. * Ensures that getMax() returns expected value
  135. *
  136. * @return void
  137. */
  138. public function testGetMax()
  139. {
  140. $validator = new Zend_Validate_File_Count(array('min' => 1, 'max' => 100));
  141. $this->assertEquals(100, $validator->getMax());
  142. try {
  143. $validator = new Zend_Validate_File_Count(array('min' => 5, 'max' => 1));
  144. $this->fail("Missing exception");
  145. } catch (Zend_Validate_Exception $e) {
  146. $this->assertContains("greater than or equal", $e->getMessage());
  147. }
  148. }
  149. /**
  150. * Ensures that setMax() returns expected value
  151. *
  152. * @return void
  153. */
  154. public function testSetMax()
  155. {
  156. $validator = new Zend_Validate_File_Count(array('min' => 1000, 'max' => 10000));
  157. $validator->setMax(1000000);
  158. $this->assertEquals(1000000, $validator->getMax());
  159. $validator->setMin(100);
  160. $this->assertEquals(1000000, $validator->getMax());
  161. }
  162. }
  163. // Call Zend_Validate_File_CountTest::main() if this source file is executed directly.
  164. if (PHPUnit_MAIN_METHOD == "Zend_Validate_File_CountTest::main") {
  165. Zend_Validate_File_CountTest::main();
  166. }