You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 9408392
Browse filesBrowse the repository at this point in the historyBrowse files
Scenario: Set a post's modification date on update
883
+
Given a WP install
884
+
885
+
# A timezone with an offset, so the GMT value derived from the local one is
886
+
# distinguishable from it. 1 January is outside DST in New York.
887
+
When I run `wp option update timezone_string 'America/New_York'`
888
+
Then STDOUT should not be empty
889
+
890
+
When I run `wp post create --post_title='A post' --post_status=publish --porcelain`
891
+
Then STDOUT should be a number
892
+
And save STDOUT as {POST_ID}
893
+
894
+
When I run `wp post update {POST_ID} --post_modified='2020-01-01 12:00:00'`
895
+
Then STDOUT should be:
896
+
"""
897
+
Success: Updated post {POST_ID}.
898
+
"""
899
+
900
+
When I run `wp post get {POST_ID} --field=post_modified`
901
+
Then STDOUT should be:
902
+
"""
903
+
2020-01-01 12:00:00
904
+
"""
905
+
906
+
When I run `wp post get {POST_ID} --field=post_modified_gmt`
907
+
Then STDOUT should be:
908
+
"""
909
+
2020-01-01 17:00:00
910
+
"""
911
+
912
+
Scenario: Set a post's modification date on create
913
+
Given a WP install
914
+
915
+
When I run `wp option update timezone_string 'America/New_York'`
916
+
Then STDOUT should not be empty
917
+
918
+
When I run `wp post create --post_title='Another post' --post_date='2019-05-05 10:00:00' --post_modified='2020-01-01 12:00:00' --porcelain`
919
+
Then STDOUT should be a number
920
+
And save STDOUT as {POST_ID}
921
+
922
+
When I run `wp post get {POST_ID} --field=post_modified`
923
+
Then STDOUT should be:
924
+
"""
925
+
2020-01-01 12:00:00
926
+
"""
927
+
928
+
When I run `wp post get {POST_ID} --field=post_modified_gmt`
929
+
Then STDOUT should be:
930
+
"""
931
+
2020-01-01 17:00:00
932
+
"""
933
+
934
+
Scenario: A post's modification date defaults to the current time
935
+
Given a WP install
936
+
937
+
# Given a known modification date, so that an update which failed to set one
938
+
# would leave this value behind and be caught.
939
+
When I run `wp post create --post_title='Undated post' --post_status=publish --post_modified='2019-02-03 04:05:06' --porcelain`
940
+
Then STDOUT should be a number
941
+
And save STDOUT as {POST_ID}
942
+
943
+
When I run `wp post get {POST_ID} --field=post_modified`
944
+
Then STDOUT should be:
945
+
"""
946
+
2019-02-03 04:05:06
947
+
"""
948
+
949
+
When I run `wp post update {POST_ID} --post_title='Retitled'`
950
+
Then STDOUT should be:
951
+
"""
952
+
Success: Updated post {POST_ID}.
953
+
"""
954
+
955
+
When I run `wp post get {POST_ID} --field=post_modified`
956
+
Then STDOUT should not contain:
957
+
"""
958
+
2019-02-03 04:05:06
959
+
"""
960
+
And STDOUT should not be empty
961
+
962
+
Scenario: Setting only the GMT modification date derives the local one
963
+
Given a WP install
964
+
965
+
# A timezone with an offset, so the derived local value is distinguishable
966
+
# from the GMT one it was derived from. 1 January is outside DST in New York.
967
+
When I run `wp option update timezone_string 'America/New_York'`
968
+
Then STDOUT should not be empty
969
+
970
+
When I run `wp post create --post_title='GMT only' --post_status=publish --post_modified_gmt='2020-01-01 12:00:00' --porcelain`
971
+
Then STDOUT should be a number
972
+
And save STDOUT as {POST_ID}
973
+
974
+
When I run `wp post get {POST_ID} --field=post_modified_gmt`
975
+
Then STDOUT should be:
976
+
"""
977
+
2020-01-01 12:00:00
978
+
"""
979
+
980
+
When I run `wp post get {POST_ID} --field=post_modified`
981
+
Then STDOUT should be:
982
+
"""
983
+
2020-01-01 07:00:00
984
+
"""
985
+
986
+
# And the same on update, which takes the other of the two code paths.
987
+
When I run `wp post update {POST_ID} --post_modified_gmt='2020-06-01 12:00:00'`
988
+
Then STDOUT should be:
989
+
"""
990
+
Success: Updated post {POST_ID}.
991
+
"""
992
+
993
+
When I run `wp post get {POST_ID} --field=post_modified_gmt`
994
+
Then STDOUT should be:
995
+
"""
996
+
2020-06-01 12:00:00
997
+
"""
998
+
999
+
# June is inside DST, so the offset is four hours rather than five.
1000
+
When I run `wp post get {POST_ID} --field=post_modified`
1001
+
Then STDOUT should be:
1002
+
"""
1003
+
2020-06-01 08:00:00
1004
+
"""
1005
+
1006
+
Scenario: An invalid modification date is rejected on create
1007
+
Given a WP install
1008
+
1009
+
When I try `wp post create --post_title='Bad date' --post_status=publish --post_modified='banana'`
1010
+
Then the return code should be 1
1011
+
And STDERR should be:
1012
+
"""
1013
+
Error: Invalid date.
1014
+
"""
1015
+
1016
+
When I try `wp post create --post_title='Bad GMT date' --post_status=publish --post_modified_gmt='banana'`
1017
+
Then the return code should be 1
1018
+
And STDERR should be:
1019
+
"""
1020
+
Error: Invalid date.
1021
+
"""
1022
+
1023
+
# Well-formed but not a real calendar date.
1024
+
When I try `wp post create --post_title='Bad calendar date' --post_status=publish --post_modified='2020-02-30 12:00:00'`
1025
+
Then the return code should be 1
1026
+
And STDERR should be:
1027
+
"""
1028
+
Error: Invalid date.
1029
+
"""
1030
+
1031
+
When I run `wp post list --s=Bad --format=count`
1032
+
Then STDOUT should be:
1033
+
"""
1034
+
0
1035
+
"""
1036
+
1037
+
Scenario: An invalid modification date is rejected on update
1038
+
Given a WP install
1039
+
1040
+
When I run `wp post create --post_title='A post' --post_status=publish --post_modified='2020-01-01 12:00:00' --porcelain`
1041
+
Then STDOUT should be a number
1042
+
And save STDOUT as {POST_ID}
1043
+
1044
+
When I try `wp post update {POST_ID} --post_modified='banana'`
1045
+
Then the return code should be 1
1046
+
And STDERR should be:
1047
+
"""
1048
+
Warning: Invalid date.
1049
+
"""
1050
+
1051
+
When I try `wp post update {POST_ID} --post_modified_gmt='banana'`
1052
+
Then the return code should be 1
1053
+
And STDERR should be:
1054
+
"""
1055
+
Warning: Invalid date.
1056
+
"""
1057
+
1058
+
When I run `wp post get {POST_ID} --field=post_modified`
1059
+
Then STDOUT should be:
1060
+
"""
1061
+
2020-01-01 12:00:00
1062
+
"""
1063
+
1064
+
When I run `wp post get {POST_ID} --field=post_modified_gmt`
1065
+
Then STDOUT should be:
1066
+
"""
1067
+
2020-01-01 12:00:00
1068
+
"""
1069
+
1070
+
Scenario: Set an attachment's modification date
1071
+
Given a WP install
1072
+
1073
+
# Attachments take the wp_insert_attachment_data filter rather than
1074
+
# wp_insert_post_data, so they are a separate path to cover.
1075
+
When I run `wp post create --post_type=attachment --post_title='An attachment' --post_mime_type=image/png --post_modified='2020-01-01 12:00:00' --porcelain`
1076
+
Then STDOUT should be a number
1077
+
And save STDOUT as {ATTACHMENT_ID}
1078
+
1079
+
When I run `wp post get {ATTACHMENT_ID} --field=post_modified`
1080
+
Then STDOUT should be:
1081
+
"""
1082
+
2020-01-01 12:00:00
1083
+
"""
1084
+
1085
+
When I run `wp post update {ATTACHMENT_ID} --post_modified='2021-02-02 13:00:00'`
1086
+
Then STDOUT should be:
1087
+
"""
1088
+
Success: Updated post {ATTACHMENT_ID}.
1089
+
"""
1090
+
1091
+
When I run `wp post get {ATTACHMENT_ID} --field=post_modified`
1092
+
Then STDOUT should be:
1093
+
"""
1094
+
2021-02-02 13:00:00
1095
+
"""
1096
+
1097
+
Scenario: A post inserted by a save hook keeps its own modification date
1098
+
Given a WP install
1099
+
And a wp-content/mu-plugins/test-save-hook.php file:
0 commit comments