| | 66 | /** |
| | 67 | * @ticket 24241 |
| | 68 | */ |
| | 69 | public function test_should_return_true_when_pingback_from_approved_site() { |
| | 70 | $post_id = self::factory()->post->create(); |
| | 71 | $uniqid = uniqid( '', true ); |
| | 72 | $prev_args = array( |
| | 73 | 'comment_post_ID' => $post_id, |
| | 74 | 'comment_content' => 'Can we build it?', |
| | 75 | 'comment_approved' => 1, |
| | 76 | 'comment_author_email' => 'bob@example.com', |
| | 77 | 'comment_author_url' => 'http://' . $uniqid . '.example.com/path', |
| | 78 | 'comment_author' => 'BobtheBuilder', |
| | 79 | 'comment_type' => 'pingback', |
| | 80 | ); |
| | 81 | self::factory()->comment->create( $prev_args ); |
| | 82 | |
| | 83 | update_option( 'comment_whitelist', 1 ); |
| | 84 | |
| | 85 | $author = 'BobtheBuilder'; |
| | 86 | $author_email = 'bob@example.com'; |
| | 87 | $author_url = 'http://' . $uniqid . '.example.com'; |
| | 88 | $comment = 'Can we fix it? Yes, we can (thanks to Wendy).'; |
| | 89 | $author_ip = '192.168.0.1'; |
| | 90 | $user_agent = ''; |
| | 91 | $comment_type = 'pingback'; |
| | 92 | |
| | 93 | $results = check_comment( $author, $author_email, $author_url, $comment, $author_ip, $user_agent, $comment_type ); |
| | 94 | $this->assertTrue( $results ); |
| | 95 | } |
| | 96 | |
| | 97 | /** |
| | 98 | * Just like test_should_return_true_when_pingback_from_approved_site() but with a HTTP/HTTPS |
| | 99 | * protocol mismatch. |
| | 100 | * |
| | 101 | * @ticket 24241 |
| | 102 | */ |
| | 103 | public function test_should_return_true_when_pingback_from_approved_site_https() { |
| | 104 | $post_id = self::factory()->post->create(); |
| | 105 | $uniqid = uniqid( '', true ); |
| | 106 | $prev_args = array( |
| | 107 | 'comment_post_ID' => $post_id, |
| | 108 | 'comment_content' => 'Can we build it?', |
| | 109 | 'comment_approved' => 1, |
| | 110 | 'comment_author_email' => 'bob@example.com', |
| | 111 | 'comment_author_url' => 'https://' . $uniqid . '.example.com/path', |
| | 112 | 'comment_author' => 'BobtheBuilder', |
| | 113 | 'comment_type' => 'pingback', |
| | 114 | ); |
| | 115 | self::factory()->comment->create( $prev_args ); |
| | 116 | |
| | 117 | update_option( 'comment_whitelist', 1 ); |
| | 118 | |
| | 119 | $author = 'BobtheBuilder'; |
| | 120 | $author_email = 'bob@example.com'; |
| | 121 | $author_url = 'http://' . $uniqid . '.example.com'; |
| | 122 | $comment = 'Can we fix it? Yes, we can (thanks to Wendy).'; |
| | 123 | $author_ip = '192.168.0.1'; |
| | 124 | $user_agent = ''; |
| | 125 | $comment_type = 'pingback'; |
| | 126 | |
| | 127 | $results = check_comment( $author, $author_email, $author_url, $comment, $author_ip, $user_agent, $comment_type ); |
| | 128 | $this->assertTrue( $results ); |
| | 129 | } |
| | 130 | |
| | 131 | /** |
| | 132 | * @ticket 24241 |
| | 133 | */ |
| | 134 | public function test_should_return_true_when_trackback_from_approved_site() { |
| | 135 | $post_id = self::factory()->post->create(); |
| | 136 | $uniqid = uniqid( '', true ); |
| | 137 | $prev_args = array( |
| | 138 | 'comment_post_ID' => $post_id, |
| | 139 | 'comment_content' => 'Can we build it?', |
| | 140 | 'comment_approved' => 1, |
| | 141 | 'comment_author_email' => 'bob@example.com', |
| | 142 | 'comment_author_url' => 'http://' . $uniqid . '.example.com/path', |
| | 143 | 'comment_author' => 'BobtheBuilder', |
| | 144 | 'comment_type' => 'trackback', |
| | 145 | ); |
| | 146 | self::factory()->comment->create( $prev_args ); |
| | 147 | |
| | 148 | update_option( 'comment_whitelist', 1 ); |
| | 149 | |
| | 150 | $author = 'BobtheBuilder'; |
| | 151 | $author_email = 'bob@example.com'; |
| | 152 | $author_url = 'http://' . $uniqid . '.example.com'; |
| | 153 | $comment = 'Can we fix it? Yes, we can (thanks to Wendy).'; |
| | 154 | $author_ip = '192.168.0.1'; |
| | 155 | $user_agent = ''; |
| | 156 | $comment_type = 'trackback'; |
| | 157 | |
| | 158 | $results = check_comment( $author, $author_email, $author_url, $comment, $author_ip, $user_agent, $comment_type ); |
| | 159 | $this->assertTrue( $results ); |
| | 160 | } |
| | 161 | |
| | 162 | /** |
| | 163 | * This test is like the ones above it but the previously-approved comment type does not match |
| | 164 | * the type being created. |
| | 165 | * |
| | 166 | * @ticket 24241 |
| | 167 | */ |
| | 168 | public function test_should_return_false_when_author_url_approved_for_wrong_type() { |
| | 169 | $post_id = self::factory()->post->create(); |
| | 170 | $uniqid = uniqid( '', true ); |
| | 171 | $prev_args = array( |
| | 172 | 'comment_post_ID' => $post_id, |
| | 173 | 'comment_content' => 'Can we build it?', |
| | 174 | 'comment_approved' => 1, |
| | 175 | 'comment_author_email' => 'bob@example.com', |
| | 176 | 'comment_author_url' => 'http://' . $uniqid . '.example.com/path', |
| | 177 | 'comment_author' => 'BobtheBuilder', |
| | 178 | 'comment_type' => 'comment', |
| | 179 | ); |
| | 180 | self::factory()->comment->create( $prev_args ); |
| | 181 | |
| | 182 | update_option( 'comment_whitelist', 1 ); |
| | 183 | |
| | 184 | $author = 'BobtheBuilder'; |
| | 185 | $author_email = 'bob@example.com'; |
| | 186 | $author_url = 'http://' . $uniqid . '.example.com'; |
| | 187 | $comment = 'Can we fix it? Yes, we can (thanks to Wendy).'; |
| | 188 | $author_ip = '192.168.0.1'; |
| | 189 | $user_agent = ''; |
| | 190 | $comment_type = 'pingback'; |
| | 191 | |
| | 192 | $results = check_comment( $author, $author_email, $author_url, $comment, $author_ip, $user_agent, $comment_type ); |
| | 193 | $this->assertFalse( $results ); |
| | 194 | } |
| | 195 | |