CountTest.php 5.7 KB

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