[~CONFIGURATION] Extbase: Set lockType to empty string instead of 'system'.
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Validation / Validator / TextValidator_testcase.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
6 * All rights reserved
7 *
8 * This class is a backport of the corresponding class of FLOW3.
9 * All credits go to the v5 team.
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 /**
29 * Testcase for the text validator
30 *
31 * @package Extbase
32 * @subpackage extbase
33 * @version $Id$
34 */
35 class Tx_Extbase_Validation_Validator_TextValidator_testcase extends Tx_Extbase_BaseTestCase {
36
37 /**
38 * @test
39 */
40 public function textValidatorReturnsTrueForASimpleString() {
41 $textValidator = new Tx_Extbase_Validation_Validator_TextValidator();
42 $this->assertTrue($textValidator->isValid('this is a very simple string'));
43 }
44
45 /**
46 * @test
47 */
48 public function textValidatorAllowsTheNewLineCharacter() {
49 $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.";
50 $textValidator = $this->getMock('Tx_Extbase_Validation_Validator_TextValidator', array('addError'), array(), '', FALSE);
51 $this->assertTrue($textValidator->isValid($sampleText));
52 }
53
54 /**
55 * @test
56 */
57 public function textValidatorAllowsCommonSpecialCharacters() {
58 $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'.";
59 $textValidator = $this->getMock('Tx_Extbase_Validation_Validator_TextValidator', array('addError'), array(), '', FALSE);
60 $this->assertTrue($textValidator->isValid($sampleText));
61 }
62
63 /**
64 * @test
65 */
66 public function textValidatorReturnsFalseForAStringWithHtml() {
67 $textValidator = $this->getMock('Tx_Extbase_Validation_Validator_TextValidator', array('addError'), array(), '', FALSE);
68 $this->assertFalse($textValidator->isValid('<span style="color: #BBBBBB;">a nice text</span>'));
69 }
70
71 /**
72 * @test
73 */
74 public function textValidatorReturnsFalseForAStringWithPercentEncodedHtml() {
75 $this->markTestIncomplete('The text validator currently allows percent encoded HTML!');
76 $textValidator = $this->getMock('Tx_Extbase_Validation_Validator_TextValidator', array('addError'), array(), '', FALSE);
77 $this->assertFalse($textValidator->isValid('%3cspan style="color: #BBBBBB;"%3ea nice text%3c/span%3e'));
78 }
79
80 /**
81 * @test
82 */
83 public function textValidatorCreatesTheCorrectErrorIfTheSubjectContainsHtmlEntities() {
84 $textValidator = $this->getMock('Tx_Extbase_Validation_Validator_TextValidator', array('addError'), array(), '', FALSE);
85 $textValidator->expects($this->once())->method('addError')->with('The given subject was not a valid text (e.g. contained XML tags).', 1221565786);
86 $textValidator->isValid('<span style="color: #BBBBBB;">a nice text</span>');
87 }
88 }
89
90 ?>