mirrored from git://develop.git.wordpress.org/
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Menus: Add
rel="noopener"
to target="_blank"
links by default in …
…menus. This expands upon `rel="noopener"` being previously added to links in the content. Props audrasjb, welcher. Fixes #43290. git-svn-id: https://develop.svn.wordpress.org/trunk@45141 602fd350-edb4-49c9-b593-d223f7449a82
- Loading branch information
Showing
2 changed files
with
77 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
/** | ||
* @group navmenus | ||
* @group walker | ||
*/ | ||
class Tests_Walker_Nav_Menu extends WP_UnitTestCase { | ||
|
||
/** | ||
* @var \Walker_Nav_Menu The instance of the walker. | ||
*/ | ||
public $walker; | ||
|
||
/** | ||
* Setup. | ||
*/ | ||
public function setUp() { | ||
global $_wp_nav_menu_max_depth; | ||
|
||
parent::setUp(); | ||
|
||
/** Walker_Nav_Menu_Edit class */ | ||
require_once ABSPATH . 'wp-includes/class-walker-nav-menu.php'; | ||
$this->walker = new Walker_Nav_Menu(); | ||
|
||
$this->_wp_nav_menu_max_depth = $_wp_nav_menu_max_depth; | ||
parent::setUp(); | ||
} | ||
|
||
/** | ||
* Tear down | ||
*/ | ||
public function tearDown() { | ||
global $_wp_nav_menu_max_depth; | ||
|
||
$_wp_nav_menu_max_depth = $this->_wp_nav_menu_max_depth; | ||
parent::tearDown(); | ||
} | ||
|
||
/** | ||
* Tests when an items target it _blank, that rel="'noopener noreferrer" is added. | ||
* | ||
* @ticket #43290 | ||
*/ | ||
public function test_noopener_no_referrer_for_target_blank() { | ||
$expected = ''; | ||
$post_id = $this->factory->post->create(); | ||
$post_title = get_the_title( $post_id ); | ||
|
||
$item = array( | ||
'ID' => $post_id, | ||
'object_id' => $post_id, | ||
'title' => $post_title, | ||
'target' => '_blank', | ||
'xfn' => '', | ||
'current' => false, | ||
); | ||
|
||
$args = array( | ||
'before' => '', | ||
'after' => '', | ||
'link_before' => '', | ||
'link_after' => '', | ||
); | ||
|
||
$this->walker->start_el( $expected, (object) $item, 0, (object) $args ); | ||
|
||
$this->assertSame( "<li id=\"menu-item-{$post_id}\" class=\"menu-item-{$post_id}\"><a target=\"_blank\" rel=\"noopener noreferrer\">{$post_title}</a>", $expected ); | ||
} | ||
} |