PageRenderTime 42ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/Tests/Unit/Validation/Validator/TextValidatorTest.php

https://github.com/christianjul/FLOW3-Composer
PHP | 95 lines | 39 code | 13 blank | 43 comment | 0 complexity | 2c133ca549aac6d92824b9d14fd19bae MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-3.0
  1. <?php
  2. namespace TYPO3\FLOW3\Tests\Unit\Validation\Validator;
  3. /* *
  4. * This script belongs to the FLOW3 framework. *
  5. * *
  6. * It is free software; you can redistribute it and/or modify it under *
  7. * the terms of the GNU Lesser General Public License, either version 3 *
  8. * of the License, or (at your option) any later version. *
  9. * *
  10. * The TYPO3 project - inspiring people to share! *
  11. * */
  12. require_once('AbstractValidatorTestcase.php');
  13. /**
  14. * Testcase for the text validator
  15. *
  16. */
  17. class TextValidatorTest extends \TYPO3\FLOW3\Tests\Unit\Validation\Validator\AbstractValidatorTestcase {
  18. protected $validatorClassName = 'TYPO3\FLOW3\Validation\Validator\TextValidator';
  19. /**
  20. * @test
  21. */
  22. public function validateReturnsNoErrorIfTheGivenValueIsNull() {
  23. $this->assertFalse($this->validator->validate(NULL)->hasErrors());
  24. }
  25. /**
  26. * Data provider with valid input for TextValidator.
  27. * @return array
  28. */
  29. public function validateReturnsNoErrorIfTheGivenValueIsAnEmptyString() {
  30. $this->assertFalse($this->validator->validate('')->hasErrors());
  31. }
  32. /**
  33. * @test
  34. */
  35. public function textValidatorReturnsNoErrorForASimpleString() {
  36. $this->assertFalse($this->validator->validate('this is a very simple string')->hasErrors());
  37. }
  38. /**
  39. * @return array
  40. */
  41. public function validInput() {
  42. return array(
  43. array('this is a very simple string'),
  44. array('Ierd Frot uechter mä get, Kirmesdag Milliounen all en, sinn main Stréi mä och. ' . chr(10) . 'Vu dan durch jéngt gréng, ze rou Monn voll stolz. \nKe kille Minutt d\'Kirmes net. Hir Wand Lann Gaas da, wär hu Heck Gart zënter, Welt Ronn grousse der ke. Wou fond eraus Wisen am. Hu dénen d\'Gaassen eng, eng am virun geplot d\'Lëtzebuerger, get botze rëscht Blieder si. Dat Dauschen schéinste Milliounen fu. Ze riede méngem Keppchen déi, si gét fergiess erwaacht, räich jéngt duerch en nun. Gëtt Gaas d\'Vullen hie hu, laacht Grénge der dé. Gemaacht gehéiert da aus, gutt gudden d\'wäiss mat wa.'),
  45. array('3% of most people tend to use semikolae; we need to check & allow that. And hashes (#) are not evil either, nor is the sign called \'quote\'.'),
  46. );
  47. }
  48. /**
  49. * @test
  50. * @dataProvider validInput
  51. * @param string $input
  52. */
  53. public function textValidatorAcceptsValidInput($input) {
  54. $textValidator = new \TYPO3\FLOW3\Validation\Validator\TextValidator();
  55. $this->assertFalse($textValidator->validate($input)->hasErrors());
  56. }
  57. /**
  58. * Data provider with invalid input for TextValidator.
  59. * @return array
  60. */
  61. public function invalidInput() {
  62. return array(
  63. array('<span style="color: #BBBBBB;">a nice text</span>')
  64. );
  65. }
  66. /**
  67. * @test
  68. * @dataProvider invalidInput
  69. * @param string $input
  70. */
  71. public function textValidatorRejectsInvalidInput($input) {
  72. $this->assertTrue($this->validator->validate($input)->hasErrors());
  73. }
  74. /**
  75. * @test
  76. */
  77. public function textValidatorCreatesTheCorrectErrorIfTheSubjectContainsHtmlEntities() {
  78. $expected = array(new \TYPO3\FLOW3\Validation\Error('Valid text without any XML tags is expected.', 1221565786));
  79. $this->assertEquals($expected, $this->validator->validate('<span style="color: #BBBBBB;">a nice text</span>')->getErrors());
  80. }
  81. }
  82. ?>