wordpress-develop/tests/phpunit/tests/ajax/wpAjaxAddMeta.php
Sergey Biryukov 54eca75d04 Tests: Rename classes in phpunit/tests/ajax/ per the naming conventions.
This updates the test classes to match the names of the functions being tested.

Includes moving the `@covers` tags from individual test methods to the class DocBlocks.

Reference: [https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/#naming-and-organization Writing PHP Tests: Naming and Organization].

Follow-up to [47780], [48911], [49327], [50291], [50292], [50342], [50452], [50453], [50456], [50967], [50968], [50969], [51491], [51492], [51493], [51623], [51639], [51646], [51650], [51651], [51860], [52264], [52265], [53489], [53561], [54704].

See #56793.

git-svn-id: https://develop.svn.wordpress.org/trunk@54722 602fd350-edb4-49c9-b593-d223f7449a82
2022-10-30 01:05:06 +00:00

79 lines
1.6 KiB
PHP

<?php
/**
* Admin Ajax functions to be tested.
*/
require_once ABSPATH . 'wp-admin/includes/ajax-actions.php';
/**
* Testing Add Meta AJAX functionality.
*
* @group ajax
*
* @covers ::wp_ajax_add_meta
*/
class Tests_Ajax_wpAjaxAddMeta extends WP_Ajax_UnitTestCase {
/**
* @ticket 43559
*
* @covers ::add_post_meta
*/
public function test_wp_ajax_add_meta_allows_empty_values_on_adding() {
$post = self::factory()->post->create();
// Become an administrator.
$this->_setRole( 'administrator' );
$_POST = array(
'post_id' => $post,
'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->assertSame( '', get_post_meta( $post, 'testkey', true ) );
}
/**
* @ticket 43559
*
* @covers ::update_metadata_by_mid
*/
public function test_wp_ajax_add_meta_allows_empty_values_on_updating() {
$post = self::factory()->post->create();
$meta_id = add_post_meta( $post, 'testkey', 'hello' );
// Become an administrator.
$this->_setRole( 'administrator' );
$_POST = array(
'_ajax_nonce-add-meta' => wp_create_nonce( 'add-meta' ),
'post_id' => $post,
'meta' => array(
$meta_id => array(
'key' => 'testkey',
'value' => '',
),
),
);
// Make the request.
try {
$this->_handleAjax( 'add-meta' );
} catch ( WPAjaxDieContinueException $e ) {
unset( $e );
}
$this->assertSame( '', get_post_meta( $post, 'testkey', true ) );
}
}