source: trunk/tests/FormValidatorTest.php @ 1

Last change on this file since 1 was 1, checked in by scdev, 19 years ago

Initial import.

File size: 3.8 KB
Line 
1<?php
2/**
3 * PHPUnit test case for FormValidator
4 *
5 * The method skeletons below need to be filled in with
6 * real data so that the tests will run correctly. Replace
7 * all EXPECTED_VAL and PARAM strings with real data.
8 *
9 * Created with PHPUnit_Skeleton on 2005-08-09
10 */
11require_once 'PHPUnit.php';
12class FormValidatorTest extends PHPUnit_TestCase {
13
14    var $FormValidator;
15
16    function FormValidatorTest($name)
17    {
18        $this->PHPUnit_TestCase($name);
19    }
20
21    function setUp()
22    {
23        require dirname(__FILE__) . '/_config.inc.php';
24        require_once '../lib/FormValidator.inc.php';
25        $this->FormValidator =& new FormValidator(PARAM);
26    }
27
28    function tearDown()
29    {
30        unset($this->FormValidator);
31    }
32
33    function test_geterrorlist()
34    {
35        $this->FormValidator->geterrorlist();
36    }
37
38    function test_adderror()
39    {
40        $this->FormValidator->addError('name', _("This is an error."), MSG_ERR, __FILE__, __LINE__);
41    }
42
43    function test_anyerrors()
44    {
45        $result = $this->FormValidator->anyerrors();
46        $this->assertFalse($result);
47    }
48
49    function test_reseterrorlist()
50    {
51        $this->FormValidator->addError('name', _("This is an error."), MSG_ERR, __FILE__, __LINE__);
52        $this->FormValidator->reseterrorlist();
53        $this->assertFalse($this->FormValidator->anyerrors());
54    }
55
56    function test_printerrormessages()
57    {
58        $this->FormValidator->addError('name', _("This is an error."), MSG_ERR, __FILE__, __LINE__);
59        ob_start();
60        $this->FormValidator->printerrormessages();
61        $result = ob_get_clean();
62        $this->assertContains('This is an error', $result);
63    }
64
65    function test_err()
66    {
67        $this->FormValidator->addError('name', _("This is an error."), MSG_ERR, __FILE__, __LINE__);
68        ob_start();
69        $this->FormValidator->err('name', 'printthis');
70        $result = ob_get_clean();
71        $this->assertContains('printthis', $result);
72    }
73
74    function test_notempty()
75    {
76        $this->FormValidator->isEmpty('name', _("Error message"));
77    }
78
79    function test_isempty()
80    {
81        $result = $this->FormValidator->isempty('name', _("Error message"));
82    }
83
84    function test_isstring()
85    {
86        $result = $this->FormValidator->isstring('name', _("Error message"));
87    }
88
89    function test_isnumber()
90    {
91        $result = $this->FormValidator->isnumber('name', _("Error message"));
92    }
93
94    function test_isinteger()
95    {
96        $result = $this->FormValidator->isinteger('name', _("Error message"));
97    }
98
99    function test_isfloat()
100    {
101        $result = $this->FormValidator->isfloat('name', _("Error message"));
102    }
103
104    function test_isarray()
105    {
106        $result = $this->FormValidator->isarray('name', _("Error message"));
107    }
108
109    function test_checkregex()
110    {
111        $result = $this->FormValidator->checkregex('name', '/\w/', true, _("Error message"));
112    }
113
114    function test_stringlength()
115    {
116        $this->FormValidator->stringLength('name', 0, 255, _("Error message"));
117    }
118
119    function test_numericrange()
120    {
121        $this->FormValidator->numericrange('name', 0, 255, _("Error message"));
122    }
123
124    function test_validateemail()
125    {
126        $this->FormValidator->validateemail('name');
127    }
128
129    function test_validatephone()
130    {
131        $this->FormValidator->validatephone('name');
132    }
133
134    function test_validatestrdate()
135    {
136        $this->FormValidator->validatestrdate('name');
137    }
138
139    function test_validateccnumber()
140    {
141        $this->FormValidator->validateccnumber('name');
142    }
143
144    function test_validatefile()
145    {
146        $this->FormValidator->validatefile('name');
147    }
148
149}
150// Running the test.
151$suite = new PHPUnit_TestSuite('FormValidatorTest');
152$result = PHPUnit::run($suite);
153echo $result->toString();
154?>
Note: See TracBrowser for help on using the repository browser.