Skip to content

Commit 3843238

Browse files
Refactor unit test
1 parent 98b12d1 commit 3843238

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

tests/phpunit/tests/post.php

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -816,13 +816,16 @@ public function test_use_block_editor_for_post() {
816816
}
817817

818818
/**
819+
* The purpose of this test is to ensure that invalid dates do not
820+
* cause PHP errors when wp_insert_post() is called, and that the
821+
* posts are not actually "inserted" (created).
822+
*
819823
* @ticket 26798
820824
*
821825
* @dataProvider data_wp_insert_post_handle_malformed_post_date
822826
*
823-
* The purpose of this test is to ensure that invalid dates do not
824-
* cause PHP errors when wp_insert_post() is called, and that the
825-
* posts are not actually "inserted" (created).
827+
* @param string $input The input post_date value.
828+
* @param bool $expected Whether the post is expected to be inserted.
826829
*/
827830
public function test_wp_insert_post_handle_malformed_post_date( $input, $expected ) {
828831
$post = array(
@@ -842,9 +845,16 @@ public function test_wp_insert_post_handle_malformed_post_date( $input, $expecte
842845
}
843846

844847
/**
845-
* @ticket 26798
848+
* Data provider for test_wp_insert_post_handle_malformed_post_date().
849+
*
850+
* @return array[] {
851+
* Arguments passed to test.
852+
*
853+
* @type string $input The input post_date value.
854+
* @type bool $expected Whether the post is expected to be inserted.
855+
* }
846856
*/
847-
public function data_wp_insert_post_handle_malformed_post_date() {
857+
public static function data_wp_insert_post_handle_malformed_post_date() {
848858
return array(
849859
array(
850860
'2012-01-01',
@@ -940,12 +950,15 @@ public function data_wp_insert_post_handle_malformed_post_date() {
940950
}
941951

942952
/**
953+
* Tests the regex inside of wp_resolve_post_date(), with
954+
* the emphasis on the date format (not the time).
955+
*
943956
* @ticket 26798
944957
*
945958
* @dataProvider data_wp_resolve_post_date_regex
946959
*
947-
* Tests the regex inside of wp_resolve_post_date(), with
948-
* the emphasis on the date format (not the time).
960+
* @param string $date The input post_date value.
961+
* @param string|false $expected The expected resolved post date, or false if invalid
949962
*/
950963
public function test_wp_resolve_post_date_regex( $date, $expected ) {
951964
// Attempt to resolve post date.
@@ -956,9 +969,16 @@ public function test_wp_resolve_post_date_regex( $date, $expected ) {
956969
}
957970

958971
/**
959-
* @ticket 26798
972+
* Data provider for test_wp_resolve_post_date_regex().
973+
*
974+
* @return array[] {
975+
* Arguments passed to test.
976+
*
977+
* @type string $date The input post_date value.
978+
* @type string|false $expected The expected resolved post date, or false if invalid
979+
* }
960980
*/
961-
public function data_wp_resolve_post_date_regex() {
981+
public static function data_wp_resolve_post_date_regex() {
962982
return array(
963983
array(
964984
'2012-01-01',

0 commit comments

Comments
 (0)