[wp-trac] [WordPress Trac] #48300: metadata registered using register_meta() do not persist through several tests

WordPress Trac noreply at wordpress.org
Mon Oct 14 15:09:21 UTC 2019


#48300: metadata registered using register_meta() do not persist through several
tests
------------------------------+-----------------------------
 Reporter:  leogermani        |      Owner:  (none)
     Type:  defect (bug)      |     Status:  new
 Priority:  normal            |  Milestone:  Awaiting Review
Component:  Build/Test Tools  |    Version:  5.2.3
 Severity:  normal            |   Keywords:
  Focuses:                    |
------------------------------+-----------------------------
 When you register a metadata using `register_meta()` function, or one of
 its variants, such as `register_post_meta()`, the metadata is present in
 the response of `get_registered_meta_keys()` only in the first test of a
 file...

 I found this issue writing tests for a plugin, in a structure created
 based on the `wp scaffold plugin-tests` cli command.

 = How to reproduce =

 Write a plugin with jus this simple code:

 {{{#!php
 <?php


 add_action('init', 'test_register_post_meta');
 function test_register_post_meta() {
         register_post_meta('post', 'test_meta', [
                 'show_in_rest' => true,
                 'single' => true,
                 'type' => 'number',
                 'description' => 'test metadata'
         ]);
 }
 }}}

 And then run these simple tests:

 {{{#!php
 <?php

 class TestRegisterPostMeta extends \WP_UnitTestCase {

         function test_register_post_meta() {

                 $registered_meta = get_registered_meta_keys('post',
 'post');
                 $this->assertArrayHasKey('test_meta', $registered_meta);
 // it passes!

         }

         function test_register_post_meta_again() {

                 $registered_meta = get_registered_meta_keys('post',
 'post');
                 $this->assertArrayHasKey('test_meta', $registered_meta);
 // it fails!

         }


 }
 }}}

 This is very odd, but the second test, which is identical to the first,
 fails.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/48300>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list