ZF-5514: implemented patch and adapted test backend
[zend/radio.git] / tests / Zend / Filter / NullTest.php
blobde441500de4b9bd3b2d796bf955902b59af8871c
1 <?php
2 /**
3 * Zend Framework
5 * LICENSE
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.
15 * @category Zend
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
20 * @version $Id$
23 /**
24 * Test helper
26 require_once dirname(__FILE__) . '/../../TestHelper.php';
28 /**
29 * @see Zend_Filter_Int
31 require_once 'Zend/Filter/Null.php';
33 /**
34 * @category Zend
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
39 * @group Zend_Filter
41 class Zend_Filter_NullTest extends PHPUnit_Framework_TestCase
43 /**
44 * Zend_Filter_Null object
46 * @var Zend_Filter_Null
48 protected $_filter;
50 /**
51 * Creates a new Zend_Filter_Null object for each test method
53 * @return void
55 public function setUp()
57 $this->_filter = new Zend_Filter_Null();
60 /**
61 * Ensures that the filter follows expected behavior
63 * @return void
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));
76 /**
77 * Ensures that the filter follows expected behavior
79 * @return void
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));
93 /**
94 * Ensures that the filter follows expected behavior
96 * @return void
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
113 * @return void
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
130 * @return void
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
147 * @return void
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
164 * @return void
166 public function testArrayConstantNotation()
168 $filter = new Zend_Filter_Null(
169 array(
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
188 * @return void
190 public function testArrayConfigNotation()
192 $filter = new Zend_Filter_Null(
193 array(
194 'type' => array(
195 Zend_Filter_Null::ZERO,
196 Zend_Filter_Null::STRING,
197 Zend_Filter_Null::BOOLEAN),
198 'test' => false
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
214 * @return void
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
234 * @return void
236 public function testStringNotation()
238 $filter = new Zend_Filter_Null(
239 array(
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
256 * @return void
258 public function testSingleStringNotation()
260 $filter = new Zend_Filter_Null(
261 'boolean'
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
276 * @return void
278 public function testSettingFalseType()
280 try {
281 $this->_filter->setType(true);
282 $this->fail();
283 } catch (Zend_Exception $e) {
284 $this->assertContains('Unknown', $e->getMessage());
289 * Ensures that the filter follows expected behavior
291 * @return void
293 public function testGetType()
295 $this->assertEquals(31, $this->_filter->getType());