7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
16 * @package Zend_Filter
17 * @subpackage UnitTests
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
26 require_once dirname(__FILE__
) . '/../../TestHelper.php';
29 * @see Zend_Filter_Int
31 require_once 'Zend/Filter/Null.php';
35 * @package Zend_Filter
36 * @subpackage UnitTests
37 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
38 * @license http://framework.zend.com/license/new-bsd New BSD License
41 class Zend_Filter_NullTest
extends PHPUnit_Framework_TestCase
44 * Zend_Filter_Null object
46 * @var Zend_Filter_Null
51 * Creates a new Zend_Filter_Null object for each test method
55 public function setUp()
57 $this->_filter
= new Zend_Filter_Null();
61 * Ensures that the filter follows expected behavior
65 public function testBasic()
67 $this->assertEquals(null, $this->_filter
->filter('0'));
68 $this->assertEquals(null, $this->_filter
->filter(''));
69 $this->assertEquals(null, $this->_filter
->filter(0));
70 $this->assertEquals(null, $this->_filter
->filter(array()));
71 $this->assertEquals(null, $this->_filter
->filter(false));
72 $this->assertEquals('test', $this->_filter
->filter('test'));
73 $this->assertEquals(true, $this->_filter
->filter(true));
77 * Ensures that the filter follows expected behavior
81 public function testOnlyBoolean()
83 $this->_filter
->setType(Zend_Filter_Null
::BOOLEAN
);
84 $this->assertEquals('0', $this->_filter
->filter('0'));
85 $this->assertEquals('', $this->_filter
->filter(''));
86 $this->assertEquals(0, $this->_filter
->filter(0));
87 $this->assertEquals(array(), $this->_filter
->filter(array()));
88 $this->assertEquals(null, $this->_filter
->filter(false));
89 $this->assertEquals('test', $this->_filter
->filter('test'));
90 $this->assertEquals(true, $this->_filter
->filter(true));
94 * Ensures that the filter follows expected behavior
98 public function testOnlyInteger()
100 $this->_filter
->setType(Zend_Filter_Null
::INTEGER);
101 $this->assertEquals('0', $this->_filter
->filter('0'));
102 $this->assertEquals('', $this->_filter
->filter(''));
103 $this->assertEquals(null, $this->_filter
->filter(0));
104 $this->assertEquals(array(), $this->_filter
->filter(array()));
105 $this->assertEquals(false, $this->_filter
->filter(false));
106 $this->assertEquals('test', $this->_filter
->filter('test'));
107 $this->assertEquals(true, $this->_filter
->filter(true));
111 * Ensures that the filter follows expected behavior
115 public function testOnlyArray()
117 $this->_filter
->setType(Zend_Filter_Null
::EMPTY_ARRAY
);
118 $this->assertEquals('0', $this->_filter
->filter('0'));
119 $this->assertEquals('', $this->_filter
->filter(''));
120 $this->assertEquals(0, $this->_filter
->filter(0));
121 $this->assertEquals(null, $this->_filter
->filter(array()));
122 $this->assertEquals(false, $this->_filter
->filter(false));
123 $this->assertEquals('test', $this->_filter
->filter('test'));
124 $this->assertEquals(true, $this->_filter
->filter(true));
128 * Ensures that the filter follows expected behavior
132 public function testOnlyString()
134 $this->_filter
->setType(Zend_Filter_Null
::STRING);
135 $this->assertEquals('0', $this->_filter
->filter('0'));
136 $this->assertEquals(null, $this->_filter
->filter(''));
137 $this->assertEquals(0, $this->_filter
->filter(0));
138 $this->assertEquals(array(), $this->_filter
->filter(array()));
139 $this->assertEquals(false, $this->_filter
->filter(false));
140 $this->assertEquals('test', $this->_filter
->filter('test'));
141 $this->assertEquals(true, $this->_filter
->filter(true));
145 * Ensures that the filter follows expected behavior
149 public function testOnlyZero()
151 $this->_filter
->setType(Zend_Filter_Null
::ZERO
);
152 $this->assertEquals(null, $this->_filter
->filter('0'));
153 $this->assertEquals('', $this->_filter
->filter(''));
154 $this->assertEquals(0, $this->_filter
->filter(0));
155 $this->assertEquals(array(), $this->_filter
->filter(array()));
156 $this->assertEquals(false, $this->_filter
->filter(false));
157 $this->assertEquals('test', $this->_filter
->filter('test'));
158 $this->assertEquals(true, $this->_filter
->filter(true));
162 * Ensures that the filter follows expected behavior
166 public function testArrayConstantNotation()
168 $filter = new Zend_Filter_Null(
170 Zend_Filter_Null
::ZERO
,
171 Zend_Filter_Null
::STRING,
172 Zend_Filter_Null
::BOOLEAN
176 $this->assertEquals(null, $filter->filter('0'));
177 $this->assertEquals(null, $filter->filter(''));
178 $this->assertEquals(0, $filter->filter(0));
179 $this->assertEquals(array(), $filter->filter(array()));
180 $this->assertEquals(null, $filter->filter(false));
181 $this->assertEquals('test', $filter->filter('test'));
182 $this->assertEquals(true, $filter->filter(true));
186 * Ensures that the filter follows expected behavior
190 public function testArrayConfigNotation()
192 $filter = new Zend_Filter_Null(
195 Zend_Filter_Null
::ZERO
,
196 Zend_Filter_Null
::STRING,
197 Zend_Filter_Null
::BOOLEAN
),
202 $this->assertEquals(null, $filter->filter('0'));
203 $this->assertEquals(null, $filter->filter(''));
204 $this->assertEquals(0, $filter->filter(0));
205 $this->assertEquals(array(), $filter->filter(array()));
206 $this->assertEquals(null, $filter->filter(false));
207 $this->assertEquals('test', $filter->filter('test'));
208 $this->assertEquals(true, $filter->filter(true));
212 * Ensures that the filter follows expected behavior
216 public function testMultiConstantNotation()
218 $filter = new Zend_Filter_Null(
219 Zend_Filter_Null
::ZERO + Zend_Filter_Null
::STRING + Zend_Filter_Null
::BOOLEAN
222 $this->assertEquals(null, $filter->filter('0'));
223 $this->assertEquals(null, $filter->filter(''));
224 $this->assertEquals(0, $filter->filter(0));
225 $this->assertEquals(array(), $filter->filter(array()));
226 $this->assertEquals(null, $filter->filter(false));
227 $this->assertEquals('test', $filter->filter('test'));
228 $this->assertEquals(true, $filter->filter(true));
232 * Ensures that the filter follows expected behavior
236 public function testStringNotation()
238 $filter = new Zend_Filter_Null(
240 'zero', 'string', 'boolean'
244 $this->assertEquals(null, $filter->filter('0'));
245 $this->assertEquals(null, $filter->filter(''));
246 $this->assertEquals(0, $filter->filter(0));
247 $this->assertEquals(array(), $filter->filter(array()));
248 $this->assertEquals(null, $filter->filter(false));
249 $this->assertEquals('test', $filter->filter('test'));
250 $this->assertEquals(true, $filter->filter(true));
254 * Ensures that the filter follows expected behavior
258 public function testSingleStringNotation()
260 $filter = new Zend_Filter_Null(
264 $this->assertEquals('0', $filter->filter('0'));
265 $this->assertEquals(null, $filter->filter(''));
266 $this->assertEquals(0, $filter->filter(0));
267 $this->assertEquals(array(), $filter->filter(array()));
268 $this->assertEquals(false, $filter->filter(false));
269 $this->assertEquals('test', $filter->filter('test'));
270 $this->assertEquals(true, $filter->filter(true));
274 * Ensures that the filter follows expected behavior
278 public function testSettingFalseType()
281 $this->_filter
->setType(true);
283 } catch (Zend_Exception
$e) {
284 $this->assertContains('Unknown', $e->getMessage());
289 * Ensures that the filter follows expected behavior
293 public function testGetType()
295 $this->assertEquals(31, $this->_filter
->getType());