SanatizeTest.php 2.34 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
<?php
/**
 * Created by PhpStorm.
 * User: crose
 * Date: 1/2/16
 * Time: 11:10 PM
 */

namespace qfq;

Carsten  Rose's avatar
Carsten Rose committed
11
//use qfq\Sanatize;
12
//use qfq\exceptions\CodeException;
13

14
require_once(__DIR__ . '/../../qfq/helper/Sanatize.php');
Carsten  Rose's avatar
Carsten Rose committed
15
require_once(__DIR__ . '/../../qfq/exceptions/CodeException.php');
16
17
18
19
20
21
22
23
24
25
26
27
28
29


class SanatizeTest extends \PHPUnit_Framework_TestCase {

    public function testSanatize() {

        # Violates SANATIZE class: sanatized string is always an empty string.
        # Access are cached: use new variables for every test.

        # Check '1'
        $this->assertEquals('1', Sanatize::sanatize('1', SANATIZE_DIGIT), "SANATIZE_DIGIT fails");
        $this->assertEquals('1', Sanatize::sanatize('1', SANATIZE_ALNUMX), "SANATIZE_ALNUMX fails");
        $this->assertEquals('1', Sanatize::sanatize('1', SANATIZE_ALL), "SANATIZE_ALL fails");

30
31
32
33
34
        # Check '-3'
        $this->assertEquals('-3', Sanatize::sanatize('-3', SANATIZE_DIGIT), "SANATIZE_DIGIT fails");
        $this->assertEquals('-3', Sanatize::sanatize('-3', SANATIZE_ALNUMX), "SANATIZE_ALNUMX fails");
        $this->assertEquals('-3', Sanatize::sanatize('-3', SANATIZE_ALL), "SANATIZE_ALL fails");

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
        # Check 'a'
        $this->assertEquals('', Sanatize::sanatize('a', SANATIZE_DIGIT), "SANATIZE_DIGIT fails");
        $this->assertEquals('a', Sanatize::sanatize('a', SANATIZE_ALNUMX), "SANATIZE_ALNUMX fails");
        $this->assertEquals('a', Sanatize::sanatize('a', SANATIZE_ALL), "SANATIZE_ALL fails");


        # Check 'a@-_.,;Z09'
        $this->assertEquals('', Sanatize::sanatize('a@-_.,;Z09', SANATIZE_DIGIT), "SANATIZE_DIGIT fails");
        $this->assertEquals('a@-_.,;Z09', Sanatize::sanatize('a@-_.,;Z09', SANATIZE_ALNUMX), "SANATIZE_ALNUMX fails");
        $this->assertEquals('a@-_.,;Z09', Sanatize::sanatize('a@-_.,;Z09', SANATIZE_ALL), "SANATIZE_ALL fails");

        # Check 'a+Z09'
        $this->assertEquals('', Sanatize::sanatize('a+Z09', SANATIZE_DIGIT), "SANATIZE_DIGIT fails");
        $this->assertEquals('', Sanatize::sanatize('a+Z09', SANATIZE_ALNUMX), "SANATIZE_ALNUMX fails");
        $this->assertEquals('a+Z09', Sanatize::sanatize('a+Z09', SANATIZE_ALL), "SANATIZE_ALL fails");
    }

Carsten  Rose's avatar
Carsten Rose committed
52
53
54
55
    /**
     * @expectedException \qfq\exceptions\CodeException
     *
     */
56
    public function testSanatizeException() {
Carsten  Rose's avatar
Carsten Rose committed
57
        Sanatize::sanatize('Hello World', 'invalid sanatize class');
58
59
60
    }

}