Make WordPress Core

Ticket #61711: 61711-unit-test.diff

File 61711-unit-test.diff, 866 bytes (added by ironprogrammer, 3 months ago)

Unit test for protected post Cache-Control header

  • tests/phpunit/tests/wp/sendHeaders.php

    diff --git tests/phpunit/tests/wp/sendHeaders.php tests/phpunit/tests/wp/sendHeaders.php
    index b5fc56bf20..928aa6a85d 100644
    class Tests_WP_SendHeaders extends WP_UnitTestCase { 
    3535                $post_id = self::factory()->post->create();
    3636                $this->go_to( get_permalink( $post_id ) );
    3737        }
     38
     39        /**
     40         * @ticket 61711
     41         */
     42        public function test_send_headers_sets_cache_control_header_for_password_protected_posts() {
     43                add_action(
     44                        'wp_headers',
     45                        function ( $headers ) {
     46                                $this->assertArrayHasKey( 'Cache-Control', $headers );
     47                        }
     48                );
     49
     50                $post_id = self::factory()->post->create();
     51                add_filter( 'post_password_required', '__return_true' );
     52                $this->go_to( get_permalink( $post_id ) );
     53                remove_filter( 'post_password_required', '__return_true' );
     54        }
    3855}