| 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 |
| 1520 | $post_id = self::factory()->post->create( |
| 1521 | array( |
| 1522 | 'post_date' => $post_date, |
| 1523 | 'post_date_gmt' => $post_date_gmt, |
| 1524 | ) |
| 1525 | ); |
| 1526 | $post = get_post( $post_id ); |
| 1527 | $this->assertEquals( $post_date, $post->post_date ); |
| 1528 | $this->assertEquals( $post_date_gmt, $post->post_date_gmt ); |
| 1529 | |
| 1530 | // Invalid post_date_gmt |
| 1531 | $post_id = self::factory()->post->create( |
| 1532 | array( |
| 1533 | 'post_date' => $post_date, |
| 1534 | 'post_date_gmt' => $invalid_date, |
| 1535 | ) |
| 1536 | ); |
| 1537 | $post = get_post( $post_id ); |
| 1538 | $this->assertEquals( $post_date, $post->post_date ); |
| 1539 | $this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt ); |
| 1540 | } |
| 1541 | |
| 1542 | /** |
| 1543 | * @ticket 52187 |
| 1544 | */ |
| 1545 | public function test_insert_invalid_post_date() { |
| 1546 | $post_date = '2020-12-28 11:26:35'; |
| 1547 | $post_date_gmt = '2020-12-29 10:11:45'; |
| 1548 | $invalid_date = '2020-12-41 14:15:27'; |
| 1549 | |
| 1550 | // Empty post_date_gmt with floating status |
| 1551 | $post_id = self::factory()->post->create( |
| 1552 | array( |
| 1553 | 'post_date' => $invalid_date, |
| 1554 | 'post_status' => 'draft', |
| 1555 | ) |
| 1556 | ); |
| 1557 | $this->assertEquals( 0, $post_id ); |
| 1558 | |
| 1559 | $post_id = self::factory()->post->create( |
| 1560 | array( |
| 1561 | 'post_date' => $invalid_date, |
| 1562 | 'post_date_gmt' => '0000-00-00 00:00:00', |
| 1563 | 'post_status' => 'draft', |
| 1564 | ) |
| 1565 | ); |
| 1566 | $this->assertEquals( 0, $post_id ); |
| 1567 | |
| 1568 | // Empty post_date_gmt without floating status |
| 1569 | $post_id = self::factory()->post->create( |
| 1570 | array( |
| 1571 | 'post_date' => $invalid_date, |
| 1572 | 'post_status' => 'publish', |
| 1573 | ) |
| 1574 | ); |
| 1575 | $this->assertEquals( 0, $post_id ); |
| 1576 | |
| 1577 | $post_id = self::factory()->post->create( |
| 1578 | array( |
| 1579 | 'post_date' => $invalid_date, |
| 1580 | 'post_date_gmt' => '0000-00-00 00:00:00', |
| 1581 | 'post_status' => 'publish', |
| 1582 | ) |
| 1583 | ); |
| 1584 | $this->assertEquals( 0, $post_id ); |
| 1585 | |
| 1586 | // Valid post_date_gmt |
| 1587 | $post_id = self::factory()->post->create( |
| 1588 | array( |
| 1589 | 'post_date' => $invalid_date, |
| 1590 | 'post_date_gmt' => $post_date_gmt, |
| 1591 | ) |
| 1592 | ); |
| 1593 | $this->assertEquals( 0, $post_id ); |
| 1594 | |
| 1595 | // Invalid post_date_gmt |
| 1596 | $post_id = self::factory()->post->create( |
| 1597 | array( |
| 1598 | 'post_date' => $invalid_date, |
| 1599 | 'post_date_gmt' => $invalid_date, |
| 1600 | ) |
| 1601 | ); |
| 1602 | $this->assertEquals( 0, $post_id ); |
| 1603 | } |
| 1604 | |
| 1605 | /** |
| 1606 | * @ticket 52187 |
| 1607 | */ |
| 1608 | function test_wp_resolve_post_date() { |
| 1609 | $post_date = '2020-12-28 11:26:35'; |
| 1610 | $post_date_gmt = '2020-12-29 10:11:45'; |
| 1611 | $invalid_date = '2020-12-41 14:15:27'; |
| 1612 | |
| 1613 | $resolved_post_date = wp_resolve_post_date(); |
| 1614 | $this->assertEqualsWithDelta( strtotime( gmdate( 'Y-m-d H:i:s' ) ), strtotime( $resolved_post_date ), 2, 'The dates should be equal' ); |
| 1615 | |
| 1616 | $resolved_post_date = wp_resolve_post_date( '', $post_date_gmt ); |
| 1617 | $this->assertEquals( get_date_from_gmt( $post_date_gmt ), $resolved_post_date ); |
| 1618 | |
| 1619 | $resolved_post_date = wp_resolve_post_date( '', $invalid_date ); |
| 1620 | $this->assertEquals( '1970-01-01 00:00:00', $resolved_post_date ); |
| 1621 | |
| 1622 | $resolved_post_date = wp_resolve_post_date( $post_date ); |
| 1623 | $this->assertEquals( $post_date, $resolved_post_date ); |
| 1624 | |
| 1625 | $resolved_post_date = wp_resolve_post_date( $post_date, $post_date_gmt ); |
| 1626 | $this->assertEquals( $post_date, $resolved_post_date ); |
| 1627 | |
| 1628 | $resolved_post_date = wp_resolve_post_date( $post_date, $invalid_date ); |
| 1629 | $this->assertEquals( $post_date, $resolved_post_date ); |
| 1630 | |
| 1631 | $resolved_post_date = wp_resolve_post_date( $invalid_date ); |
| 1632 | $this->assertFalse( $resolved_post_date ); |
| 1633 | |
| 1634 | $resolved_post_date = wp_resolve_post_date( $invalid_date, $post_date_gmt ); |
| 1635 | $this->assertFalse( $resolved_post_date ); |
| 1636 | |
| 1637 | $resolved_post_date = wp_resolve_post_date( $invalid_date, $invalid_date ); |
| 1638 | $this->assertFalse( $resolved_post_date ); |
| 1639 | } |