WordCountTest.php 5.1 KB

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