Tests_The_Magic

Tests the _GET.

Defined (1)

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

/vendor/calderawp/magic-tags/tests/tests-get_var.php  
  1. class Tests_The_Magic extends WP_UnitTestCase { 
  2.  
  3. public function test_get_var() { 
  4.  
  5. $magic = new calderawp\filter\magictag(); 
  6. $count = rand(0, 999); 
  7. // _GETS 
  8. $_GET = array( 
  9. 'company' => 'caldera',  
  10. 'name' => 'Bob Bitmap',  
  11. 'count' => $count 
  12. ); 
  13.  
  14. $this->assertSame( 'Company is caldera' , $magic->do_magic_tag( 'Company is {_GET:company}' ) ); 
  15. $this->assertSame( 'Name is Bob Bitmap' , $magic->do_magic_tag( 'Name is {_GET:name}' ) ); 
  16. $this->assertSame( 'Total count is ' . $count , $magic->do_magic_tag( 'Total count is {_GET:count}' ) ); 
  17. $this->assertSame( 'home is {_GET:home}' , $magic->do_magic_tag( 'home is {_GET:home}' ) ); 
  18.  
  19. // REFERR 
  20. $_SERVER['HTTP_REFERER'] = 'http://localhost/apath/?country=ZA&location=office'; 
  21.  
  22. $this->assertSame( 'location is office' , $magic->do_magic_tag( 'location is {_GET:location}' ) ); 
  23. $this->assertSame( 'country is ZA' , $magic->do_magic_tag( 'country is {_GET:country}' ) ); 
  24.  
  25. $this->assertSame( 'cant find {_GET:billy} sorry' , $magic->do_magic_tag( 'cant find {_GET:billy} sorry' ) ); 
  26.  
  27. $this->assertSame( 'Bob Bitmap works in ZA in his office' , $magic->do_magic_tag( '{_GET:name} works in {_GET:country} in his {_GET:location}' ) ); 
  28.  
  29.  
  30.  
  31. public function test_post_var() { 
  32.  
  33. $magic = new calderawp\filter\magictag(); 
  34. $count = rand(0, 999); 
  35. $_POST = array( 
  36. 'company' => 'caldera',  
  37. 'name' => 'Bob Bitmap',  
  38. 'count' => $count 
  39. ); 
  40.  
  41. $this->assertSame( 'Company is caldera' , $magic->do_magic_tag( 'Company is {_POST:company}' ) ); 
  42. $this->assertSame( 'Name is Bob Bitmap' , $magic->do_magic_tag( 'Name is {_POST:name}' ) ); 
  43. $this->assertSame( 'Total count is ' . $count , $magic->do_magic_tag( 'Total count is {_POST:count}' ) ); 
  44.  
  45. $this->assertSame( 'cant find {_POST:billy} sorry' , $magic->do_magic_tag( 'cant find {_POST:billy} sorry' ) ); 
  46.  
  47.  
  48. public function test_request_var() { 
  49.  
  50. $magic = new calderawp\filter\magictag(); 
  51. $count = rand(0, 999); 
  52.  
  53. $_REQUEST = array( 
  54. 'company' => 'caldera',  
  55. 'name' => 'Bob Bitmap',  
  56. ); 
  57.  
  58. $this->assertSame( 'Company is caldera' , $magic->do_magic_tag( 'Company is {_REQUEST:company}' ) ); 
  59. $this->assertSame( 'Name is Bob Bitmap' , $magic->do_magic_tag( 'Name is {_REQUEST:name}' ) ); 
  60.  
  61. $this->assertSame( 'cant find {_REQUEST:billy} sorry' , $magic->do_magic_tag( 'cant find {_REQUEST:billy} sorry' ) ); 
  62.  
  63.  
  64.  
  65. public function test_user() { 
  66.  
  67. $magic = new calderawp\filter\magictag(); 
  68.  
  69. // not logged in 
  70. $this->assertSame( 'user name is {user:user_login}' , $magic->do_magic_tag( 'user name is {user:user_login}' ) ); 
  71. $this->assertSame( 'no meta {user:stuff}' , $magic->do_magic_tag( 'no meta {user:stuff}' ) ); 
  72.  
  73. wp_set_current_user( 1 ); 
  74.  
  75. $this->assertSame( 'user name is admin' , $magic->do_magic_tag( 'user name is {user:user_login}' ) ); 
  76. $this->assertSame( 'welcome 1' , $magic->do_magic_tag( 'welcome {user:show_welcome_panel}' ) ); 
  77. $this->assertSame( 'no meta {user:stuff}' , $magic->do_magic_tag( 'no meta {user:stuff}' ) ); 
  78.  
  79.  
  80.  
  81. public function test_post() { 
  82.  
  83. global $post; 
  84.  
  85. $magic = new calderawp\filter\magictag(); 
  86. // get post 
  87. $posts = get_posts( array( 'post_status' => 'publish' ) ); 
  88.  
  89. $this->assertSame( 'post_title is sample post' , $magic->do_magic_tag( 'post_title is {post:' . $posts[0]->ID . ':post_title}' ) ); 
  90. $this->assertSame( 'meta data is sample meta value' , $magic->do_magic_tag( 'meta data is {post:' . $posts[0]->ID . ':sample_meta}' ) ); 
  91. $this->assertSame( 'meta data is private meta value' , $magic->do_magic_tag( 'meta data is {post:' . $posts[0]->ID . ':_sample_meta}' ) ); 
  92. $this->assertSame( 'meta data is value one, value two' , $magic->do_magic_tag( 'meta data is {post:' . $posts[0]->ID . ':array_meta}' ) ); 
  93.  
  94.  
  95. // set post global 
  96. $post = $posts[0]; 
  97.  
  98. $this->assertSame( 'post_title is sample post' , $magic->do_magic_tag( 'post_title is {post:post_title}' ) ); 
  99. $this->assertSame( 'meta data is sample meta value' , $magic->do_magic_tag( 'meta data is {post:sample_meta}' ) ); 
  100. $this->assertSame( 'meta data is private meta value' , $magic->do_magic_tag( 'meta data is {post:_sample_meta}' ) ); 
  101. $this->assertSame( 'meta data is value one, value two' , $magic->do_magic_tag( 'meta data is {post:array_meta}' ) ); 
  102.  
  103. // bad data 
  104. $this->assertSame( 'meta data is {post:no_real}' , $magic->do_magic_tag( 'meta data is {post:no_real}' ) ); 
  105. // no post 
  106. $post = null; 
  107. $this->assertSame( 'title is {post:post_title}' , $magic->do_magic_tag( 'title is {post:post_title}' ) ); 
  108. $this->assertSame( 'meta data is {post:sample_meta}' , $magic->do_magic_tag( 'meta data is {post:sample_meta}' ) ); 
  109. $this->assertSame( 'meta data is {post:_sample_meta}' , $magic->do_magic_tag( 'meta data is {post:_sample_meta}' ) ); 
  110. $this->assertSame( 'meta data is {post:array_meta}' , $magic->do_magic_tag( 'meta data is {post:array_meta}' ) ); 
  111.  
  112.  
  113. public function test_ip() { 
  114.  
  115. $magic = new calderawp\filter\magictag(); 
  116.  
  117. // get IP 
  118. $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; 
  119. $this->assertSame( 'Remote IP is 127.0.0.1' , $magic->do_magic_tag( 'Remote IP is {ip:address}' ) ); 
  120.  
  121. $_SERVER['HTTP_CLIENT_IP'] = '10.0.0.1'; 
  122. $this->assertSame( 'Client IP is 10.0.0.1' , $magic->do_magic_tag( 'Client IP is {ip:address}' ) ); 
  123.  
  124. unset( $_SERVER['HTTP_CLIENT_IP'] ); 
  125. $_SERVER['HTTP_X_FORWARDED_FOR'] = '192.168.0.1'; 
  126. $this->assertSame( 'Forward IP is 192.168.0.1' , $magic->do_magic_tag( 'Forward IP is {ip:address}' ) ); 
  127.  
  128.  
  129. public function test_date() { 
  130.  
  131. $magic = new calderawp\filter\magictag();  
  132.  
  133. $date = date('Y m m d d m y YY lR'); 
  134.  
  135. $this->assertSame( $date , $magic->do_magic_tag( '{date:Y m m d d m y YY lR}' ) ); 
  136.  
  137.  
  138.  
  139. public function test_nothing() { 
  140. $magic = new calderawp\filter\magictag();  
  141.  
  142. $this->assertSame( 'This is a string without tags' , $magic->do_magic_tag( 'This is a string without tags' ) ); 
  143.  
  144. public function test_general() { 
  145. $magic = new calderawp\filter\magictag();  
  146.  
  147. $this->assertSame( '{post}' , $magic->do_magic_tag( '{post}' ) ); 
  148.