mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 12:20:22 +00:00
Privacy: Introduce Privacy Policy page helpers:
* `is_privacy_policy()` template tag * `privacy-policy.php` template * `.privacy-policy` body class * `.menu-item-privacy-policy` menu item class Props garrett-eclipse, birgire, xkon, Clorith. Fixes #44005. git-svn-id: https://develop.svn.wordpress.org/trunk@44966 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -926,6 +926,7 @@ abstract class WP_UnitTestCase_Base extends PHPUnit_Framework_TestCase {
|
||||
'is_feed',
|
||||
'is_front_page',
|
||||
'is_home',
|
||||
'is_privacy_policy',
|
||||
'is_month',
|
||||
'is_page',
|
||||
'is_paged',
|
||||
|
||||
@@ -202,4 +202,28 @@ class Tests_Post_GetBodyClass extends WP_UnitTestCase {
|
||||
$this->assertContains( "attachmentid-{$attachment_id}", $class );
|
||||
$this->assertContains( 'attachment-jpeg', $class );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 44005
|
||||
* @group privacy
|
||||
*/
|
||||
public function test_privacy_policy_body_class() {
|
||||
$page_id = self::factory()->post->create(
|
||||
array(
|
||||
'post_type' => 'page',
|
||||
'post_title' => 'Privacy Policy',
|
||||
)
|
||||
);
|
||||
update_option( 'wp_page_for_privacy_policy', $page_id );
|
||||
|
||||
$this->go_to( get_permalink( $page_id ) );
|
||||
|
||||
$class = get_body_class();
|
||||
|
||||
$this->assertContains( 'privacy-policy', $class );
|
||||
$this->assertContains( 'page-template-default', $class );
|
||||
$this->assertContains( 'page', $class );
|
||||
$this->assertContains( "page-id-{$page_id}", $class );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -861,4 +861,69 @@ class Test_Nav_Menus extends WP_UnitTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 44005
|
||||
* @group privacy
|
||||
*/
|
||||
function test_no_privacy_policy_class_applied() {
|
||||
$page_id = self::factory()->post->create(
|
||||
array(
|
||||
'post_type' => 'page',
|
||||
'post_title' => 'Privacy Policy Page',
|
||||
)
|
||||
);
|
||||
|
||||
wp_update_nav_menu_item(
|
||||
$this->menu_id,
|
||||
0,
|
||||
array(
|
||||
'menu-item-type' => 'post_type',
|
||||
'menu-item-object' => 'page',
|
||||
'menu-item-object-id' => $page_id,
|
||||
'menu-item-status' => 'publish',
|
||||
)
|
||||
);
|
||||
|
||||
$menu_items = wp_get_nav_menu_items( $this->menu_id );
|
||||
_wp_menu_item_classes_by_context( $menu_items );
|
||||
|
||||
$classes = $menu_items[0]->classes;
|
||||
|
||||
$this->assertNotContains( 'menu-item-privacy-policy', $classes );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 44005
|
||||
* @group privacy
|
||||
*/
|
||||
function test_class_applied_to_privacy_policy_page_item() {
|
||||
$page_id = self::factory()->post->create(
|
||||
array(
|
||||
'post_type' => 'page',
|
||||
'post_title' => 'Privacy Policy Page',
|
||||
)
|
||||
);
|
||||
update_option( 'wp_page_for_privacy_policy', $page_id );
|
||||
|
||||
wp_update_nav_menu_item(
|
||||
$this->menu_id,
|
||||
0,
|
||||
array(
|
||||
'menu-item-type' => 'post_type',
|
||||
'menu-item-object' => 'page',
|
||||
'menu-item-object-id' => $page_id,
|
||||
'menu-item-status' => 'publish',
|
||||
)
|
||||
);
|
||||
|
||||
$menu_items = wp_get_nav_menu_items( $this->menu_id );
|
||||
_wp_menu_item_classes_by_context( $menu_items );
|
||||
|
||||
$classes = $menu_items[0]->classes;
|
||||
|
||||
delete_option( 'wp_page_for_privacy_policy' );
|
||||
|
||||
$this->assertContains( 'menu-item-privacy-policy', $classes );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1590,4 +1590,24 @@ class Tests_Query_Conditionals extends WP_UnitTestCase {
|
||||
$this->assertTrue( is_single( $p2 ) );
|
||||
$this->assertFalse( is_single( $p1 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 44005
|
||||
* @group privacy
|
||||
*/
|
||||
public function test_is_privacy_policy() {
|
||||
$page_id = self::factory()->post->create(
|
||||
array(
|
||||
'post_type' => 'page',
|
||||
'post_title' => 'Privacy Policy',
|
||||
)
|
||||
);
|
||||
|
||||
update_option( 'wp_page_for_privacy_policy', $page_id );
|
||||
|
||||
$this->go_to( get_permalink( $page_id ) );
|
||||
|
||||
$this->assertQueryTrue( 'is_page', 'is_singular', 'is_privacy_policy' );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,15 @@ class Tests_Template extends WP_UnitTestCase {
|
||||
protected static $page;
|
||||
protected static $post;
|
||||
|
||||
/**
|
||||
* Page For Privacy Policy.
|
||||
*
|
||||
* @since 5.2.0
|
||||
*
|
||||
* @var WP_Post $page_for_privacy_policy
|
||||
*/
|
||||
protected static $page_for_privacy_policy;
|
||||
|
||||
public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
|
||||
self::$page_on_front = $factory->post->create_and_get(
|
||||
array(
|
||||
@@ -45,6 +54,13 @@ class Tests_Template extends WP_UnitTestCase {
|
||||
);
|
||||
set_post_format( self::$post, 'quote' );
|
||||
add_post_meta( self::$post->ID, '_wp_page_template', 'templates/post.php' );
|
||||
|
||||
self::$page_for_privacy_policy = $factory->post->create_and_get(
|
||||
array(
|
||||
'post_type' => 'page',
|
||||
'post_title' => 'Privacy Policy',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function setUp() {
|
||||
@@ -272,6 +288,25 @@ class Tests_Template extends WP_UnitTestCase {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 44005
|
||||
* @group privacy
|
||||
*/
|
||||
public function test_privacy_template_hierarchy() {
|
||||
update_option( 'wp_page_for_privacy_policy', self::$page_for_privacy_policy->ID );
|
||||
|
||||
$this->assertTemplateHierarchy(
|
||||
get_permalink( self::$page_for_privacy_policy->ID ),
|
||||
array(
|
||||
'privacy-policy.php',
|
||||
'page-privacy-policy.php',
|
||||
'page-' . self::$page_for_privacy_policy->ID . '.php',
|
||||
'page.php',
|
||||
'singular.php',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 18375
|
||||
*/
|
||||
@@ -436,6 +471,7 @@ class Tests_Template extends WP_UnitTestCase {
|
||||
'search' => 'is_search',
|
||||
'front_page' => 'is_front_page',
|
||||
'home' => 'is_home',
|
||||
'privacy_policy' => 'is_privacy_policy',
|
||||
'post_type_archive' => 'is_post_type_archive',
|
||||
'taxonomy' => 'is_tax',
|
||||
'attachment' => 'is_attachment',
|
||||
|
||||
@@ -288,6 +288,7 @@ class Tests_Theme extends WP_UnitTestCase {
|
||||
$this->assertEquals( get_category_template(), get_query_template( 'category' ) );
|
||||
$this->assertEquals( get_date_template(), get_query_template( 'date' ) );
|
||||
$this->assertEquals( get_home_template(), get_query_template( 'home', array( 'home.php', 'index.php' ) ) );
|
||||
$this->assertEquals( get_privacy_policy_template(), get_query_template( 'privacy_policy', array( 'privacy-policy.php' ) ) );
|
||||
$this->assertEquals( get_page_template(), get_query_template( 'page' ) );
|
||||
$this->assertEquals( get_search_template(), get_query_template( 'search' ) );
|
||||
$this->assertEquals( get_single_template(), get_query_template( 'single' ) );
|
||||
|
||||
@@ -45,8 +45,6 @@ class Tests_Url_GetPrivacyPolicyUrl extends WP_UnitTestCase {
|
||||
'post_title' => WP_TESTS_DOMAIN . ' Privacy Policy',
|
||||
)
|
||||
);
|
||||
|
||||
self::$privacy_policy_url = get_permalink( self::$privacy_policy_page_id );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,9 +58,10 @@ class Tests_Url_GetPrivacyPolicyUrl extends WP_UnitTestCase {
|
||||
* The function should return the privacy policy URL when `wp_page_for_privacy_policy` is set.
|
||||
*/
|
||||
public function test_get_privacy_policy_url_should_return_valid_url_when_policy_page_set() {
|
||||
$privacy_policy_url = get_permalink( self::$privacy_policy_page_id );
|
||||
update_option( 'wp_page_for_privacy_policy', self::$privacy_policy_page_id );
|
||||
|
||||
$this->assertSame( self::$privacy_policy_url, get_privacy_policy_url() );
|
||||
$this->assertSame( $privacy_policy_url, get_privacy_policy_url() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user