DereferenceShortcodeVars_ExportTest

The Contact Form DB DereferenceShortcodeVars ExportTest class.

Defined (1)

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

/phpunit/DereferenceShortcodeVars_ExportTest.php  
  1. class DereferenceShortcodeVars_ExportTest extends PHPUnit_Framework_TestCase { 
  2.  
  3. public function setUp() { 
  4. global $_POST; 
  5. $_POST = array(); 
  6.  
  7. public function dataProviderReplace() { 
  8. $data = array(); 
  9. $data[] = array('debug', 'true'); 
  10. $data[] = array('unbuffered', 'true'); 
  11. $data[] = array('class', 'myclass'); 
  12. $data[] = array('style', 'mystyle'); 
  13. $data[] = array('id', 'myid'); 
  14. $data[] = array('permissionmsg', 'false'); 
  15. $data[] = array('orderby', 'name'); 
  16. $data[] = array('orderby', 'name DESC'); 
  17. $data[] = array('limit', '10'); 
  18. $data[] = array('limit', '20, 10'); 
  19. $data[] = array('tlimit', '10'); 
  20. $data[] = array('tlimit', '20, 10'); 
  21. $data[] = array('header', 'true'); 
  22. $data[] = array('filter', 'name=Simpson'); 
  23. $data[] = array('tfilter', 'name=Simpson'); 
  24. $data[] = array('search', 'Simpson'); 
  25. $data[] = array('tsearch', 'Simpson'); 
  26. $data[] = array('trans', 'name=Simpson'); 
  27. return $data; 
  28.  
  29. /** 
  30. * @dataProvider dataProviderReplace 
  31. */ 
  32. public function test_general_option($name, $value) { 
  33. $options = array(); 
  34. $exp = new ExportBase; 
  35. $exp->setOptions($options); 
  36.  
  37. $options[$name] = '$_POST(' .$name .')'; 
  38. $_POST[$name] = $value; 
  39. $exp->setOptions($options); 
  40. $exp->setCommonOptions(true); 
  41. $this->assertEquals($value, $exp->options[$name], "$name=$value"); 
  42.  
  43. public function test_show() { 
  44. $options = array(); 
  45. $exp = new ExportBase; 
  46. $exp->setOptions($options); 
  47.  
  48. $options['show'] = 's1, s2, s3, $_POST(s), s6'; 
  49. $_POST['s'] = 's4, s5'; 
  50. $exp->setOptions($options); 
  51. $exp->setCommonOptions(true); 
  52. $this->assertEquals(explode(', ', 's1, s2, s3, s4, s5, s6'), $exp->showColumns); 
  53.  
  54. public function test_hide() { 
  55. $options = array(); 
  56. $exp = new ExportBase; 
  57. $exp->setOptions($options); 
  58.  
  59. $options['hide'] = 'h1, h2, h3, $_POST(h), h6'; 
  60. $_POST['h'] = 'h4, h5'; 
  61. $exp->setOptions($options); 
  62. $exp->setCommonOptions(true); 
  63. $this->assertEquals(explode(', ', 'h1, h2, h3, h4, h5, h6'), $exp->hideColumns); 
  64.  
  65. public function test_headers() { 
  66. $options = array(); 
  67. $exp = new ExportBase; 
  68. $exp->setOptions($options); 
  69.  
  70. $options['headers'] = 'h1=$_POST(h1), h2=$_POST(h2), h3=H_3'; 
  71. $_POST['h1'] = 'H_1'; 
  72. $_POST['h2'] = 'H_2'; 
  73. $exp->setOptions($options); 
  74. $exp->setCommonOptions(true); 
  75. $this->assertEquals( 
  76. array( 
  77. 'h1' => 'H_1',  
  78. 'h2' => 'H_2',  
  79. 'h3' => 'H_3',  
  80. ),  
  81. $exp->headers); 
  82.  
  83.  
  84. public function dataProviderNoReplace() { 
  85. $data = array(); 
  86. $data[] = array('role', 'Anyone'); 
  87. $data[] = array('fromshortcode', 'name=Simpson'); 
  88. return $data; 
  89.  
  90. /** 
  91. * @dataProvider dataProviderNoReplace 
  92. */ 
  93. public function test_general_option_no_replace($name, $value) { 
  94. $options = array(); 
  95. $exp = new ExportBase; 
  96.  
  97. $options[$name] = '$_POST(' .$name .')'; 
  98. $_POST[$name] = $value; 
  99. $exp->setOptions($options); 
  100. $exp->setCommonOptions(true); 
  101. // No replacement expected 
  102. $this->assertEquals('$_POST(' .$name .')', $exp->options[$name], "$name=$value"); 
  103.  
  104. public function test_post_vars() { 
  105. $options = array(); 
  106. $exp = new ExportBase; 
  107.  
  108. $options['debug'] = 'true'; 
  109. $options['filter'] = 'your-name=$_POST(aname)&&your-subject=$_POST(subject)'; 
  110. $exp->setOptions($options); 
  111. $exp->setCommonOptions(true); 
  112.  
  113. print_r($exp->rowFilter->tree); 
  114. $this->assertEquals('your-name', $exp->rowFilter->tree[0][0][0]); 
  115. $this->assertEquals('=', $exp->rowFilter->tree[0][0][1]); 
  116. $this->assertEquals('', $exp->rowFilter->tree[0][0][2]); 
  117.  
  118. $this->assertEquals('your-subject', $exp->rowFilter->tree[0][1][0]); 
  119. $this->assertEquals('=', $exp->rowFilter->tree[0][1][1]); 
  120. $this->assertEquals('', $exp->rowFilter->tree[0][1][2]); 
  121.