Make WordPress Core

Changeset 53509


Ignore:
Timestamp:
06/15/2022 02:07:24 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Tests: Some improvements for REST API cache priming tests:

  • Give the test methods more specific names and move them closer together.
  • Correct the @covers tags.

Follow-up to [53499], [53504], [53506], [53507], [53508].

See #55593, #55652.

Location:
trunk/tests/phpunit/tests
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post/nav-menu.php

    r53508 r53509  
    205205        /**
    206206         * @ticket 55620
    207          * @covers update_menu_item_cache
    208          */
    209         public function test_update_menu_item_cache_primed_posts() {
     207         * @covers ::update_menu_item_cache
     208         */
     209        public function test_update_menu_item_cache_primes_posts() {
    210210                $post_id = self::factory()->post->create();
    211211                wp_update_nav_menu_item(
     
    236236        /**
    237237         * @ticket 55620
    238          * @covers update_menu_item_cache
    239          */
    240         public function test_update_menu_item_cache_primed_terms() {
     238         * @covers ::update_menu_item_cache
     239         */
     240        public function test_update_menu_item_cache_primes_terms() {
    241241                register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ) );
    242242                $term_id = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax' ) );
  • trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php

    r53507 r53509  
    15181518         * @ticket 55592
    15191519         * @covers WP_REST_Posts_Controller::get_items
     1520         * @covers ::update_post_thumbnail_cache
    15201521         */
    1521         public function test_get_items_with_featured_media() {
     1522        public function test_get_items_primes_thumbnail_cache_for_featured_media() {
    15221523                $file           = DIR_TESTDATA . '/images/canola.jpg';
    15231524                $attachment_ids = array();
     
    15351536                }
    15361537
    1537                 // Attachment creation warms thumbnail ids. Needs clean up for test.
     1538                // Attachment creation warms thumbnail IDs. Needs clean up for test.
    15381539                wp_cache_delete_multiple( $attachment_ids, 'posts' );
    15391540
     
    15491550                $this->assertIsArray( $last, 'The last value is not an array' );
    15501551                $this->assertEqualSets( $attachment_ids, $last[1] );
     1552        }
     1553
     1554        /**
     1555         * @ticket 55593
     1556         * @covers WP_REST_Posts_Controller::get_items
     1557         * @covers ::update_post_parent_caches
     1558         */
     1559        public function test_get_items_primes_parent_post_caches() {
     1560                $parent_id1 = self::$post_ids[0];
     1561                $parent_id2 = self::$post_ids[1];
     1562                $parent_ids = array( $parent_id2, $parent_id1 );
     1563
     1564                $this->factory->attachment->create_object(
     1565                        DIR_TESTDATA . '/images/canola.jpg',
     1566                        $parent_id1,
     1567                        array(
     1568                                'post_mime_type' => 'image/jpeg',
     1569                                'post_excerpt'   => 'A sample caption 1',
     1570                        )
     1571                );
     1572
     1573                $this->factory->attachment->create_object(
     1574                        DIR_TESTDATA . '/images/canola.jpg',
     1575                        $parent_id2,
     1576                        array(
     1577                                'post_mime_type' => 'image/jpeg',
     1578                                'post_excerpt'   => 'A sample caption 2',
     1579                        )
     1580                );
     1581
     1582                // Attachment creation warms parent IDs. Needs clean up for test.
     1583                wp_cache_delete_multiple( $parent_ids, 'posts' );
     1584
     1585                $filter = new MockAction();
     1586                add_filter( 'update_post_metadata_cache', array( $filter, 'filter' ), 10, 2 );
     1587
     1588                $request = new WP_REST_Request( 'GET', '/wp/v2/media' );
     1589                rest_get_server()->dispatch( $request );
     1590
     1591                $args = $filter->get_args();
     1592                $last = end( $args );
     1593                $this->assertIsArray( $last, 'The last value is not an array' );
     1594                $this->assertEqualSets( $parent_ids, $last[1] );
    15511595        }
    15521596
     
    17861830
    17871831                $this->assertSame( $formats, $data['schema']['properties']['format']['enum'] );
    1788         }
    1789 
    1790         /**
    1791          * @ticket 55593
    1792          * @covers WP_REST_Posts_Controller::get_items
    1793          * @covers update_post_parent_caches
    1794          */
    1795         public function test_get_items_parent_ids_primed() {
    1796                 $parent_id1 = self::$post_ids[0];
    1797                 $parent_id2 = self::$post_ids[1];
    1798                 $parent_ids = array( $parent_id2, $parent_id1 );
    1799 
    1800                 $this->factory->attachment->create_object(
    1801                         DIR_TESTDATA . '/images/canola.jpg',
    1802                         $parent_id1,
    1803                         array(
    1804                                 'post_mime_type' => 'image/jpeg',
    1805                                 'post_excerpt'   => 'A sample caption 1',
    1806                         )
    1807                 );
    1808 
    1809                 $this->factory->attachment->create_object(
    1810                         DIR_TESTDATA . '/images/canola.jpg',
    1811                         $parent_id2,
    1812                         array(
    1813                                 'post_mime_type' => 'image/jpeg',
    1814                                 'post_excerpt'   => 'A sample caption 2',
    1815                         )
    1816                 );
    1817 
    1818                 // Attachment creation warms parent ids. Needs clean up for test.
    1819                 wp_cache_delete_multiple( $parent_ids, 'posts' );
    1820 
    1821                 $filter = new MockAction();
    1822                 add_filter( 'update_post_metadata_cache', array( $filter, 'filter' ), 10, 2 );
    1823 
    1824                 $request = new WP_REST_Request( 'GET', '/wp/v2/media' );
    1825                 rest_get_server()->dispatch( $request );
    1826 
    1827                 $args = $filter->get_args();
    1828                 $last = end( $args );
    1829                 $this->assertIsArray( $last, 'The last value is not an array' );
    1830                 $this->assertEqualSets( $parent_ids, $last[1] );
    18311832        }
    18321833
Note: See TracChangeset for help on using the changeset viewer.