PageRenderTime 34ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/Zend/Filter/NullTest.php

https://bitbucket.org/dbaltas/zend-framework-1.x-on-git
PHP | 292 lines | 165 code | 21 blank | 106 comment | 0 complexity | 12b047afdfaae9bd4cfa22558a947d0e MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, MIT
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  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.
  14. *
  15. * @category Zend
  16. * @package Zend_Filter
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Filter_Int
  24. */
  25. require_once 'Zend/Filter/Null.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Filter
  29. * @subpackage UnitTests
  30. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. * @group Zend_Filter
  33. */
  34. class Zend_Filter_NullTest extends PHPUnit_Framework_TestCase
  35. {
  36. /**
  37. * Zend_Filter_Null object
  38. *
  39. * @var Zend_Filter_Null
  40. */
  41. protected $_filter;
  42. /**
  43. * Creates a new Zend_Filter_Null object for each test method
  44. *
  45. * @return void
  46. */
  47. public function setUp()
  48. {
  49. $this->_filter = new Zend_Filter_Null();
  50. }
  51. /**
  52. * Ensures that the filter follows expected behavior
  53. *
  54. * @return void
  55. */
  56. public function testBasic()
  57. {
  58. $this->assertEquals(null, $this->_filter->filter('0'));
  59. $this->assertEquals(null, $this->_filter->filter(''));
  60. $this->assertEquals(null, $this->_filter->filter(0));
  61. $this->assertEquals(null, $this->_filter->filter(array()));
  62. $this->assertEquals(null, $this->_filter->filter(false));
  63. $this->assertEquals('test', $this->_filter->filter('test'));
  64. $this->assertEquals(true, $this->_filter->filter(true));
  65. }
  66. /**
  67. * Ensures that the filter follows expected behavior
  68. *
  69. * @return void
  70. */
  71. public function testOnlyBoolean()
  72. {
  73. $this->_filter->setType(Zend_Filter_Null::BOOLEAN);
  74. $this->assertEquals('0', $this->_filter->filter('0'));
  75. $this->assertEquals('', $this->_filter->filter(''));
  76. $this->assertEquals(0, $this->_filter->filter(0));
  77. $this->assertEquals(array(), $this->_filter->filter(array()));
  78. $this->assertEquals(null, $this->_filter->filter(false));
  79. $this->assertEquals('test', $this->_filter->filter('test'));
  80. $this->assertEquals(true, $this->_filter->filter(true));
  81. }
  82. /**
  83. * Ensures that the filter follows expected behavior
  84. *
  85. * @return void
  86. */
  87. public function testOnlyInteger()
  88. {
  89. $this->_filter->setType(Zend_Filter_Null::INTEGER);
  90. $this->assertEquals('0', $this->_filter->filter('0'));
  91. $this->assertEquals('', $this->_filter->filter(''));
  92. $this->assertEquals(null, $this->_filter->filter(0));
  93. $this->assertEquals(array(), $this->_filter->filter(array()));
  94. $this->assertEquals(false, $this->_filter->filter(false));
  95. $this->assertEquals('test', $this->_filter->filter('test'));
  96. $this->assertEquals(true, $this->_filter->filter(true));
  97. }
  98. /**
  99. * Ensures that the filter follows expected behavior
  100. *
  101. * @return void
  102. */
  103. public function testOnlyArray()
  104. {
  105. $this->_filter->setType(Zend_Filter_Null::EMPTY_ARRAY);
  106. $this->assertEquals('0', $this->_filter->filter('0'));
  107. $this->assertEquals('', $this->_filter->filter(''));
  108. $this->assertEquals(0, $this->_filter->filter(0));
  109. $this->assertEquals(null, $this->_filter->filter(array()));
  110. $this->assertEquals(false, $this->_filter->filter(false));
  111. $this->assertEquals('test', $this->_filter->filter('test'));
  112. $this->assertEquals(true, $this->_filter->filter(true));
  113. }
  114. /**
  115. * Ensures that the filter follows expected behavior
  116. *
  117. * @return void
  118. */
  119. public function testOnlyString()
  120. {
  121. $this->_filter->setType(Zend_Filter_Null::STRING);
  122. $this->assertEquals('0', $this->_filter->filter('0'));
  123. $this->assertEquals(null, $this->_filter->filter(''));
  124. $this->assertEquals(0, $this->_filter->filter(0));
  125. $this->assertEquals(array(), $this->_filter->filter(array()));
  126. $this->assertEquals(false, $this->_filter->filter(false));
  127. $this->assertEquals('test', $this->_filter->filter('test'));
  128. $this->assertEquals(true, $this->_filter->filter(true));
  129. }
  130. /**
  131. * Ensures that the filter follows expected behavior
  132. *
  133. * @return void
  134. */
  135. public function testOnlyZero()
  136. {
  137. $this->_filter->setType(Zend_Filter_Null::ZERO);
  138. $this->assertEquals(null, $this->_filter->filter('0'));
  139. $this->assertEquals('', $this->_filter->filter(''));
  140. $this->assertEquals(0, $this->_filter->filter(0));
  141. $this->assertEquals(array(), $this->_filter->filter(array()));
  142. $this->assertEquals(false, $this->_filter->filter(false));
  143. $this->assertEquals('test', $this->_filter->filter('test'));
  144. $this->assertEquals(true, $this->_filter->filter(true));
  145. }
  146. /**
  147. * Ensures that the filter follows expected behavior
  148. *
  149. * @return void
  150. */
  151. public function testArrayConstantNotation()
  152. {
  153. $filter = new Zend_Filter_Null(
  154. array(
  155. Zend_Filter_Null::ZERO,
  156. Zend_Filter_Null::STRING,
  157. Zend_Filter_Null::BOOLEAN
  158. )
  159. );
  160. $this->assertEquals(null, $filter->filter('0'));
  161. $this->assertEquals(null, $filter->filter(''));
  162. $this->assertEquals(0, $filter->filter(0));
  163. $this->assertEquals(array(), $filter->filter(array()));
  164. $this->assertEquals(null, $filter->filter(false));
  165. $this->assertEquals('test', $filter->filter('test'));
  166. $this->assertEquals(true, $filter->filter(true));
  167. }
  168. /**
  169. * Ensures that the filter follows expected behavior
  170. *
  171. * @return void
  172. */
  173. public function testArrayConfigNotation()
  174. {
  175. $filter = new Zend_Filter_Null(
  176. array(
  177. 'type' => array(
  178. Zend_Filter_Null::ZERO,
  179. Zend_Filter_Null::STRING,
  180. Zend_Filter_Null::BOOLEAN),
  181. 'test' => false
  182. )
  183. );
  184. $this->assertEquals(null, $filter->filter('0'));
  185. $this->assertEquals(null, $filter->filter(''));
  186. $this->assertEquals(0, $filter->filter(0));
  187. $this->assertEquals(array(), $filter->filter(array()));
  188. $this->assertEquals(null, $filter->filter(false));
  189. $this->assertEquals('test', $filter->filter('test'));
  190. $this->assertEquals(true, $filter->filter(true));
  191. }
  192. /**
  193. * Ensures that the filter follows expected behavior
  194. *
  195. * @return void
  196. */
  197. public function testMultiConstantNotation()
  198. {
  199. $filter = new Zend_Filter_Null(
  200. Zend_Filter_Null::ZERO + Zend_Filter_Null::STRING + Zend_Filter_Null::BOOLEAN
  201. );
  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));
  209. }
  210. /**
  211. * Ensures that the filter follows expected behavior
  212. *
  213. * @return void
  214. */
  215. public function testStringNotation()
  216. {
  217. $filter = new Zend_Filter_Null(
  218. array(
  219. 'zero', 'string', 'boolean'
  220. )
  221. );
  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));
  229. }
  230. /**
  231. * Ensures that the filter follows expected behavior
  232. *
  233. * @return void
  234. */
  235. public function testSingleStringNotation()
  236. {
  237. $filter = new Zend_Filter_Null(
  238. 'boolean'
  239. );
  240. $this->assertEquals('0', $filter->filter('0'));
  241. $this->assertEquals(null, $filter->filter(''));
  242. $this->assertEquals(0, $filter->filter(0));
  243. $this->assertEquals(array(), $filter->filter(array()));
  244. $this->assertEquals(false, $filter->filter(false));
  245. $this->assertEquals('test', $filter->filter('test'));
  246. $this->assertEquals(true, $filter->filter(true));
  247. }
  248. /**
  249. * Ensures that the filter follows expected behavior
  250. *
  251. * @return void
  252. */
  253. public function testSettingFalseType()
  254. {
  255. try {
  256. $this->_filter->setType(true);
  257. $this->fail();
  258. } catch (Zend_Exception $e) {
  259. $this->assertContains('Unknown', $e->getMessage());
  260. }
  261. }
  262. /**
  263. * Ensures that the filter follows expected behavior
  264. *
  265. * @return void
  266. */
  267. public function testGetType()
  268. {
  269. $this->assertEquals(31, $this->_filter->getType());
  270. }
  271. }