2
0

WordCountTest.php 5.1 KB

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