Skip to content

Commit

Permalink
Lower the priority as suggested by @azaozz here: #55400 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-vlasenko authored and Anton Vlasenko committed Nov 16, 2023
1 parent 55c6733 commit b075e61
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions phpunit/tests/blocks/registerBlockCorePostExcerptLengthFilter.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<?php

/**
* Tests for hooked blocks rendering.
* Functional unit test for wp_register_block_core_post_excerpt_length_filter().
*
* @package WordPress
* @subpackage Blocks
* @since 6.5.0
*
*/

/**
* @group blocks
* @covers ::register_block_core_post_excerpt_length_filter
*/
class Tests_Blocks_RegisterBlockCorePostExcerptLengthFilter extends WP_Test_REST_TestCase {

Expand All @@ -29,9 +31,14 @@ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
}

/**
* Unit test for ensuring correct length of the post excerpt in the REST API context.
*
* @dataProvider data_register_block_core_post_excerpt_length_filter
*
* @param int $expeceted_excerpt_length Expected excerpt length.
* @param string $context Current context.
*/
public function test_register_block_core_post_excerpt_length_filter( $expected_word_length, $context ) {
public function test_register_block_core_post_excerpt_length_filter( $expeceted_excerpt_length, $context ) {
wp_set_current_user( self::$admin_id );

$request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id );
Expand All @@ -47,15 +54,20 @@ public function test_register_block_core_post_excerpt_length_filter( $expected_w

$mock->expects( $this->atLeastOnce() )
->method( 'excerpt_length_callback' )
->with( $this->equalTo( $expected_word_length ) )
->willReturn( $expected_word_length );
->with( $this->equalTo( $expeceted_excerpt_length ) )
->willReturn( $expeceted_excerpt_length );

add_filter( 'excerpt_length', [ $mock, 'excerpt_length_callback' ], PHP_INT_MAX );
rest_get_server()->dispatch( $request );
remove_filter( 'excerpt_length', [ $mock, 'excerpt_length_callback' ], PHP_INT_MAX );
unset ( $_REQUEST['context'] );
}

/**
* Data provider.
*
* @return array
*/
public function data_register_block_core_post_excerpt_length_filter() {
return array(
'no_edit_context' => array(
Expand Down

0 comments on commit b075e61

Please sign in to comment.