Make WordPress Core

Ticket #36786: 1655.patch

File 1655.patch, 4.2 KB (added by gaambo, 3 years ago)

#36786 refresh patch

  • tests/phpunit/includes/utils.php

    From ed994e7c7e0cdf961929efb39f51daf297843790 Mon Sep 17 00:00:00 2001
    From: Fabian Todt <mail@fabiantodt.at>
    Date: Fri, 3 Sep 2021 10:11:46 +0200
    Subject: [PATCH] fix MockAction::get_call_count correct usage & for filters
    
    ---
     tests/phpunit/includes/utils.php                 |  7 ++++---
     tests/phpunit/tests/rest-api/rest-controller.php | 14 +++++++-------
     2 files changed, 11 insertions(+), 10 deletions(-)
    
    diff --git a/tests/phpunit/includes/utils.php b/tests/phpunit/includes/utils.php
    index e37c3c15d66..ce6b9a1ed8d 100644
    a b function strip_ws( $txt ) { 
    5858 *     add_action( 'foo', array( &$ma, 'action' ) );
    5959 */
    6060class MockAction {
     61        // stores all called actions/filters in an array, where `action`/`filter` is the callback and `tag` is the called hook
    6162        public $events;
    6263        public $debug;
    6364
    function get_events() { 
    168169                return $this->events;
    169170        }
    170171
    171         // Return a count of the number of times the action was called since the last reset.
     172        // Return a count of the number of times the action or filter ( = tag ) was called since the last reset.
    172173        function get_call_count( $tag = '' ) {
    173174                if ( $tag ) {
    174175                        $count = 0;
    175176                        foreach ( $this->events as $e ) {
    176                                 if ( $e['action'] === $tag ) {
     177                                if ( $e['tag'] === $tag ) {
    177178                                        ++$count;
    178179                                }
    179180                        }
    function get_call_count( $tag = '' ) { 
    182183                return count( $this->events );
    183184        }
    184185
    185         // Return an array of the tags that triggered calls to this action.
     186        // Return an array of the tags (actions or filters) that triggered calls to this action.
    186187        function get_tags() {
    187188                $out = array();
    188189                foreach ( $this->events as $e ) {
  • tests/phpunit/tests/rest-api/rest-controller.php

    diff --git a/tests/phpunit/tests/rest-api/rest-controller.php b/tests/phpunit/tests/rest-api/rest-controller.php
    index 0af9460aa5d..a87dd331e65 100644
    a b public function test_get_fields_for_response_filters_by_context() { 
    392392
    393393                $controller->prepare_item_for_response( array(), $request );
    394394
    395                 $this->assertSame( 0, $listener->get_call_count( $method ) );
     395                $this->assertSame( 0, $listener->get_call_count() );
    396396
    397397                $request->set_param( 'context', 'embed' );
    398398
    399399                $controller->prepare_item_for_response( array(), $request );
    400400
    401                 $this->assertGreaterThan( 0, $listener->get_call_count( $method ) );
     401                $this->assertGreaterThan( 0, $listener->get_call_count() );
    402402        }
    403403
    404404        public function test_filtering_fields_for_response_by_context_returns_fields_with_no_context() {
    public function test_filtering_fields_for_response_by_context_returns_fields_wit 
    426426
    427427                $controller->prepare_item_for_response( array(), $request );
    428428
    429                 $this->assertGreaterThan( 0, $listener->get_call_count( $method ) );
     429                $this->assertGreaterThan( 0, $listener->get_call_count() );
    430430        }
    431431
    432432        public function test_filtering_fields_for_response_by_context_returns_fields_with_no_schema() {
    public function test_filtering_fields_for_response_by_context_returns_fields_wit 
    451451
    452452                $controller->prepare_item_for_response( array(), $request );
    453453
    454                 $this->assertGreaterThan( 0, $listener->get_call_count( $method ) );
     454                $this->assertGreaterThan( 0, $listener->get_call_count() );
    455455        }
    456456
    457457        /**
    public function test_add_additional_fields_to_object_respects_fields_param() { 
    511511
    512512                $controller->prepare_item_for_response( $item, $request );
    513513
    514                 $first_call_count = $listener->get_call_count( $method );
     514                $first_call_count = $listener->get_call_count();
    515515
    516516                $this->assertGreaterThan( 0, $first_call_count );
    517517
    public function test_add_additional_fields_to_object_respects_fields_param() { 
    519519
    520520                $controller->prepare_item_for_response( $item, $request );
    521521
    522                 $this->assertSame( $first_call_count, $listener->get_call_count( $method ) );
     522                $this->assertSame( $first_call_count, $listener->get_call_count() );
    523523
    524524                $request->set_param( '_fields', $field );
    525525
    526526                $controller->prepare_item_for_response( $item, $request );
    527527
    528                 $this->assertGreaterThan( $first_call_count, $listener->get_call_count( $method ) );
     528                $this->assertGreaterThan( $first_call_count, $listener->get_call_count() );
    529529        }
    530530
    531531        /**