Make WordPress Core

Ticket #44005: 44005.4.diff

File 44005.4.diff, 12.8 KB (added by garrett-eclipse, 5 years ago)

Minor additions/adjustments to the unit tests started by @birgire

  • src/wp-admin/includes/file.php

     
    3636        'single.php'            => __( 'Single Post' ),
    3737        'page.php'              => __( 'Single Page' ),
    3838        'front-page.php'        => __( 'Homepage' ),
     39        'privacy-policy.php'    => __( 'Privacy Policy Page' ),
    3940        // Attachments
    4041        'attachment.php'        => __( 'Attachment Template' ),
    4142        'image.php'             => __( 'Image Attachment Template' ),
  • src/wp-includes/class-wp-query.php

     
    326326        public $is_home = false;
    327327
    328328        /**
     329         * Signifies whether the current query is for the Privacy Policy page.
     330         *
     331         * @since 5.2.0
     332         * @var bool
     333         */
     334        public $is_privacy_policy = false;
     335
     336        /**
    329337         * Signifies whether the current query couldn't find anything.
    330338         *
    331339         * @since 1.5.0
     
    463471                $this->is_comment_feed      = false;
    464472                $this->is_trackback         = false;
    465473                $this->is_home              = false;
     474                $this->is_privacy_policy    = false;
    466475                $this->is_404               = false;
    467476                $this->is_paged             = false;
    468477                $this->is_admin             = false;
     
    9981007                                $this->is_home       = true;
    9991008                                $this->is_posts_page = true;
    10001009                        }
     1010
     1011                        if ( isset( $this->queried_object_id ) && $this->queried_object_id == get_option( 'wp_page_for_privacy_policy' ) ) {
     1012                                $this->is_privacy_policy = true;
     1013                        }
    10011014                }
    10021015
    10031016                if ( $qv['page_id'] ) {
     
    10061019                                $this->is_home       = true;
    10071020                                $this->is_posts_page = true;
    10081021                        }
     1022
     1023                        if ( $qv['page_id'] == get_option( 'wp_page_for_privacy_policy' ) ) {
     1024                                $this->is_privacy_policy = true;
     1025                        }
    10091026                }
    10101027
    10111028                if ( ! empty( $qv['post_type'] ) ) {
     
    38783895        }
    38793896
    38803897        /**
     3898         * Is the query for the Privacy Policy page?
     3899         *
     3900         * This is the page which shows the Privacy Policy content of your site.
     3901         *
     3902         * Depends on the site's "Change your Privacy Policy page" Privacy Settings 'wp_page_for_privacy_policy'.
     3903         *
     3904         * This function will return true only on the page you set as the "Privacy Policy page".
     3905         *
     3906         * @see WP_Query::is_front_page()
     3907         *
     3908         * @since 5.2.0
     3909         *
     3910         * @return bool True, if Privacy Policy page.
     3911         */
     3912        public function is_privacy_policy() {
     3913                if ( get_option( 'wp_page_for_privacy_policy' ) && $this->is_page( get_option( 'wp_page_for_privacy_policy' ) ) ) {
     3914                        return true;
     3915                } else {
     3916                        return false;
     3917                }
     3918        }
     3919
     3920        /**
    38813921         * Is the query for an existing month archive?
    38823922         *
    38833923         * @since 3.1.0
  • src/wp-includes/post-template.php

     
    603603        if ( is_home() ) {
    604604                $classes[] = 'blog';
    605605        }
     606        if ( is_privacy_policy() ) {
     607                $classes[] = 'privacy-policy';
     608        }
    606609        if ( is_archive() ) {
    607610                $classes[] = 'archive';
    608611        }
  • src/wp-includes/query.php

     
    490490}
    491491
    492492/**
     493 * Determines whether the query is for the Privacy Policy page.
     494 *
     495 * The Privacy Policy page is the page that shows the Privacy Policy content of the site.
     496 *
     497 * is_privacy_policy() is dependent on the site's "Change your Privacy Policy page" Privacy Settings 'wp_page_for_privacy_policy'.
     498 *
     499 * This function will return true only on the page you set as the "Privacy Policy page".
     500 *
     501 * For more information on this and similar theme functions, check out
     502 * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
     503 * Conditional Tags} article in the Theme Developer Handbook.
     504 *
     505 * @since 5.2.0
     506 *
     507 * @global WP_Query $wp_query Global WP_Query instance.
     508 *
     509 * @return bool
     510 */
     511function is_privacy_policy() {
     512        global $wp_query;
     513
     514        if ( ! isset( $wp_query ) ) {
     515                _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' );
     516                return false;
     517        }
     518
     519        return $wp_query->is_privacy_policy();
     520}
     521
     522/**
    493523 * Determines whether the query is for an existing month archive.
    494524 *
    495525 * For more information on this and similar theme functions, check out
  • src/wp-includes/template-loader.php

     
    5151        elseif ( is_search() && $template = get_search_template() ) :
    5252        elseif ( is_front_page() && $template = get_front_page_template() ) :
    5353        elseif ( is_home() && $template = get_home_template() ) :
     54        elseif ( is_privacy_policy() && $template = get_privacy_policy_template() ) :
    5455        elseif ( is_post_type_archive() && $template = get_post_type_archive_template() ) :
    5556        elseif ( is_tax() && $template = get_taxonomy_template() ) :
    5657        elseif ( is_attachment() && $template = get_attachment_template() ) :
  • src/wp-includes/template.php

     
    3333         * The last element in the array should always be the fallback template for this query type.
    3434         *
    3535         * Possible values for `$type` include: 'index', '404', 'archive', 'author', 'category', 'tag', 'taxonomy', 'date',
    36          * 'embed', 'home', 'frontpage', 'page', 'paged', 'search', 'single', 'singular', and 'attachment'.
     36         * 'embed', 'home', 'frontpage', 'privacypolicy', 'page', 'paged', 'search', 'single', 'singular', and 'attachment'.
    3737         *
    3838         * @since 4.7.0
    3939         *
     
    5151         * This hook also applies to various types of files loaded as part of the Template Hierarchy.
    5252         *
    5353         * Possible values for `$type` include: 'index', '404', 'archive', 'author', 'category', 'tag', 'taxonomy', 'date',
    54          * 'embed', 'home', 'frontpage', 'page', 'paged', 'search', 'single', 'singular', and 'attachment'.
     54         * 'embed', 'home', 'frontpage', 'privacypolicy', 'page', 'paged', 'search', 'single', 'singular', and 'attachment'.
    5555         *
    5656         * @since 1.5.0
    5757         * @since 4.8.0 The `$type` and `$templates` parameters were added.
     
    377377}
    378378
    379379/**
     380 * Retrieve path of Privacy Policy page template in current or parent template.
     381 *
     382 * The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'}
     383 * and {@see '$type_template'} dynamic hooks, where `$type` is 'privacypolicy'.
     384 *
     385 * @since 5.2.0
     386 *
     387 * @see get_query_template()
     388 *
     389 * @return string Full path to front page template file.
     390 */
     391function get_privacy_policy_template() {
     392        $templates = array( 'privacy-policy.php' );
     393
     394        return get_query_template( 'privacy_policy', $templates );
     395}
     396
     397/**
    380398 * Retrieve path of page template in current or parent template.
    381399 *
    382400 * The hierarchy for this template looks like:
  • tests/phpunit/includes/abstract-testcase.php

     
    821821                        'is_feed',
    822822                        'is_front_page',
    823823                        'is_home',
     824                        'is_privacy_policy',
    824825                        'is_month',
    825826                        'is_page',
    826827                        'is_paged',
  • tests/phpunit/tests/post/getBodyClass.php

     
    202202                $this->assertContains( "attachmentid-{$attachment_id}", $class );
    203203                $this->assertContains( 'attachment-jpeg', $class );
    204204        }
     205
     206        /**
     207         * @ticket 44005
     208         * @group privacy
     209         */
     210        public function test_privacy_policy_body_class() {
     211                $page_id = self::factory()->post->create(
     212                        array(
     213                                'post_type'  => 'page',
     214                                'post_title' => 'Privacy Policy',
     215                        )
     216                );
     217                update_option( 'wp_page_for_privacy_policy', $page_id );
     218
     219                $this->go_to( get_permalink( $page_id ) );
     220
     221                $class = get_body_class();
     222
     223                $this->assertContains( 'privacy-policy', $class );
     224                $this->assertContains( 'page-template-default', $class );
     225                $this->assertContains( 'page', $class );
     226                $this->assertContains( "page-id-{$page_id}", $class );
     227        }
     228
    205229}
  • tests/phpunit/tests/query/conditionals.php

     
    15901590                $this->assertTrue( is_single( $p2 ) );
    15911591                $this->assertFalse( is_single( $p1 ) );
    15921592        }
     1593       
     1594        /**
     1595         * @ticket 44005
     1596         * @group privacy
     1597         */
     1598        public function test_is_privacy_policy() {
     1599                $page_id = self::factory()->post->create(
     1600                        array(
     1601                                'post_type'  => 'page',
     1602                                'post_title' => 'Privacy Policy',
     1603                        )
     1604                );
     1605
     1606                update_option( 'wp_page_for_privacy_policy', $page_id );
     1607
     1608                $this->go_to( get_permalink( $page_id ) );
     1609
     1610                $this->assertQueryTrue( 'is_page', 'is_singular', 'is_privacy_policy' );
     1611        }
     1612
    15931613}
  • tests/phpunit/tests/template.php

     
    1313        protected static $page;
    1414        protected static $post;
    1515
     16        /**
     17         * Page For Privacy Policy.
     18         *
     19         * @since 5.2.0
     20         *
     21         * @var WP_Post $page_for_privacy_policy
     22         */
     23        protected static $page_for_privacy_policy;
     24
    1625        public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
    1726                self::$page_on_front = $factory->post->create_and_get(
    1827                        array(
     
    4554                );
    4655                set_post_format( self::$post, 'quote' );
    4756                add_post_meta( self::$post->ID, '_wp_page_template', 'templates/post.php' );
     57
     58                self::$page_for_privacy_policy = $factory->post->create_and_get(
     59                        array(
     60                                'post_type'  => 'page',
     61                                'post_title' => 'Privacy Policy',
     62                        )
     63                );
    4864        }
    4965
    5066        public function setUp() {
     
    273289        }
    274290
    275291        /**
     292         * @ticket 44005
     293         * @group privacy
     294         */
     295        public function test_privacy_template_hierarchy() {
     296                update_option( 'wp_page_for_privacy_policy', self::$page_for_privacy_policy->ID );
     297
     298                $this->assertTemplateHierarchy(
     299                        get_permalink( self::$page_for_privacy_policy->ID ),
     300                        array(
     301                                'privacy-policy.php',
     302                                'page-privacy-policy.php',
     303                                'page-' . self::$page_for_privacy_policy->ID . '.php',
     304                                'page.php',
     305                                'singular.php',
     306                        )
     307                );
     308        }
     309
     310        /**
    276311         * @ticket 18375
    277312         */
    278313        public function test_single_template_hierarchy_for_post() {
     
    436471                        'search'            => 'is_search',
    437472                        'front_page'        => 'is_front_page',
    438473                        'home'              => 'is_home',
     474                        'privacy_policy'    => 'is_privacy_policy',
    439475                        'post_type_archive' => 'is_post_type_archive',
    440476                        'taxonomy'          => 'is_tax',
    441477                        'attachment'        => 'is_attachment',
  • tests/phpunit/tests/theme.php

     
    288288                                $this->assertEquals( get_category_template(), get_query_template( 'category' ) );
    289289                                $this->assertEquals( get_date_template(), get_query_template( 'date' ) );
    290290                                $this->assertEquals( get_home_template(), get_query_template( 'home', array( 'home.php', 'index.php' ) ) );
     291                                $this->assertEquals( get_privacy_policy_template(), get_query_template( 'privacy_policy', array( 'privacy-policy.php' ) ) );
    291292                                $this->assertEquals( get_page_template(), get_query_template( 'page' ) );
    292293                                $this->assertEquals( get_search_template(), get_query_template( 'search' ) );
    293294                                $this->assertEquals( get_single_template(), get_query_template( 'single' ) );
  • tests/phpunit/tests/url/getPrivacyPolicyUrl.php

     
    4545                                'post_title' => WP_TESTS_DOMAIN . ' Privacy Policy',
    4646                        )
    4747                );
    48 
    49                 self::$privacy_policy_url = get_permalink( self::$privacy_policy_page_id );
    5048        }
    5149
    5250        /**
     
    6058         * The function should return the privacy policy URL when `wp_page_for_privacy_policy` is set.
    6159         */
    6260        public function test_get_privacy_policy_url_should_return_valid_url_when_policy_page_set() {
     61                $privacy_policy_url = get_permalink( self::$privacy_policy_page_id );
    6362                update_option( 'wp_page_for_privacy_policy', self::$privacy_policy_page_id );
    6463
    65                 $this->assertSame( self::$privacy_policy_url, get_privacy_policy_url() );
     64                $this->assertSame( $privacy_policy_url, get_privacy_policy_url() );
    6665        }
    6766
    6867        /**