[TASK] Namespace classes
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Validation / Validator / BeforeExtbase14 / TextValidatorTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\BeforeExtbase14;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
8 * All rights reserved
9 *
10 * This class is a backport of the corresponding class of FLOW3.
11 * All credits go to the v5 team.
12 *
13 * This script is part of the TYPO3 project. The TYPO3 project is
14 * free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * The GNU General Public License can be found at
20 * http://www.gnu.org/copyleft/gpl.html.
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29 /**
30 * Testcase for the text validator.
31 *
32 * This testcase checks the expected behavior for Extbase < 1.4.0, to make sure
33 * we do not break backwards compatibility.
34 *
35 * @package Extbase
36 * @subpackage extbase
37 * @version $Id: TextValidator_testcase.php 2428 2010-07-20 10:18:51Z jocrau $
38 */
39 class TextValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
40
41 /**
42 * @test
43 */
44 public function textValidatorReturnsTrueForASimpleString() {
45 $textValidator = new \TYPO3\CMS\Extbase\Validation\Validator\TextValidator();
46 $this->assertTrue($textValidator->isValid('this is a very simple string'));
47 }
48
49 /**
50 * @test
51 */
52 public function textValidatorAllowsTheNewLineCharacter() {
53 $sampleText = 'Ierd Frot uechter mä get, Kirmesdag Milliounen all en, sinn main Stréi mä och.
54 Vu dan durch jéngt gréng, ze rou Monn voll stolz.
55 Ke 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.';
56 $textValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\TextValidator', array('addError'), array(), '', FALSE);
57 $this->assertTrue($textValidator->isValid($sampleText));
58 }
59
60 /**
61 * @test
62 */
63 public function textValidatorAllowsCommonSpecialCharacters() {
64 $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\'.';
65 $textValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\TextValidator', array('addError'), array(), '', FALSE);
66 $this->assertTrue($textValidator->isValid($sampleText));
67 }
68
69 /**
70 * @test
71 */
72 public function textValidatorReturnsFalseForAStringWithHtml() {
73 $textValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\TextValidator', array('addError'), array(), '', FALSE);
74 $this->assertFalse($textValidator->isValid('<span style="color: #BBBBBB;">a nice text</span>'));
75 }
76
77 /**
78 * @test
79 */
80 public function textValidatorReturnsFalseForAStringWithPercentEncodedHtml() {
81 $this->markTestIncomplete('The text validator currently allows percent encoded HTML!');
82 $textValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\TextValidator', array('addError'), array(), '', FALSE);
83 $this->assertFalse($textValidator->isValid('%3cspan style="color: #BBBBBB;"%3ea nice text%3c/span%3e'));
84 }
85
86 /**
87 * @test
88 */
89 public function textValidatorCreatesTheCorrectErrorIfTheSubjectContainsHtmlEntities() {
90 $textValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\TextValidator', array('addError'), array(), '', FALSE);
91 $textValidator->expects($this->once())->method('addError')->with('The given subject was not a valid text (e.g. contained XML tags).', 1221565786);
92 $textValidator->isValid('<span style="color: #BBBBBB;">a nice text</span>');
93 }
94
95 }
96
97
98 ?>