wpBlacklistCheck.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /**
  3. * @group comment
  4. */
  5. class Tests_WP_Blocklist_Check extends WP_UnitTestCase {
  6. public function test_should_return_true_when_content_matches_disallowed_keys() {
  7. $author = 'Sting';
  8. $author_email = 'sting@example.com';
  9. $author_url = 'http://example.com';
  10. $comment = "There's a hole in my heart. As deep as a well. For that poor little boy. Who's stuck halfway to Hell.";
  11. $author_ip = '192.168.0.1';
  12. $user_agent = '';
  13. update_option( 'disallowed_keys', "well\nfoo" );
  14. $result = wp_check_comment_disallowed_list( $author, $author_email, $author_url, $comment, $author_ip, $user_agent );
  15. $this->assertTrue( $result );
  16. }
  17. /**
  18. * @ticket 37208
  19. */
  20. public function test_should_return_true_when_content_with_html_matches_disallowed_keys() {
  21. $author = 'Sting';
  22. $author_email = 'sting@example.com';
  23. $author_url = 'http://example.com';
  24. $comment = "There's a hole in my heart. As deep as a well. For that poor little boy. Who's stuck <b>half</b>way to Hell.";
  25. $author_ip = '192.168.0.1';
  26. $user_agent = '';
  27. update_option( 'disallowed_keys', "halfway\nfoo" );
  28. $result = wp_check_comment_disallowed_list( $author, $author_email, $author_url, $comment, $author_ip, $user_agent );
  29. $this->assertTrue( $result );
  30. }
  31. public function test_should_return_true_when_author_matches_disallowed_keys() {
  32. $author = 'Sideshow Mel';
  33. $author_email = 'mel@example.com';
  34. $author_url = 'http://example.com';
  35. $comment = "Though we can't get him out. We'll do the next best thing.";
  36. $author_ip = '192.168.0.1';
  37. $user_agent = '';
  38. update_option( 'disallowed_keys', "sideshow\nfoo" );
  39. $result = wp_check_comment_disallowed_list( $author, $author_email, $author_url, $comment, $author_ip, $user_agent );
  40. $this->assertTrue( $result );
  41. }
  42. public function test_should_return_true_when_url_matches_disallowed_keys() {
  43. $author = 'Rainier Wolfcastle';
  44. $author_email = 'rainier@wolfcastle.com';
  45. $author_url = 'http://example.com';
  46. $comment = 'We go on TV and sing, sing, sing.';
  47. $author_ip = '192.168.0.1';
  48. $user_agent = '';
  49. update_option( 'disallowed_keys', "example\nfoo" );
  50. $result = wp_check_comment_disallowed_list( $author, $author_email, $author_url, $comment, $author_ip, $user_agent );
  51. $this->assertTrue( $result );
  52. }
  53. /**
  54. * @ticket 37208
  55. */
  56. public function test_should_return_true_when_link_matches_disallowed_keys() {
  57. $author = 'Rainier Wolfcastle';
  58. $author_email = 'rainier@wolfcastle.com';
  59. $author_url = 'http://example.com';
  60. $comment = 'We go on TV and sing, <a href="http://example.com/spam/>sing</a>, sing.';
  61. $author_ip = '192.168.0.1';
  62. $user_agent = '';
  63. update_option( 'disallowed_keys', '/spam/' );
  64. $result = wp_check_comment_disallowed_list( $author, $author_email, $author_url, $comment, $author_ip, $user_agent );
  65. $this->assertTrue( $result );
  66. }
  67. public function test_should_return_false_when_no_match() {
  68. $author = 'Krusty the Clown';
  69. $author_email = 'krusty@example.com';
  70. $author_url = 'http://example.com';
  71. $comment = "And we're sending our love down the well.";
  72. $author_ip = '192.168.0.1';
  73. $user_agent = '';
  74. update_option( 'disallowed_keys', "sideshow\nfoobar" );
  75. $result = wp_check_comment_disallowed_list( $author, $author_email, $author_url, $comment, $author_ip, $user_agent );
  76. $this->assertFalse( $result );
  77. }
  78. }