Changeset 31615
- Timestamp:
- 03/05/2015 02:59:47 AM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/comment.php
r31553 r31615 2213 2213 $commentdata['comment_agent'] = isset( $_SERVER['HTTP_USER_AGENT'] ) ? substr( $_SERVER['HTTP_USER_AGENT'], 0, 254 ) : ''; 2214 2214 2215 $commentdata['comment_date'] = current_time('mysql'); 2216 $commentdata['comment_date_gmt'] = current_time('mysql', 1); 2215 if ( empty( $commentdata['comment_date'] ) ) { 2216 $commentdata['comment_date'] = current_time('mysql'); 2217 } 2218 2219 if ( empty( $commentdata['comment_date_gmt'] ) ) { 2220 $commentdata['comment_date_gmt'] = current_time( 'mysql', 1 ); 2221 } 2217 2222 2218 2223 $commentdata = wp_filter_comment($commentdata); -
trunk/tests/phpunit/tests/comment.php
r31195 r31615 73 73 $this->assertSame( array(), $found ); 74 74 } 75 76 /** 77 * @ticket 14279 78 */ 79 public function test_wp_new_comment_respects_dates() { 80 // `wp_new_comment()` checks REMOTE_ADDR, so we fake it to avoid PHP notices. 81 if ( isset( $_SERVER['REMOTE_ADDR'] ) ) { 82 $remote_addr = $_SERVER['REMOTE_ADDR']; 83 } else { 84 $_SERVER['REMOTE_ADDR'] = ''; 85 } 86 87 $u = $this->factory->user->create(); 88 $post_id = $this->factory->post->create( array( 'post_author' => $u ) ); 89 90 $data = array( 91 'comment_post_ID' => $post_id, 92 'comment_author' => rand_str(), 93 'comment_author_url' => '', 94 'comment_author_email' => '', 95 'comment_type' => '', 96 'comment_content' => rand_str(), 97 'comment_date' => '2011-01-01 10:00:00', 98 'comment_date_gmt' => '2011-01-01 10:00:00', 99 ); 100 101 $id = wp_new_comment( $data ); 102 103 $comment = get_comment( $id ); 104 105 $this->assertEquals( $data['comment_date'], $comment->comment_date ); 106 $this->assertEquals( $data['comment_date_gmt'], $comment->comment_date_gmt ); 107 108 // Cleanup. 109 if ( isset( $remote_addr ) ) { 110 $_SERVER['REMOTE_ADDR'] = $remote_addr; 111 } else { 112 unset( $_SERVER['REMOTE_ADDR'] ); 113 } 114 } 75 115 }
Note: See TracChangeset
for help on using the changeset viewer.