CFDBFilterParserTest

The Contact Form DB CFDBFilterParserTest class.

Defined (1)

The class is defined in the following location(s).

/phpunit/CFDBFilterParserTest.php  
  1. class CFDBFilterParserTest extends PHPUnit_Framework_TestCase { 
  2.  
  3.  
  4. public function test1() { 
  5. $filterText = 'a=b'; 
  6. $filters = preg_split('/&&|\|\|/', $filterText, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); 
  7.  
  8. $this->assertEquals($filterText, $filters[0]); 
  9. //print_r($filters); 
  10.  
  11. public function test2() { 
  12. $filterText = 'aaa=bbb&&ccc=ddd&&eee<>fff'; 
  13. $filters = preg_split('/&&|\|\|/', $filterText, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); 
  14.  
  15. $this->assertEquals('aaa=bbb', $filters[0]); 
  16. $this->assertEquals('ccc=ddd', $filters[1]); 
  17. $this->assertEquals('eee<>fff', $filters[2]); 
  18. //print_r($filters); 
  19.  
  20. public function test3() { 
  21. $filterText = 'aaa=bbb||ccc=ddd||eee<>fff'; 
  22. $filters = preg_split('/&&|\|\|/', $filterText, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); 
  23.  
  24. $this->assertEquals('aaa=bbb', $filters[0]); 
  25. $this->assertEquals('ccc=ddd', $filters[1]); 
  26. $this->assertEquals('eee<>fff', $filters[2]); 
  27. //print_r($filters); 
  28.  
  29. public function test4() { 
  30. $filterText = 'aaa=bbb&&ccc=ddd&&eee<>fff'; 
  31. $filters = preg_split('/(&&)|(\|\|)/', $filterText, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); 
  32.  
  33. $this->assertEquals('aaa=bbb', $filters[0]); 
  34. $this->assertEquals('&&', $filters[1]); 
  35. $this->assertEquals('ccc=ddd', $filters[2]); 
  36. $this->assertEquals('&&', $filters[3]); 
  37. $this->assertEquals('eee<>fff', $filters[4]); 
  38. //print_r($filters); 
  39.  
  40. public function test5() { 
  41. $filters = preg_split('/&&/', 'your-message=admin&&your-subject=Simpson', -1, PREG_SPLIT_NO_EMPTY); 
  42. $this->assertEquals('your-message=admin', $filters[0]); 
  43. $this->assertEquals('your-subject=Simpson', $filters[1]); 
  44. $this->assertEquals(count($filters), 2); 
  45.  
  46. public function test_parseORs_1() { 
  47. $p = new CFDBFilterParser; 
  48. $filters = $p->parseORs('aaa=bbb||ccc=ddd||eee<>fff'); 
  49. $this->assertEquals('aaa=bbb', $filters[0]); 
  50. $this->assertEquals('ccc=ddd', $filters[1]); 
  51. $this->assertEquals('eee<>fff', $filters[2]); 
  52. $this->assertEquals(count($filters), 3); 
  53.  
  54. public function test_parseORs_2() { 
  55. $p = new CFDBFilterParser; 
  56. $filters = $p->parseORs('aaa=bbb&&ccc=ddd||eee<>fff'); 
  57. $this->assertEquals('aaa=bbb&&ccc=ddd', $filters[0]); 
  58. $this->assertEquals('eee<>fff', $filters[1]); 
  59. $this->assertEquals(count($filters), 2); 
  60.  
  61. public function test_parseORs_3() { 
  62. $p = new CFDBFilterParser; 
  63. $filters = $p->parseORs('aaa=bbb'); 
  64. $this->assertEquals('aaa=bbb', $filters[0]); 
  65. $this->assertEquals(count($filters), 1); 
  66.  
  67. public function test_parseANDs_1() { 
  68. $p = new CFDBFilterParser; 
  69. $filters = $p->parseANDs('aaa=bbb&&ccc=ddd&&eee<>fff'); 
  70. $this->assertEquals('aaa=bbb', $filters[0]); 
  71. $this->assertEquals('ccc=ddd', $filters[1]); 
  72. $this->assertEquals('eee<>fff', $filters[2]); 
  73. $this->assertEquals(count($filters), 3); 
  74.  
  75. public function test_parseANDs_2() { 
  76. $p = new CFDBFilterParser; 
  77. $filters = $p->parseANDs('aaa=bbb||ccc=ddd&&eee<>fff'); 
  78. $this->assertEquals('aaa=bbb||ccc=ddd', $filters[0]); 
  79. $this->assertEquals('eee<>fff', $filters[1]); 
  80. $this->assertEquals(count($filters), 2); 
  81.  
  82. public function test_parseANDs_3() { 
  83. $p = new CFDBFilterParser; 
  84. $filters = $p->parseANDs('aaa=bbb'); 
  85. $this->assertEquals('aaa=bbb', $filters[0]); 
  86. $this->assertEquals(count($filters), 1); 
  87.  
  88.  
  89. public function test_parseEncodedANDs_1() { 
  90. $p = new CFDBFilterParser; 
  91. $filters = $p->parseANDs('aaa=bbb&&ccc=ddd&&eee<>fff'); 
  92. $this->assertEquals('aaa=bbb', $filters[0]); 
  93. $this->assertEquals('ccc=ddd', $filters[1]); 
  94. $this->assertEquals('eee<>fff', $filters[2]); 
  95. $this->assertEquals(count($filters), 3); 
  96.  
  97. public function test_parseEncodedANDs_2() { 
  98. $p = new CFDBFilterParser; 
  99. $filters = $p->parseANDs('aaa=bbb&&ccc=ddd&&eee<>fff'); 
  100. $this->assertEquals('aaa=bbb', $filters[0]); 
  101. $this->assertEquals('ccc=ddd', $filters[1]); 
  102. $this->assertEquals('eee<>fff', $filters[2]); 
  103. $this->assertEquals(count($filters), 3); 
  104.  
  105. /** 
  106. Array 
  107. [0] => Array 
  108. [0] => Array 
  109. [0] => aaa 
  110. [1] => = 
  111. [2] => bbb 
  112.   
  113.   
  114. */ 
  115. public function test_parseFilterString_1() { 
  116. $p = new CFDBFilterParser; 
  117. $p->parse('aaa=bbb'); 
  118. $tree = $p->getFilterTree(); 
  119.  
  120. $this->assertEquals('aaa', $tree[0][0][0], print_r($tree, true)); 
  121. $this->assertEquals('=', $tree[0][0][1], print_r($tree, true)); 
  122. $this->assertEquals('bbb', $tree[0][0][2], print_r($tree, true)); 
  123. $this->assertEquals(count($tree), 1, print_r($tree, true)); 
  124. $this->assertEquals(count($tree[0]), 1, print_r($tree, true)); 
  125. $this->assertEquals(count($tree[0][0]), 3, print_r($tree, true)); 
  126.  
  127. /** 
  128. Array 
  129. [0] => Array 
  130. [0] => Array 
  131. [0] => aaa 
  132. [1] => = 
  133. [2] => bbb 
  134.   
  135.   
  136. [1] => Array 
  137. [0] => Array 
  138. [0] => ccc 
  139. [1] => = 
  140. [2] => ddd 
  141.   
  142.   
  143. */ 
  144. public function test_parseFilterString_2() { 
  145. $p = new CFDBFilterParser; 
  146. $p->parse('aaa=bbb||ccc=ddd'); 
  147. $tree = $p->getFilterTree(); 
  148. $this->assertEquals('aaa', $tree[0][0][0], print_r($tree, true)); 
  149. $this->assertEquals('=', $tree[0][0][1], print_r($tree, true)); 
  150. $this->assertEquals('bbb', $tree[0][0][2], print_r($tree, true)); 
  151.  
  152. $this->assertEquals('ccc', $tree[1][0][0], print_r($tree, true)); 
  153. $this->assertEquals('=', $tree[1][0][1], print_r($tree, true)); 
  154. $this->assertEquals('ddd', $tree[1][0][2], print_r($tree, true)); 
  155.  
  156.  
  157. $this->assertEquals(count($tree), 2, print_r($tree, true)); 
  158. $this->assertEquals(count($tree[0][0]), 3, print_r($tree, true)); 
  159. $this->assertEquals(count($tree[1][0]), 3, print_r($tree, true)); 
  160.  
  161.  
  162. /** 
  163. Array 
  164. [0] => Array 
  165. [0] => Array 
  166. [0] => aaa 
  167. [1] => = 
  168. [2] => bbb 
  169.   
  170.   
  171. [1] => Array 
  172. [0] => Array 
  173. [0] => ccc 
  174. [1] => = 
  175. [2] => ddd 
  176.   
  177. [1] => Array 
  178. [0] => eee 
  179. [1] => = 
  180. [2] => fff 
  181.   
  182.   
  183. */ 
  184. public function test_parseFilterString_3() { 
  185. $p = new CFDBFilterParser; 
  186. $p->parse('aaa=bbb||ccc=ddd&&eee=fff'); 
  187. $tree = $p->getFilterTree(); 
  188. $this->assertEquals(count($tree), 2, print_r($tree, true)); 
  189.  
  190. $this->assertEquals('aaa', $tree[0][0][0], print_r($tree, true)); 
  191. $this->assertEquals('=', $tree[0][0][1], print_r($tree, true)); 
  192. $this->assertEquals('bbb', $tree[0][0][2], print_r($tree, true)); 
  193. $this->assertEquals(count($tree[0][0]), 3, print_r($tree, true)); 
  194.  
  195. $this->assertEquals('ccc', $tree[1][0][0], print_r($tree, true)); 
  196. $this->assertEquals('=', $tree[1][0][1], print_r($tree, true)); 
  197. $this->assertEquals('ddd', $tree[1][0][2], print_r($tree, true)); 
  198. $this->assertEquals(count($tree[1][0]), 3, print_r($tree, true)); 
  199.  
  200.  
  201. $this->assertEquals('eee', $tree[1][1][0], print_r($tree, true)); 
  202. $this->assertEquals('=', $tree[1][1][1], print_r($tree, true)); 
  203. $this->assertEquals('fff', $tree[1][1][2], print_r($tree, true)); 
  204. $this->assertEquals(count($tree[1][1]), 3, print_r($tree, true)); 
  205.  
  206. $this->assertEquals(count($tree[1]), 2, print_r($tree, true)); 
  207.  
  208. $this->assertEquals(count($tree), 2, print_r($tree, true)); 
  209.  
  210.  
  211. /** 
  212. Array 
  213. [0] => Array 
  214. [0] => Array 
  215. [0] => aaa 
  216. [1] => = 
  217. [2] => bbb 
  218.   
  219.   
  220. [1] => Array 
  221. [0] => Array 
  222. [0] => ccc 
  223. [1] => = 
  224. [2] => ddd 
  225.   
  226. [1] => Array 
  227. [0] => eee 
  228. [1] => = 
  229. [2] => fff 
  230.   
  231. [2] => Array 
  232. [0] => ggg 
  233. [1] => = 
  234. [2] => hhh 
  235.   
  236.   
  237. */ 
  238. public function test_parseFilterString_4() { 
  239. $p = new CFDBFilterParser; 
  240. $p->parse('aaa=bbb||ccc=ddd&&eee=fff&&ggg=hhh'); 
  241. $tree = $p->getFilterTree(); 
  242. $this->assertEquals(count($tree), 2, print_r($tree, true)); 
  243.  
  244. $this->assertEquals('aaa', $tree[0][0][0], print_r($tree, true)); 
  245. $this->assertEquals('=', $tree[0][0][1], print_r($tree, true)); 
  246. $this->assertEquals('bbb', $tree[0][0][2], print_r($tree, true)); 
  247. $this->assertEquals(count($tree[0][0]), 3, print_r($tree, true)); 
  248.  
  249. $this->assertEquals('ccc', $tree[1][0][0], print_r($tree, true)); 
  250. $this->assertEquals('=', $tree[1][0][1], print_r($tree, true)); 
  251. $this->assertEquals('ddd', $tree[1][0][2], print_r($tree, true)); 
  252.  
  253. $this->assertEquals('eee', $tree[1][1][0], print_r($tree, true)); 
  254. $this->assertEquals('=', $tree[1][1][1], print_r($tree, true)); 
  255. $this->assertEquals('fff', $tree[1][1][2], print_r($tree, true)); 
  256.  
  257. $this->assertEquals('ggg', $tree[1][2][0], print_r($tree, true)); 
  258. $this->assertEquals('=', $tree[1][2][1], print_r($tree, true)); 
  259. $this->assertEquals('hhh', $tree[1][2][2], print_r($tree, true)); 
  260.  
  261. $this->assertEquals(count($tree[1]), 3, print_r($tree, true)); 
  262.  
  263. /** 
  264. Array 
  265. [0] => Array 
  266. [0] => Array 
  267. [0] => aaa 
  268. [1] => = 
  269. [2] => bbb 
  270.   
  271. [1] => Array 
  272. [0] => yyy 
  273. [1] => = 
  274. [2] => zzz 
  275.   
  276. [2] => Array 
  277. [0] => www 
  278. [1] => = 
  279. [2] => xxx 
  280.   
  281.   
  282. [1] => Array 
  283. [0] => Array 
  284. [0] => ccc 
  285. [1] => = 
  286. [2] => ddd 
  287.   
  288. [1] => Array 
  289. [0] => eee 
  290. [1] => = 
  291. [2] => fff 
  292.   
  293. [2] => Array 
  294. [0] => ggg 
  295. [1] => = 
  296. [2] => hhh 
  297.   
  298.   
  299. */ 
  300. public function test_parseFilterString_5() { 
  301. $p = new CFDBFilterParser; 
  302. $p->parse('aaa=bbb&&yyy=zzz&&www=xxx||ccc=ddd&&eee=fff&&ggg=hhh'); 
  303. $tree = $p->getFilterTree(); 
  304. $this->assertEquals(count($tree), 2, print_r($tree, true)); 
  305.  
  306. $this->assertEquals('aaa', $tree[0][0][0], print_r($tree, true)); 
  307. $this->assertEquals('=', $tree[0][0][1], print_r($tree, true)); 
  308. $this->assertEquals('bbb', $tree[0][0][2], print_r($tree, true)); 
  309.  
  310. $this->assertEquals('yyy', $tree[0][1][0], print_r($tree, true)); 
  311. $this->assertEquals('=', $tree[0][1][1], print_r($tree, true)); 
  312. $this->assertEquals('zzz', $tree[0][1][2], print_r($tree, true)); 
  313.  
  314. $this->assertEquals('www', $tree[0][2][0], print_r($tree, true)); 
  315. $this->assertEquals('=', $tree[0][2][1], print_r($tree, true)); 
  316. $this->assertEquals('xxx', $tree[0][2][2], print_r($tree, true)); 
  317.  
  318. $this->assertEquals(count($tree[0]), 3, print_r($tree, true)); 
  319.  
  320. $this->assertEquals('ccc', $tree[1][0][0], print_r($tree, true)); 
  321. $this->assertEquals('=', $tree[1][0][1], print_r($tree, true)); 
  322. $this->assertEquals('ddd', $tree[1][0][2], print_r($tree, true)); 
  323.  
  324. $this->assertEquals('eee', $tree[1][1][0], print_r($tree, true)); 
  325. $this->assertEquals('=', $tree[1][1][1], print_r($tree, true)); 
  326. $this->assertEquals('fff', $tree[1][1][2], print_r($tree, true)); 
  327.  
  328. $this->assertEquals('ggg', $tree[1][2][0], print_r($tree, true)); 
  329. $this->assertEquals('=', $tree[1][2][1], print_r($tree, true)); 
  330. $this->assertEquals('hhh', $tree[1][2][2], print_r($tree, true)); 
  331.  
  332. $this->assertEquals(count($tree[1]), 3, print_r($tree, true)); 
  333.  
  334. public function test_parseFilterString_6() { 
  335. $p = new CFDBFilterParser; 
  336. $p->parse(''); 
  337. $tree = $p->getFilterTree(); 
  338. $this->assertEquals(count($tree), 0); 
  339.  
  340. private function parseExpression($a, $op, $b) { 
  341. $p = new CFDBFilterParser; 
  342. $exp = $p->parseExpression($a . $op . $b); 
  343. $this->assertEquals(count($exp), 3); 
  344. $this->assertEquals($exp[0], $a); 
  345. $this->assertEquals($exp[1], $op); 
  346. $this->assertEquals($exp[2], $b); 
  347.  
  348. public function test_parseExpression_1() { 
  349. $this->parseExpression('aaa', '=', 'b'); 
  350. $this->parseExpression('aaa', '==', 'b'); 
  351. $this->parseExpression('aaa', '===', 'b'); 
  352. $this->parseExpression('aaa', '!=', 'b'); 
  353. $this->parseExpression('aaa', '!==', 'b'); 
  354. $this->parseExpression('aaa', '<>', 'b'); 
  355. $this->parseExpression('aaa', '>=', 'b'); 
  356. $this->parseExpression('aaa', '<=', 'b'); 
  357. $this->parseExpression('aaa', '<', 'b'); 
  358. $this->parseExpression('aaa', '>', 'b'); 
  359.  
  360.  
  361. public function test_hasFilters() { 
  362. $p = new CFDBFilterParser; 
  363. $p->parse('aaa=bbb'); 
  364. //$tree = $p->getFilterTree(); 
  365. $this->assertTrue($p->hasFilters()); 
  366.  
  367. $p->parse('aaa=bbb&&yyy=zzz&&www=xxx||ccc=ddd&&eee=fff&&ggg=hhh'); 
  368. //$tree = $p->getFilterTree(); 
  369. $this->assertTrue($p->hasFilters()); 
  370.  
  371. $p->parse(''); 
  372. //$tree = $p->getFilterTree(); 
  373. $this->assertFalse($p->hasFilters()); 
  374.  
  375. public function test_evaluateLeftOpRightComparison_1() { 
  376. $p = new CFDBFilterParser; 
  377. $this->assertTrue($p->evaluateLeftOpRightComparison('aaa', '=', 'aaa')); 
  378. $this->assertTrue($p->evaluateLeftOpRightComparison(3, '=', 3)); 
  379.  
  380. $this->assertTrue($p->evaluateLeftOpRightComparison('aaa', '==', 'aaa')); 
  381. $this->assertTrue($p->evaluateLeftOpRightComparison(3, '==', 3)); 
  382.  
  383. $this->assertTrue($p->evaluateLeftOpRightComparison('aaa', '===', 'aaa')); 
  384. $this->assertTrue($p->evaluateLeftOpRightComparison(3, '===', 3)); 
  385.  
  386. $this->assertTrue($p->evaluateLeftOpRightComparison('aaa', '!=', 'bbb')); 
  387. $this->assertTrue($p->evaluateLeftOpRightComparison('aaa', '!==', 'bbb')); 
  388. $this->assertTrue($p->evaluateLeftOpRightComparison('aaa', '<>', 'bbb')); 
  389. $this->assertTrue($p->evaluateLeftOpRightComparison('aaa', '!=', 3)); 
  390.  
  391. $this->assertTrue($p->evaluateLeftOpRightComparison(3, '<', 4)); 
  392. $this->assertTrue($p->evaluateLeftOpRightComparison(3, '<=', 4)); 
  393. $this->assertTrue($p->evaluateLeftOpRightComparison(3, '<=', 3)); 
  394.  
  395. $this->assertTrue($p->evaluateLeftOpRightComparison(4, '>', 3)); 
  396. $this->assertTrue($p->evaluateLeftOpRightComparison(4, '>=', 3)); 
  397. $this->assertTrue($p->evaluateLeftOpRightComparison(4, '>=', 4)); 
  398.  
  399.  
  400. public function test_evaluateLeftOpRightComparison_2() { 
  401. $p = new CFDBFilterParser; 
  402. $this->assertFalse($p->evaluateLeftOpRightComparison('aaa', '=', 'bbb')); 
  403. $this->assertFalse($p->evaluateLeftOpRightComparison(3, '=', 4)); 
  404.  
  405. $this->assertFalse($p->evaluateLeftOpRightComparison('aaa', '==', 'bbb')); 
  406. $this->assertFalse($p->evaluateLeftOpRightComparison(3, '==', 4)); 
  407.  
  408. $this->assertFalse($p->evaluateLeftOpRightComparison('aaa', '===', 'bbb')); 
  409. $this->assertFalse($p->evaluateLeftOpRightComparison(3, '===', 4)); 
  410.  
  411. $this->assertFalse($p->evaluateLeftOpRightComparison('aaa', '!=', 'aaa')); 
  412. $this->assertFalse($p->evaluateLeftOpRightComparison('aaa', '!==', 'aaa')); 
  413. $this->assertFalse($p->evaluateLeftOpRightComparison('aaa', '<>', 'aaa')); 
  414. $this->assertFalse($p->evaluateLeftOpRightComparison(3, '!=', 3)); 
  415.  
  416. $this->assertFalse($p->evaluateLeftOpRightComparison(3, '>', 4)); 
  417. $this->assertFalse($p->evaluateLeftOpRightComparison(3, '>=', 4)); 
  418.  
  419. $this->assertFalse($p->evaluateLeftOpRightComparison(4, '<', 3)); 
  420. $this->assertFalse($p->evaluateLeftOpRightComparison(4, '<=', 3)); 
  421.  
  422.  
  423. public function test_evaluateLeftOpRightComparison_badOperator() { 
  424. ini_set('error_reporting', !E_NOTICE & !E_WARNING); 
  425. $p = new CFDBFilterParser; 
  426. //PHPUnit_Framework_Error_Warning::$enabled = FALSE; 
  427. PHPUnit_Framework_Error_Notice::$enabled = FALSE; 
  428. $this->assertFalse($p->evaluateLeftOpRightComparison('aaa', '%', 'aaa')); 
  429.  
  430. public function test_evaluateLeftOpRightComparison_badOperator2() { 
  431. ini_set('error_reporting', !E_NOTICE & !E_WARNING); 
  432. $p = new CFDBFilterParser; 
  433. //PHPUnit_Framework_Error_Warning::$enabled = FALSE; 
  434. PHPUnit_Framework_Error_Notice::$enabled = FALSE; 
  435. $this->assertFalse($p->evaluateLeftOpRightComparison('aaa', null, 'aaa')); 
  436.  
  437. public function test_evaluateLeftOpRightComparison_3() { 
  438. $p = new CFDBFilterParser; 
  439. //PHPUnit_Framework_Error_Warning::$enabled = FALSE; 
  440. PHPUnit_Framework_Error_Notice::$enabled = FALSE; 
  441. $this->assertFalse($p->evaluateLeftOpRightComparison('aaa', '=', null)); 
  442.  
  443. public function test_evaluateLeftOpRightComparison_4() { 
  444. $p = new CFDBFilterParser; 
  445. //PHPUnit_Framework_Error_Warning::$enabled = FALSE; 
  446. PHPUnit_Framework_Error_Notice::$enabled = FALSE; 
  447. $this->assertFalse($p->evaluateLeftOpRightComparison(null, '=', 'aaa')); 
  448.  
  449. public function test_evaluateLeftOpRightComparison_null() { 
  450. $p = new CFDBFilterParser; 
  451. $val = null; 
  452. $this->assertTrue($p->evaluateLeftOpRightComparison($val, '=', 'null')); 
  453.  
  454. $val = 'null'; 
  455. $this->assertFalse($p->evaluateLeftOpRightComparison($val, '=', 'null')); 
  456.  
  457. public function test_evaluate_1t() { 
  458. $p = new CFDBFilterParser; 
  459. $p->parse('aaa=bbb'); 
  460. $data = array('aaa' => 'bbb'); 
  461. $this->assertTrue($p->evaluate($data)); 
  462.  
  463. public function test_evaluate_1f() { 
  464. $p = new CFDBFilterParser; 
  465. $p->parse('aaa=bbb'); 
  466. $data = array('aaa' => 'xxx'); 
  467. $this->assertFalse($p->evaluate($data)); 
  468.  
  469. public function test_evaluate_2tOR() { 
  470. $p = new CFDBFilterParser; 
  471. $p->parse('aaa=bbb||ccc=ddd'); 
  472. $data = array('aaa' => 'bbb', 'ccc' => 'ddd'); 
  473. $this->assertTrue($p->evaluate($data)); 
  474.  
  475. public function test_evaluate_2tAND() { 
  476. $p = new CFDBFilterParser; 
  477. $p->parse('aaa=bbb&&ccc=ddd'); 
  478. $data = array('aaa' => 'bbb', 'ccc' => 'ddd'); 
  479. $this->assertTrue($p->evaluate($data)); 
  480.  
  481. public function test_evaluate_2f() { 
  482. $p = new CFDBFilterParser; 
  483. $p->parse('aaa=xxx&&ccc=ddd'); 
  484. $data = array('aaa' => 'bbb', 'ccc' => 'ddd'); 
  485. $this->assertFalse($p->evaluate($data)); 
  486.  
  487. public function test_evaluate_3() { 
  488. $p = new CFDBFilterParser; 
  489. // no filters added 
  490. $data = array('aaa' => 'bbb'); 
  491. $this->assertTrue($p->evaluate($data)); 
  492.  
  493. public function test_evaluate_4() { 
  494. $p = new CFDBFilterParser; 
  495. $p->parse('aaa=xxx||ccc=ddd'); 
  496. $data = array('aaa' => 'bbb', 'ccc' => 'ddd'); 
  497. $this->assertTrue($p->evaluate($data)); 
  498.  
  499.  
  500. public function test_evaluate_5() { 
  501. $p = new CFDBFilterParser; 
  502. $p->parse('aaa=bbb&&yyy=zzz&&www=xxx||ccc=ddd&&eee=fff&&ggg=hhh'); 
  503.  
  504. $data = array( 
  505. 'aaa' => 'bbb',  
  506. 'yyy' => 'zzz',  
  507. 'www' => 'xxx',  
  508.  
  509. 'ccc' => 'ddd',  
  510. 'eee' => 'fff',  
  511. 'ggg' => 'hhh',  
  512. ); 
  513. $this->assertTrue($p->evaluate($data)); 
  514.  
  515. public function test_evaluate_6() { 
  516. $p = new CFDBFilterParser; 
  517. $p->parse('aaa=bbb&&yyy=zzz&&www=xxx||ccc=ddd&&eee=fff&&ggg=hhh'); 
  518.  
  519. $data = array( 
  520. 'aaa' => 'XXXX',  
  521. 'yyy' => 'zzz',  
  522. 'www' => 'xxx',  
  523.  
  524. 'ccc' => 'ddd',  
  525. 'eee' => 'fff',  
  526. 'ggg' => 'hhh',  
  527. ); 
  528. $this->assertTrue($p->evaluate($data)); 
  529.  
  530. public function test_evaluate_7() { 
  531. $p = new CFDBFilterParser; 
  532. $p->parse('aaa=bbb&&yyy=zzz&&www=xxx||ccc=ddd&&eee=fff&&ggg=hhh'); 
  533.  
  534. $data = array( 
  535. 'aaa' => 'XXXX',  
  536. 'yyy' => 'XXXX',  
  537. 'www' => 'XXXX',  
  538.  
  539. 'ccc' => 'ddd',  
  540. 'eee' => 'fff',  
  541. 'ggg' => 'hhh',  
  542. ); 
  543. $this->assertTrue($p->evaluate($data)); 
  544.  
  545. public function test_evaluate_8() { 
  546. $p = new CFDBFilterParser; 
  547. $p->parse('aaa=bbb&&yyy=zzz&&www=xxx||ccc=ddd&&eee=fff&&ggg=hhh'); 
  548.  
  549. $data = array( 
  550. 'aaa' => 'XXXX',  
  551. 'yyy' => 'zzz',  
  552. 'www' => 'xxx',  
  553.  
  554. 'ccc' => 'XXXX',  
  555. 'eee' => 'fff',  
  556. 'ggg' => 'hhh',  
  557. ); 
  558. $this->assertFalse($p->evaluate($data)); 
  559.  
  560.  
  561. public function test_evaluate_9() { 
  562. $p = new CFDBFilterParser; 
  563. $p->parse('aaa>3'); 
  564. $data = array('aaa' => 4); 
  565. $this->assertTrue($p->evaluate($data)); 
  566.  
  567. public function test_evaluate_nullValue() { 
  568. $p = new CFDBFilterParser; 
  569. $p->parse('aaa=null&&yyy=zzz'); 
  570.  
  571. $data = array( 
  572. //'aaa' => 'bbb',  
  573. 'yyy' => 'zzz' 
  574. ); 
  575. $this->assertTrue($p->evaluate($data)); 
  576.  
  577. public function test_evaluate_nullValue2() { 
  578. $p = new CFDBFilterParser; 
  579. $p->parse('aaa=null&&yyy=zzz'); 
  580.  
  581. $data = array( 
  582. 'aaa' => 'null',  
  583. 'yyy' => 'zzz' 
  584. ); 
  585. $this->assertFalse($p->evaluate($data)); 
  586.  
  587. public function test_evaluate_regex1() { 
  588. $p = new CFDBFilterParser; 
  589. $p->parse('aaa~~/^b/'); 
  590. $data = array('aaa' => 'bbbb'); 
  591. $this->assertTrue($p->evaluate($data)); 
  592.  
  593. public function test_evaluate_regex2() { 
  594. $p = new CFDBFilterParser; 
  595. $p->parse('aaa~~/^b/'); 
  596. $data = array('aaa' => 'abbb'); 
  597. $this->assertFalse($p->evaluate($data)); 
  598.  
  599.  
  600. public function test_setComparisonValuePreprocessor1() { 
  601. $p = new CFDBFilterParser; 
  602. $p->setComparisonValuePreprocessor(new ChangeNameToValue('$stuff', 'AAA')); 
  603. $p->parse('aaa=$stuff'); 
  604. $data = array('aaa' => 'AAA'); 
  605. $this->assertTrue($p->evaluate($data)); 
  606.  
  607. public function test_setComparisonValuePreprocessor2() { 
  608. $p = new CFDBFilterParser; 
  609. $p->setComparisonValuePreprocessor(new ChangeNameToValue('$stuff', 'AAA')); 
  610. $p->parse('aaa=$stuff'); 
  611. $data = array('aaa' => 'BBB'); 
  612. $this->assertFalse($p->evaluate($data)); 
  613.  
  614. public function test_setComparisonValuePreprocessor3() { 
  615. $p = new CFDBFilterParser; 
  616. $p->setComparisonValuePreprocessor(new ChangeUserVar); 
  617. $data = array('your-message' => 'admin',  
  618. 'your-email' => 'mike@simpson-software-studio.com'); 
  619.  
  620. $p->parse('your-email=$user_email'); 
  621. $this->assertTrue($p->evaluate($data)); 
  622.  
  623. $p->parse('your-message=$user_login'); 
  624. $this->assertTrue($p->evaluate($data)); 
  625.  
  626. $p->parse('your-message=$user_login&&your-email=$user_email'); 
  627. $this->assertTrue($p->evaluate($data)); 
  628.  
  629. $p->parse('your-message=$user_login||your-email=$user_email'); 
  630. $this->assertTrue($p->evaluate($data)); 
  631.  
  632. $p->parse('your-message=$user_login||your-email!=$user_email'); 
  633. $this->assertTrue($p->evaluate($data)); 
  634.  
  635. $p->parse('your-message=$user_login&&your-email!=$user_email'); 
  636. $this->assertFalse($p->evaluate($data)); 
  637.  
  638.  
  639. public function test_submit_time() { 
  640. $p = new CFDBFilterParser; 
  641. $p->parse('submit_time=1305930218.2452'); 
  642. $data = array('submit_time' => '1305930218.2452'); 
  643. $this->assertTrue($p->evaluate($data)); 
  644.  
  645. $p = new CFDBFilterParser; 
  646. $p->parse('submit_time=1305930218.2452'); 
  647. $data = array('submit_time' => '1305930218.9999'); 
  648. $this->assertFalse($p->evaluate($data)); 
  649.  
  650. $p = new CFDBFilterParser; 
  651. $p->parse('submit_time<1305930218.9999'); 
  652. $data = array('submit_time' => '1305930218.2452'); 
  653. $this->assertTrue($p->evaluate($data)); 
  654.  
  655. $p = new CFDBFilterParser; 
  656. $p->parse('submit_time<=1305930218.9999'); 
  657. $data = array('submit_time' => '1305930218.2452'); 
  658. $this->assertTrue($p->evaluate($data)); 
  659.  
  660.  
  661. $p = new CFDBFilterParser; 
  662. $p->parse('submit_time>1305930218'); 
  663. $data = array('submit_time' => '1305930218.2452'); 
  664. $this->assertTrue($p->evaluate($data)); 
  665.  
  666.  
  667.  
  668. public function test_submit_time_with_relative() { 
  669. date_default_timezone_set('America/New_York'); 
  670. $p = new CFDBFilterParser; 
  671. $p->parse('submit_time<8 weeks ago'); 
  672.  
  673. $nineWeeksAgo = microtime(true) - (60 * 60 * 24 * 7 * 9); 
  674. $data = array('submit_time' => $nineWeeksAgo); 
  675. $this->assertTrue($p->evaluate($data)); 
  676.  
  677. $twoWeeksAgo = microtime(true) - (60 * 60 * 24 * 7 * 2); 
  678. $data = array('submit_time' => $twoWeeksAgo); 
  679. $this->assertFalse($p->evaluate($data)); 
  680.  
  681. public function test_preg_split() { 
  682. //$comparisonExpression = 'submit_time<=1305930218.2452'; 
  683. $comparisonExpression = 'submit_time<=1305930218.2452'; 
  684.  
  685. $p = new CFDBFilterParser; 
  686. $p->setComparisonValuePreprocessor(new DereferenceShortcodeVars); 
  687. $p->parse($comparisonExpression); 
  688. // echo '<pre>'; print_r($p->tree); echo '</pre>'; 
  689. $this->assertEquals('<=', $p->tree[0][0][1]); 
  690.  
  691. $comparisonExpression = 'submit_time>=1305930218.2452'; 
  692. $p->parse($comparisonExpression); 
  693. $this->assertEquals('>=', $p->tree[0][0][1]); 
  694.  
  695. public function test_evaluateLeftOpRightComparison_float() { 
  696. $p = new CFDBFilterParser; 
  697. $this->assertTrue($p->evaluateLeftOpRightComparison('1305589311.4503', '<', '1305589312.4503')); 
  698. $this->assertFalse($p->evaluateLeftOpRightComparison('1305589311.4503', '<', '1305589310.4503')); 
  699.  
  700. $this->assertFalse($p->evaluateLeftOpRightComparison('1305589311.4503', '>', '13055893109999.4503')); 
  701.  
  702. public function test_conversion_float() { 
  703. // $i = (float)'1305589311.4503'; 
  704. // $j = (float)'Mike'; // becomes 0 
  705. // echo "$i, $j"; 
  706.  
  707. $k = '1305589311.4503'; 
  708. $this->assertTrue((float)$k == $k); 
  709.  
  710. // $m = 'Mike'; 
  711. // $this->assertFalse((float)$m == $m); 
  712.  
  713.  
  714. $this->assertTrue(is_numeric('1305589311.4503')); 
  715.  
  716. public function testQuarterHouseAND() 
  717. $filterText = 'Week Number?=52&&Year=2015'; 
  718. $filters = preg_split('/&&|\|\|/', $filterText, -1, PREG_SPLIT_NO_EMPTY); 
  719.  
  720. $this->assertEquals('Week Number?=52', $filters[0]); 
  721. $this->assertEquals('Year=2015', $filters[1]); 
  722. //print_r($filters); 
  723.  
  724. public function testQuarterHouseAND_2() 
  725. $filterText = 'Week Number?=52&&Year=2015'; 
  726. $filters = explode('&&', $filterText); 
  727.  
  728. $this->assertEquals('Week Number?=52', $filters[0]); 
  729. $this->assertEquals('Year=2015', $filters[1]); 
  730. //print_r($filters); 
  731.  
  732. public function testQuarterHouse() 
  733.  
  734. $filterText = 'Week Number?=52&&Year=2015'; 
  735. $p = new CFDBFilterParser; 
  736. $p->parse($filterText); 
  737.  
  738. print_r($p->getFilterTree()); 
  739.  
  740. $data = array( 
  741. 'Week Number?' => '52',  
  742. 'Year' => '2015' 
  743. ); 
  744. $this->assertTrue($p->evaluate($data)); 
  745.  
  746. public function testParseFunction_noParams1() { 
  747. $filterText = 'funct()'; 
  748. $p = new CFDBFilterParser; 
  749. $array = $p->parseFunction($filterText); 
  750. $this->assertEquals('funct', $array[0]); 
  751. $this->assertEquals(1, count($array)); 
  752.  
  753. public function testParseFunction_noParams2() { 
  754. $filterText = 'funct( )'; 
  755. $p = new CFDBFilterParser; 
  756. $array = $p->parseFunction($filterText); 
  757. $this->assertEquals('funct', $array[0]); 
  758. $this->assertEquals(1, count($array)); 
  759. public function testParseFunction_noParams3() { 
  760. $filterText = ' funct()'; 
  761. $p = new CFDBFilterParser; 
  762. $array = $p->parseFunction($filterText); 
  763. $this->assertEquals('funct', $array[0]); 
  764. $this->assertEquals(1, count($array)); 
  765.  
  766. public function testParseFunction_noParams4() { 
  767. $filterText = 'funct() '; 
  768. $p = new CFDBFilterParser; 
  769. $array = $p->parseFunction($filterText); 
  770. $this->assertEquals('funct', $array[0]); 
  771. $this->assertEquals(1, count($array)); 
  772.  
  773. public function testParseFunction_noParams5() { 
  774. $filterText = ' funct( ) '; 
  775. $p = new CFDBFilterParser; 
  776. $array = $p->parseFunction($filterText); 
  777. $this->assertEquals('funct', $array[0]); 
  778. $this->assertEquals(1, count($array)); 
  779.  
  780. public function testParseFunction_1param() { 
  781. $filterText = 'funct(hello)'; 
  782. $p = new CFDBFilterParser; 
  783. $array = $p->parseFunction($filterText); 
  784. $this->assertEquals('funct', $array[0]); 
  785. $this->assertEquals('hello', $array[1]); 
  786. $this->assertEquals(2, count($array)); 
  787.  
  788. public function testParseFunction_2param() { 
  789. $filterText = 'funct(hello, there)'; 
  790. $p = new CFDBFilterParser; 
  791. $array = $p->parseFunction($filterText); 
  792. $this->assertEquals('funct', $array[0]); 
  793. $this->assertEquals('hello', $array[1]); 
  794. $this->assertEquals($array[2], 'there'); 
  795. $this->assertEquals(3, count($array)); 
  796.  
  797. public function testParseFunction_2param_spaces1() { 
  798. $filterText = 'funct(hello, there)'; 
  799. $p = new CFDBFilterParser; 
  800. $array = $p->parseFunction($filterText); 
  801. $this->assertEquals('funct', $array[0]); 
  802. $this->assertEquals('hello', $array[1]); 
  803. $this->assertEquals('there', $array[2]); 
  804. $this->assertEquals(3, count($array)); 
  805.  
  806. public function testParseFunction_2param_spaces2() { 
  807. $filterText = ' funct( hello , there )'; 
  808. $p = new CFDBFilterParser; 
  809. $array = $p->parseFunction($filterText); 
  810. $this->assertEquals('funct', $array[0]); 
  811. $this->assertEquals('hello', $array[1]); 
  812. $this->assertEquals('there', $array[2]); 
  813. $this->assertEquals(3, count($array)); 
  814.  
  815. public function testParseFunction_3param() { 
  816. $filterText = 'funct(hello, there, buddy)'; 
  817. $p = new CFDBFilterParser; 
  818. $array = $p->parseFunction($filterText); 
  819. $this->assertEquals('funct', $array[0]); 
  820. $this->assertEquals('hello', $array[1]); 
  821. $this->assertEquals('there', $array[2]); 
  822. $this->assertEquals('buddy', $array[3]); 
  823. $this->assertEquals(4, count($array)); 
  824.  
  825. public function testParseFunction_POST() { 
  826. $filterText = 'funct($_POST(lname))'; 
  827. $p = new CFDBFilterParser; 
  828. $array = $p->parseFunction($filterText); 
  829. $this->assertEquals('funct', $array[0]); 
  830. $this->assertEquals('$_POST(lname)', $array[1]); 
  831. $this->assertEquals(2, count($array)); 
  832.  
  833. public function testParseFunction_POST2() { 
  834. $filterText = 'funct($_POST(lname), $_GET(fname))'; 
  835. $p = new CFDBFilterParser; 
  836. $array = $p->parseFunction($filterText); 
  837. $this->assertEquals('funct', $array[0]); 
  838. $this->assertEquals('$_POST(lname)', $array[1]); 
  839. $this->assertEquals('$_GET(fname)', $array[2]); 
  840. $this->assertEquals(3, count($array)); 
  841.  
  842. public function testParseFunction_danglingParam() { 
  843. $filterText = 'funct(hello, there, buddy, )'; 
  844. $p = new CFDBFilterParser; 
  845. $array = $p->parseFunction($filterText); 
  846. $this->assertEquals('funct', $array[0]); 
  847. $this->assertEquals('hello', $array[1]); 
  848. $this->assertEquals('there', $array[2]); 
  849. $this->assertEquals('buddy', $array[3]); 
  850. $this->assertEquals(4, count($array)); 
  851.  
  852. public function testParseFunction_danglingParam2() { 
  853. $filterText = 'funct(hello, there, buddy, )'; 
  854. $p = new CFDBFilterParser; 
  855. $array = $p->parseFunction($filterText); 
  856. $this->assertEquals('funct', $array[0]); 
  857. $this->assertEquals('hello', $array[1]); 
  858. $this->assertEquals('there', $array[2]); 
  859. $this->assertEquals('buddy', $array[3]); 
  860. $this->assertEquals(4, count($array)); 
  861.  
  862. public function testParseFunction_danglingParam3() { 
  863. $filterText = 'funct(, hello, there, buddy, )'; 
  864. $p = new CFDBFilterParser; 
  865. $array = $p->parseFunction($filterText); 
  866. $this->assertEquals('funct', $array[0]); 
  867. $this->assertEquals('hello', $array[1]); 
  868. $this->assertEquals('there', $array[2]); 
  869. $this->assertEquals('buddy', $array[3]); 
  870. $this->assertEquals(4, count($array)); 
  871.  
  872. public function testParseFunction_danglingParam4() { 
  873. $filterText = 'funct(, hello, there, buddy, )'; 
  874. $p = new CFDBFilterParser; 
  875. $array = $p->parseFunction($filterText); 
  876. $this->assertEquals('funct', $array[0]); 
  877. $this->assertEquals('hello', $array[1]); 
  878. $this->assertEquals('there', $array[2]); 
  879. $this->assertEquals('buddy', $array[3]); 
  880. $this->assertEquals(4, count($array)); 
  881.  
  882. public function testParseFunction_danglingParam5() { 
  883. $filterText = 'funct(, hello, , there, , buddy, )'; 
  884. $p = new CFDBFilterParser; 
  885. $array = $p->parseFunction($filterText); 
  886. $this->assertEquals('funct', $array[0]); 
  887. $this->assertEquals('hello', $array[1]); 
  888. $this->assertEquals('there', $array[2]); 
  889. $this->assertEquals('buddy', $array[3]); 
  890. $this->assertEquals(4, count($array)); 
  891.  
  892.  
  893. public function test_parse_function() { 
  894. $p = new CFDBFilterParser; 
  895. $p->parse('aaa=AAA&&yyy=strtoupper(zzz)'); 
  896.  
  897. $this->assertEquals('aaa', $p->tree[0][0][0]); 
  898. $this->assertEquals('=', $p->tree[0][0][1]); 
  899. $this->assertEquals('AAA', $p->tree[0][0][2]); 
  900.  
  901. $this->assertEquals('yyy', $p->tree[0][1][0]); 
  902. $this->assertEquals('=', $p->tree[0][1][1]); 
  903. $this->assertEquals('strtoupper', $p->tree[0][1][2][0]); 
  904. $this->assertEquals('zzz', $p->tree[0][1][2][1]); 
  905.  
  906. public function test_evaluate_unknown_function() { 
  907. $p = new CFDBFilterParser; 
  908. $p->parse('aaa=AAA&&yyy=hello(zzz)'); 
  909.  
  910. $this->assertEquals('aaa', $p->tree[0][0][0]); 
  911. $this->assertEquals('=', $p->tree[0][0][1]); 
  912. $this->assertEquals('AAA', $p->tree[0][0][2]); 
  913.  
  914. $this->assertEquals('yyy', $p->tree[0][1][0]); 
  915. $this->assertEquals('=', $p->tree[0][1][1]); 
  916. $this->assertEquals('hello(zzz)', $p->tree[0][1][2]); 
  917.  
  918. public function test_parse_function_injected_boolean() { 
  919. $p = new CFDBFilterParser; 
  920. $p->parse('aaa=AAA&&strtoupper(zzz)'); 
  921.  
  922. $this->assertEquals('aaa', $p->tree[0][0][0]); 
  923. $this->assertEquals('=', $p->tree[0][0][1]); 
  924. $this->assertEquals('AAA', $p->tree[0][0][2]); 
  925.  
  926. $this->assertEquals('strtoupper', $p->tree[0][1][0][0]); 
  927. $this->assertEquals('zzz', $p->tree[0][1][0][1]); 
  928. $this->assertEquals('==', $p->tree[0][1][1]); // sets the operator 
  929. $this->assertEquals(true, $p->tree[0][1][2]); 
  930.  
  931. public function test_parse_function_boolean_true() { 
  932. $p = new CFDBFilterParser; 
  933. $p->parse('aaa=AAA&&true=strtoupper(zzz)'); 
  934.  
  935. $this->assertEquals('aaa', $p->tree[0][0][0]); 
  936. $this->assertEquals('=', $p->tree[0][0][1]); 
  937. $this->assertEquals('AAA', $p->tree[0][0][2]); 
  938.  
  939. $this->assertEquals(true, $p->tree[0][1][0]); 
  940. $this->assertEquals('=', $p->tree[0][1][1]); 
  941. $this->assertEquals('strtoupper', $p->tree[0][1][2][0]); 
  942. $this->assertEquals('zzz', $p->tree[0][1][2][1]); 
  943.  
  944. public function test_parse_function_boolean_false() { 
  945. $p = new CFDBFilterParser; 
  946. $p->parse('aaa=AAA&&false=strtoupper(zzz)'); 
  947.  
  948. $this->assertEquals('aaa', $p->tree[0][0][0]); 
  949. $this->assertEquals('=', $p->tree[0][0][1]); 
  950. $this->assertEquals('AAA', $p->tree[0][0][2]); 
  951.  
  952. $this->assertEquals(false, $p->tree[0][1][0]); 
  953. $this->assertEquals('=', $p->tree[0][1][1]); 
  954. $this->assertEquals('strtoupper', $p->tree[0][1][2][0]); 
  955. $this->assertEquals('zzz', $p->tree[0][1][2][1]); 
  956.  
  957. public function test_parse_function_boolean_true2() { 
  958. $p = new CFDBFilterParser; 
  959. $p->parse('aaa=AAA&&strtoupper(zzz)=true'); 
  960.  
  961. $this->assertEquals('aaa', $p->tree[0][0][0]); 
  962. $this->assertEquals('=', $p->tree[0][0][1]); 
  963. $this->assertEquals('AAA', $p->tree[0][0][2]); 
  964.  
  965. $this->assertEquals('strtoupper', $p->tree[0][1][0][0]); 
  966. $this->assertEquals('zzz', $p->tree[0][1][0][1]); 
  967. $this->assertEquals('=', $p->tree[0][1][1]); 
  968. $this->assertEquals(true, $p->tree[0][1][2]); 
  969.  
  970. public function test_parse_function_boolean_false2() { 
  971. $p = new CFDBFilterParser; 
  972. $p->parse('aaa=AAA&&strtoupper(zzz)=false'); 
  973.  
  974. $this->assertEquals('aaa', $p->tree[0][0][0]); 
  975. $this->assertEquals('=', $p->tree[0][0][1]); 
  976. $this->assertEquals('AAA', $p->tree[0][0][2]); 
  977.  
  978. $this->assertEquals('strtoupper', $p->tree[0][1][0][0]); 
  979. $this->assertEquals('zzz', $p->tree[0][1][0][1]); 
  980. $this->assertEquals('=', $p->tree[0][1][1]); 
  981. $this->assertEquals(false, $p->tree[0][1][2]); 
  982.  
  983. public function test_evaluate_function_1() { 
  984. $p = new CFDBFilterParser; 
  985. $p->parse('fname=AAA&&strtoupper(lname)=ZZZ'); 
  986. $data = array('fname' => 'AAA'); 
  987. $this->assertFalse($p->evaluate($data)); 
  988.  
  989. public function test_evaluate_function_1_1() { 
  990. $p = new CFDBFilterParser; 
  991. $p->parse('fname=AAA&&strtoupper(zzz)=ZZZ'); 
  992. $data = array('fname' => 'AAA'); 
  993. $this->assertTrue($p->evaluate($data)); 
  994.  
  995. public function test_evaluate_function_1_2() { 
  996. $p = new CFDBFilterParser; 
  997. $p->parse('fname=AAA&&strtoupper(lname)=ZZZ'); 
  998. $data = array('fname' => 'AAA',  
  999. 'lname' => 'zzz'); 
  1000. $this->assertTrue($p->evaluate($data)); 
  1001.  
  1002. public function test_evaluate_function_2() { 
  1003. $p = new CFDBFilterParser; 
  1004. $p->parse('fname=AAA&&is_numeric(lname)'); 
  1005. $data = array('fname' => 'AAA',  
  1006. 'lname' => '123'); 
  1007. $this->assertTrue($p->evaluate($data)); 
  1008.  
  1009. public function test_evaluate_function_2_1() { 
  1010. $p = new CFDBFilterParser; 
  1011. $p->parse('fname=AAA&&true=is_numeric(lname)'); 
  1012. $data = array('fname' => 'AAA',  
  1013. 'lname' => '123'); 
  1014. $this->assertTrue($p->evaluate($data)); 
  1015.  
  1016. public function test_evaluate_function_2_2() { 
  1017. $p = new CFDBFilterParser; 
  1018. $p->parse('fname=AAA&&false=is_numeric(lname)'); 
  1019. $data = array('fname' => 'AAA',  
  1020. 'lname' => 'abc'); 
  1021. $this->assertTrue($p->evaluate($data)); 
  1022.  
  1023. public function test_evaluate_function_2_3() { 
  1024. $p = new CFDBFilterParser; 
  1025. $p->parse('fname=AAA&&is_numeric(lname)=true'); 
  1026. $data = array('fname' => 'AAA',  
  1027. 'lname' => '123'); 
  1028. $this->assertTrue($p->evaluate($data)); 
  1029.  
  1030. public function test_evaluate_function_2_3_1() { 
  1031. $p = new CFDBFilterParser; 
  1032. $p->parse('fname=AAA&&is_numeric(lname)=true'); 
  1033. $data = array('fname' => 'AAA',  
  1034. 'lname' => 'abc'); 
  1035. $this->assertFalse($p->evaluate($data)); 
  1036.  
  1037. public function test_evaluate_function_2_4() { 
  1038. $p = new CFDBFilterParser; 
  1039. $p->parse('fname=AAA&&is_numeric(lname)=false'); 
  1040. $data = array('fname' => 'AAA',  
  1041. 'lname' => 'abc'); 
  1042. $this->assertTrue($p->evaluate($data)); 
  1043.  
  1044. public function test_evaluate_function_2_4_1() { 
  1045. $p = new CFDBFilterParser; 
  1046. $p->parse('fname=AAA&&is_numeric(lname)=false'); 
  1047. $data = array('fname' => 'AAA',  
  1048. 'lname' => '123'); 
  1049. $this->assertFalse($p->evaluate($data)); 
  1050.  
  1051. public function test_login_name() { 
  1052. //Submitted Login = $user_login with no data value for Submitted Login and not logged in 
  1053. $p = new CFDBFilterParser; 
  1054. $p->setComparisonValuePreprocessor(new ChangeNameToValue('$user_login', 'msimpson')); 
  1055.  
  1056. $p->parse('Submitted Login=$user_login'); 
  1057. $data = array('Submitted Login' => 'msimpson'); 
  1058. $this->assertTrue($p->evaluate($data)); 
  1059.  
  1060. public function test_login_name2() { 
  1061. //Submitted Login = $user_login with no data value for Submitted Login and not logged in 
  1062. $p = new CFDBFilterParser; 
  1063. $p->setComparisonValuePreprocessor(new ChangeNameToValue('$user_login', 'msimpson')); 
  1064.  
  1065. $p->parse('Submitted Login=$user_login'); 
  1066. $data = array('Submitted Login' => 'admin'); 
  1067. $this->assertFalse($p->evaluate($data)); 
  1068.  
  1069. public function test_no_login() { 
  1070. //Submitted Login = $user_login with no data value for Submitted Login and not logged in 
  1071. $p = new CFDBFilterParser; 
  1072. $p->setComparisonValuePreprocessor(new ChangeNameToValue('$user_login', null)); 
  1073.  
  1074. $p->parse('Submitted Login=$user_login'); 
  1075. $data = array(); 
  1076. $this->assertFalse($p->evaluate($data)); 
  1077.  
  1078. public function test_null_field() { 
  1079. $p = new CFDBFilterParser; 
  1080. $p->parse('field=null'); 
  1081. $data = array(); 
  1082. $this->assertTrue($p->evaluate($data)); 
  1083.  
  1084. public function test_constants_params() { 
  1085. $p = new CFDBFilterParser; 
  1086. $p->parse('str_pad(field, 10, ., STR_PAD_BOTH)=..hello...'); 
  1087. $data = array('field' =>'hello'); 
  1088. $this->assertTrue($p->evaluate($data)); 
  1089.  
  1090. public function test_filterTrue() { 
  1091. $p = new CFDBFilterParser; 
  1092. $p->parse('filterTrue()'); 
  1093. print_r($p->tree); 
  1094. $data = array('field' =>'hello'); 
  1095. $this->assertTrue($p->evaluate($data)); 
  1096.  
  1097. public function test_filterTrueEqualsTrue() { 
  1098. $p = new CFDBFilterParser; 
  1099. $p->parse('filterTrue()=true'); 
  1100. print_r($p->tree); 
  1101. $data = array('field' =>'hello'); 
  1102. $this->assertTrue($p->evaluate($data)); 
  1103.  
  1104. public function test_filterTrueEqualsTrue2() { 
  1105. $p = new CFDBFilterParser; 
  1106. $p->parse('true=filterTrue()'); 
  1107. print_r($p->tree); 
  1108. $data = array('field' =>'hello'); 
  1109. $this->assertTrue($p->evaluate($data)); 
  1110.  
  1111. public function test_filterFalse() { 
  1112. $p = new CFDBFilterParser; 
  1113. $p->parse('filterFalse()'); 
  1114. print_r($p->tree); 
  1115. $data = array('field' =>'hello'); 
  1116. $this->assertFalse($p->evaluate($data)); 
  1117.  
  1118. public function test_filterFalseEqualFalse() { 
  1119. $p = new CFDBFilterParser; 
  1120. $p->parse('filterFalse()=false'); 
  1121. print_r($p->tree); 
  1122. $data = array('field' =>'hello'); 
  1123. $this->assertTrue($p->evaluate($data)); 
  1124.  
  1125. public function test_filterFalseEqualFalse2() { 
  1126. $p = new CFDBFilterParser; 
  1127. $p->parse('false=filterFalse()'); 
  1128. print_r($p->tree); 
  1129. $data = array('field' =>'hello'); 
  1130. $this->assertTrue($p->evaluate($data)); 
  1131.  
  1132. public function test_blank_values() { 
  1133. global $_POST; 
  1134. $_POST = array('aname' => 'Simpson', 'subject' => 'hello'); 
  1135. $p = new CFDBFilterParser; 
  1136. $p->setComparisonValuePreprocessor(new DereferenceShortcodeVars()); 
  1137. $p->parse('your-name=$_POST(aname)&&your-subject=$_POST(subject)'); 
  1138. print_r($p->tree); 
  1139.  
  1140. $this->assertEquals('your-name', $p->tree[0][0][0]); 
  1141. $this->assertEquals('=', $p->tree[0][0][1]); 
  1142. $this->assertEquals('$_POST(aname)', $p->tree[0][0][2]); 
  1143.  
  1144. $this->assertEquals('your-subject', $p->tree[0][1][0]); 
  1145. $this->assertEquals('=', $p->tree[0][1][1]); 
  1146. $this->assertEquals('$_POST(subject)', $p->tree[0][1][2]); 
  1147.