TextValidatorTest.php.patch

Patch for the unit test - Karsten Dambekalns, 2010-01-20 12:11

Download (4.8 KB)

View differences:

/Users/karsten/Sites/flow3/Packages/Framework/FLOW3/Tests/Unit/Validation/Validator/TextValidatorTest.php (working copy)
31 31
class TextValidatorTest extends \F3\Testing\BaseTestCase {
32 32

  
33 33
	/**
34
	 * @test
35
	 * @author Andreas Förthner <andreas.foerthner@netlogix.de>
34
	 * Data provider with valid input for TextValidator.
35
	 * @return array
36 36
	 */
37
	public function textValidatorReturnsTrueForASimpleString() {
38
		$textValidator = new \F3\FLOW3\Validation\Validator\TextValidator();
39
		$this->assertTrue($textValidator->isValid('this is a very simple string'));
37
	public function validInput() {
38
		return array(
39
			array('this is a very simple string'),
40
			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.'),
41
			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\'.'),
42
		);
40 43
	}
41 44

  
42 45
	/**
43 46
	 * @test
44
	 * @author Robert Lemke <robert@typo3.org>
47
	 * @dataProvider validInput
48
	 * @param string $input
45 49
	 */
46
	public function textValidatorAllowsTheNewLineCharacter() {
47
		$sampleText = "Ierd Frot uechter mä get, Kirmesdag Milliounen all en, sinn main Stréi mä och. \nVu 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.";
48
		$textValidator = $this->getMock('F3\FLOW3\Validation\Validator\TextValidator', array('addError'), array(), '', FALSE);
49
		$this->assertTrue($textValidator->isValid($sampleText));
50
	public function textValidatorAcceptsValidInput($input) {
51
		$textValidator = new \F3\FLOW3\Validation\Validator\TextValidator();
52
		$this->assertTrue($textValidator->isValid($input));
50 53
	}
51 54

  
52 55
	/**
53
	 * @test
54
	 * @author Robert Lemke <robert@typo3.org>
56
	 * Data provider with invalid input for TextValidator.
57
	 * @return array
55 58
	 */
56
	public function textValidatorAllowsCommonSpecialCharacters() {
57
		$sampleText = "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'.";
58
		$textValidator = $this->getMock('F3\FLOW3\Validation\Validator\TextValidator', array('addError'), array(), '', FALSE);
59
		$this->assertTrue($textValidator->isValid($sampleText));
59
	public function invalidInput() {
60
		return array(
61
			array('<span style="color: #BBBBBB;">a nice text</span>'),
62
			array('%3cspan style="color: #BBBBBB;"%3ea nice text%3c/span%3e'),
63
		);
60 64
	}
61 65

  
62 66
	/**
63 67
	 * @test
64
	 * @author Andreas Förthner <andreas.foerthner@netlogix.de>
68
	 * @dataProvider invalidInput
69
	 * @param string $input
65 70
	 */
66
	public function textValidatorReturnsFalseForAStringWithHtml() {
71
	public function textValidatorRejectsInvalidInput($input) {
67 72
		$textValidator = $this->getMock('F3\FLOW3\Validation\Validator\TextValidator', array('addError'), array(), '', FALSE);
68
		$this->assertFalse($textValidator->isValid('<span style="color: #BBBBBB;">a nice text</span>'));
73
		$this->assertFalse($textValidator->isValid($input));
69 74
	}
70 75

  
71 76
	/**
72 77
	 * @test
73
	 * @author Karsten Dambekalns <karsten@typo3.org>
74
	 */
75
	public function textValidatorReturnsFalseForAStringWithPercentEncodedHtml() {
76
		$this->markTestIncomplete('The text validator currently allows percent encoded HTML!');
77
		$textValidator = $this->getMock('F3\FLOW3\Validation\Validator\TextValidator', array('addError'), array(), '', FALSE);
78
		$this->assertFalse($textValidator->isValid('%3cspan style="color: #BBBBBB;"%3ea nice text%3c/span%3e'));
79
	}
80

  
81
	/**
82
	 * @test
83 78
	 * @author Andreas Förthner <andreas.foerthner@netlogix.de>
84 79
	 */
85 80
	public function textValidatorCreatesTheCorrectErrorIfTheSubjectContainsHtmlEntities() {