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