| | 1398 | |
| | 1399 | /** |
| | 1400 | * @ticket 52187 |
| | 1401 | */ |
| | 1402 | public function test_insert_empty_post_date() { |
| | 1403 | $post_date_gmt = '2020-12-29 10:11:45'; |
| | 1404 | $invalid_date = '2020-12-41 14:15:27'; |
| | 1405 | |
| | 1406 | // Empty post_date_gmt with floating status |
| | 1407 | $post_id = self::factory()->post->create( |
| | 1408 | array( |
| | 1409 | 'post_status' => 'draft', |
| | 1410 | ) |
| | 1411 | ); |
| | 1412 | $post = get_post( $post_id ); |
| | 1413 | $this->assertEqualsWithDelta( strtotime( gmdate( 'Y-m-d H:i:s' ) ), strtotime( $post->post_date ), 2, 'The dates should be equal' ); |
| | 1414 | $this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt ); |
| | 1415 | |
| | 1416 | $post_id = self::factory()->post->create( |
| | 1417 | array( |
| | 1418 | 'post_date_gmt' => '0000-00-00 00:00:00', |
| | 1419 | 'post_status' => 'draft', |
| | 1420 | ) |
| | 1421 | ); |
| | 1422 | $post = get_post( $post_id ); |
| | 1423 | $this->assertEqualsWithDelta( strtotime( gmdate( 'Y-m-d H:i:s' ) ), strtotime( $post->post_date ), 2, 'The dates should be equal' ); |
| | 1424 | $this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt ); |
| | 1425 | |
| | 1426 | // Empty post_date_gmt without floating status |
| | 1427 | $post_id = self::factory()->post->create( |
| | 1428 | array( |
| | 1429 | 'post_status' => 'publish', |
| | 1430 | ) |
| | 1431 | ); |
| | 1432 | $post = get_post( $post_id ); |
| | 1433 | $this->assertEqualsWithDelta( strtotime( gmdate( 'Y-m-d H:i:s' ) ), strtotime( $post->post_date ), 2, 'The dates should be equal' ); |
| | 1434 | $this->assertEqualsWithDelta( strtotime( gmdate( 'Y-m-d H:i:s' ) ), strtotime( get_gmt_from_date( $post->post_date ) ), 2, 'The dates should be equal' ); |
| | 1435 | |
| | 1436 | $post_id = self::factory()->post->create( |
| | 1437 | array( |
| | 1438 | 'post_date_gmt' => '0000-00-00 00:00:00', |
| | 1439 | 'post_status' => 'publish', |
| | 1440 | ) |
| | 1441 | ); |
| | 1442 | $post = get_post( $post_id ); |
| | 1443 | $this->assertEqualsWithDelta( strtotime( gmdate( 'Y-m-d H:i:s' ) ), strtotime( $post->post_date ), 2, 'The dates should be equal' ); |
| | 1444 | $this->assertEqualsWithDelta( strtotime( gmdate( 'Y-m-d H:i:s' ) ), strtotime( get_gmt_from_date( $post->post_date ) ), 2, 'The dates should be equal' ); |
| | 1445 | |
| | 1446 | // Valid post_date_gmt |
| | 1447 | $post_id = self::factory()->post->create( |
| | 1448 | array( |
| | 1449 | 'post_date_gmt' => $post_date_gmt, |
| | 1450 | ) |
| | 1451 | ); |
| | 1452 | $post = get_post( $post_id ); |
| | 1453 | $this->assertEquals( get_date_from_gmt( $post_date_gmt ), $post->post_date ); |
| | 1454 | $this->assertEquals( $post_date_gmt, $post->post_date_gmt ); |
| | 1455 | |
| | 1456 | // Invalid post_date_gmt |
| | 1457 | $post_id = self::factory()->post->create( |
| | 1458 | array( |
| | 1459 | 'post_date_gmt' => $invalid_date, |
| | 1460 | ) |
| | 1461 | ); |
| | 1462 | $post = get_post( $post_id ); |
| | 1463 | $this->assertEquals( '1970-01-01 00:00:00', $post->post_date ); |
| | 1464 | $this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt ); |
| | 1465 | } |
| | 1466 | |
| | 1467 | /** |
| | 1468 | * @ticket 52187 |
| | 1469 | */ |
| | 1470 | public function test_insert_valid_post_date() { |
| | 1471 | $post_date = '2020-12-28 11:26:35'; |
| | 1472 | $post_date_gmt = '2020-12-29 10:11:45'; |
| | 1473 | $invalid_date = '2020-12-41 14:15:27'; |
| | 1474 | |
| | 1475 | // Empty post_date_gmt with floating status |
| | 1476 | $post_id = self::factory()->post->create( |
| | 1477 | array( |
| | 1478 | 'post_date' => $post_date, |
| | 1479 | 'post_status' => 'draft', |
| | 1480 | ) |
| | 1481 | ); |
| | 1482 | $post = get_post( $post_id ); |
| | 1483 | $this->assertEquals( $post_date, $post->post_date ); |
| | 1484 | $this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt ); |
| | 1485 | |
| | 1486 | $post_id = self::factory()->post->create( |
| | 1487 | array( |
| | 1488 | 'post_date' => $post_date, |
| | 1489 | 'post_date_gmt' => '0000-00-00 00:00:00', |
| | 1490 | 'post_status' => 'draft', |
| | 1491 | ) |
| | 1492 | ); |
| | 1493 | $post = get_post( $post_id ); |
| | 1494 | $this->assertEquals( $post_date, $post->post_date ); |
| | 1495 | $this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt ); |
| | 1496 | |
| | 1497 | // Empty post_date_gmt without floating status |
| | 1498 | $post_id = self::factory()->post->create( |
| | 1499 | array( |
| | 1500 | 'post_date' => $post_date, |
| | 1501 | 'post_status' => 'publish', |
| | 1502 | ) |
| | 1503 | ); |
| | 1504 | $post = get_post( $post_id ); |
| | 1505 | $this->assertEquals( $post_date, $post->post_date ); |
| | 1506 | $this->assertEquals( get_gmt_from_date( $post_date ), $post->post_date_gmt ); |
| | 1507 | |
| | 1508 | $post_id = self::factory()->post->create( |
| | 1509 | array( |
| | 1510 | 'post_date' => $post_date, |
| | 1511 | 'post_date_gmt' => '0000-00-00 00:00:00', |
| | 1512 | 'post_status' => 'publish', |
| | 1513 | ) |
| | 1514 | ); |
| | 1515 | $post = get_post( $post_id ); |
| | 1516 | $this->assertEquals( $post_date, $post->post_date ); |
| | 1517 | $this->assertEquals( get_gmt_from_date( $post_date ), $post->post_date_gmt ); |
| | 1518 | |
| | 1519 | // Valid post_date_gmt |