/ZendFramework/tests/Zend/Validate/File/WordCountTest.php

https://bitbucket.org/Dal-Papa/is-340-publish-base · PHP · 162 lines · 83 code · 16 blank · 63 comment · 3 complexity · b3686a84e71aeeae52c9d78611b457f4 MD5 · raw file

  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-2012 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: WordCountTest.php 24593 2012-01-05 20:35:02Z 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. * @see Zend_Validate_File_WordCount
  28. */
  29. require_once 'Zend/Validate/File/WordCount.php';
  30. /**
  31. * @category Zend
  32. * @package Zend_Validate_File
  33. * @subpackage UnitTests
  34. * @copyright Copyright (c) 2005-2012 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_WordCountTest 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_WordCountTest");
  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(15, true),
  59. array(4, false),
  60. array(array('min' => 0, 'max' => 10), true),
  61. array(array('min' => 10, 'max' => 15), false),
  62. );
  63. foreach ($valuesExpected as $element) {
  64. $validator = new Zend_Validate_File_WordCount($element[0]);
  65. $this->assertEquals(
  66. $element[1],
  67. $validator->isValid(dirname(__FILE__) . '/_files/wordcount.txt'),
  68. "Tested with " . var_export($element, 1)
  69. );
  70. }
  71. }
  72. /**
  73. * Ensures that getMin() returns expected value
  74. *
  75. * @return void
  76. */
  77. public function testGetMin()
  78. {
  79. $validator = new Zend_Validate_File_WordCount(array('min' => 1, 'max' => 5));
  80. $this->assertEquals(1, $validator->getMin());
  81. try {
  82. $validator = new Zend_Validate_File_WordCount(array('min' => 5, 'max' => 1));
  83. $this->fail("Missing exception");
  84. } catch (Zend_Validate_Exception $e) {
  85. $this->assertContains("greater than or equal", $e->getMessage());
  86. }
  87. $validator = new Zend_Validate_File_WordCount(array('min' => 1, 'max' => 5));
  88. $this->assertEquals(1, $validator->getMin());
  89. try {
  90. $validator = new Zend_Validate_File_WordCount(array('min' => 5, 'max' => 1));
  91. $this->fail("Missing exception");
  92. } catch (Zend_Validate_Exception $e) {
  93. $this->assertContains("greater than or equal", $e->getMessage());
  94. }
  95. }
  96. /**
  97. * Ensures that setMin() returns expected value
  98. *
  99. * @return void
  100. */
  101. public function testSetMin()
  102. {
  103. $validator = new Zend_Validate_File_WordCount(array('min' => 1000, 'max' => 10000));
  104. $validator->setMin(100);
  105. $this->assertEquals(100, $validator->getMin());
  106. try {
  107. $validator->setMin(20000);
  108. $this->fail("Missing exception");
  109. } catch (Zend_Validate_Exception $e) {
  110. $this->assertContains("less than or equal", $e->getMessage());
  111. }
  112. }
  113. /**
  114. * Ensures that getMax() returns expected value
  115. *
  116. * @return void
  117. */
  118. public function testGetMax()
  119. {
  120. $validator = new Zend_Validate_File_WordCount(array('min' => 1, 'max' => 100));
  121. $this->assertEquals(100, $validator->getMax());
  122. try {
  123. $validator = new Zend_Validate_File_WordCount(array('min' => 5, 'max' => 1));
  124. $this->fail("Missing exception");
  125. } catch (Zend_Validate_Exception $e) {
  126. $this->assertContains("greater than or equal", $e->getMessage());
  127. }
  128. }
  129. /**
  130. * Ensures that setMax() returns expected value
  131. *
  132. * @return void
  133. */
  134. public function testSetMax()
  135. {
  136. $validator = new Zend_Validate_File_WordCount(array('min' => 1000, 'max' => 10000));
  137. $validator->setMax(1000000);
  138. $this->assertEquals(1000000, $validator->getMax());
  139. $validator->setMin(100);
  140. $this->assertEquals(1000000, $validator->getMax());
  141. }
  142. }
  143. // Call Zend_Validate_File_WordCountTest::main() if this source file is executed directly.
  144. if (PHPUnit_MAIN_METHOD == "Zend_Validate_File_WordCountTest::main") {
  145. Zend_Validate_File_WordCountTest::main();
  146. }