mirrored from git://develop.git.wordpress.org/
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Meta: Allow empty strings to be set by Custom Fields meta box.
Because the REST API allows meta keys to have empty values, the Custom Fields meta box should permit the same behavior. Props charlestonsw, soulseekah. Fixes #43559. git-svn-id: https://develop.svn.wordpress.org/branches/5.0@43811 602fd350-edb4-49c9-b593-d223f7449a82
- Loading branch information
1 parent
8c0b678
commit dfbe885
Showing
4 changed files
with
89 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
/** | ||
* Admin ajax functions to be tested | ||
*/ | ||
require_once( ABSPATH . 'wp-admin/includes/ajax-actions.php' ); | ||
|
||
/** | ||
* Testing Add Meta AJAX functionality. | ||
* | ||
* @group ajax | ||
*/ | ||
class Tests_Ajax_AddMeta extends WP_Ajax_UnitTestCase { | ||
/** | ||
* @ticket 43559 | ||
*/ | ||
public function test_post_add_meta_empty_is_allowed_ajax() { | ||
$p = self::factory()->post->create(); | ||
|
||
// Become an administrator. | ||
$this->_setRole( 'administrator' ); | ||
|
||
$_POST = array( | ||
'post_id' => $p, | ||
'metakeyinput' => 'testkey', | ||
'metavalue' => '', | ||
'_ajax_nonce-add-meta' => wp_create_nonce( 'add-meta' ), | ||
); | ||
|
||
// Make the request. | ||
try { | ||
$this->_handleAjax( 'add-meta' ); | ||
} catch ( WPAjaxDieContinueException $e ) { | ||
unset( $e ); | ||
} | ||
|
||
$this->assertEquals( '', get_post_meta( $p, 'testkey', true ) ); | ||
} | ||
|
||
/** | ||
* @ticket 43559 | ||
*/ | ||
public function test_post_update_meta_empty_is_allowed_ajax() { | ||
$p = self::factory()->post->create(); | ||
|
||
$m = add_post_meta( $p, 'testkey', 'hello' ); | ||
|
||
// Become an administrator. | ||
$this->_setRole( 'administrator' ); | ||
|
||
$_POST = array( | ||
'_ajax_nonce-add-meta' => wp_create_nonce( 'add-meta' ), | ||
'post_id' => $p, | ||
'meta' => array( | ||
$m => array( | ||
'key' => 'testkey', | ||
'value' => '', | ||
), | ||
), | ||
); | ||
|
||
// Make the request. | ||
try { | ||
$this->_handleAjax( 'add-meta' ); | ||
} catch ( WPAjaxDieContinueException $e ) { | ||
unset( $e ); | ||
} | ||
|
||
$this->assertEquals( '', get_post_meta( $p, 'testkey', true ) ); | ||
} | ||
} |