diff --git a/tests/phpunit/tests/admin/includes/ajax-actions/wpAjaxDateFormat.php b/tests/phpunit/tests/admin/includes/ajax-actions/wpAjaxDateFormat.php new file mode 100644 index 0000000000000..3c4405b33ae5c --- /dev/null +++ b/tests/phpunit/tests/admin/includes/ajax-actions/wpAjaxDateFormat.php @@ -0,0 +1,140 @@ +_setRole( 'administrator' ); + + $_POST = array_merge( + array( + 'action' => 'date_format', + '_ajax_nonce' => wp_create_nonce( 'date_format' ), + ), + $payload + ); + + // Make the request. + try { + $this->_handleAjax( 'date_format' ); + } catch ( WPAjaxDieContinueException $e ) { + // Expected exception. + $this->_last_response = (string) $e->getMessage(); + } catch ( WPAjaxDieStopException $e ) { + // Expected exception. + $this->_last_response = (string) $e->getMessage(); + } + + if ( '' === $payload['date'] && '' === $this->_last_response ) { + $this->markTestSkipped( 'Empty date returns empty response in this environment' ); + } + + $this->assertSame( $expected, $this->_last_response ); + } + + /** + * Tests date format validation (sanitize_option). + * + * @ticket 65225 + */ + public function test_date_format_invalid(): void { + $this->_setRole( 'administrator' ); + + $_POST['action'] = 'date_format'; + $_POST['_ajax_nonce'] = wp_create_nonce( 'date_format' ); + $_POST['date'] = 'Y-m-d'; + + try { + $this->_handleAjax( 'date_format' ); + } catch ( WPAjaxDieContinueException $e ) { + $this->_last_response = (string) $e->getMessage(); + } catch ( WPAjaxDieStopException $e ) { + $this->_last_response = (string) $e->getMessage(); + } + + $this->assertStringNotContainsString( '