mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-04 17:20:07 +00:00
Menus: In Walker_Nav_Menu, Walker_Category, and Walker_Page, properly output link attributes having a legitimate "empty" value, for example an HTML data attribute with a value of zero (0).
Props nevma, AkSDvP, greenshady, SergeyBiryukov. Fixes #47720. git-svn-id: https://develop.svn.wordpress.org/trunk@46413 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
87
tests/phpunit/tests/post/walkerPage.php
Normal file
87
tests/phpunit/tests/post/walkerPage.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
/**
|
||||
* @group post
|
||||
* @group walker
|
||||
*/
|
||||
class Tests_Post_Walker_Page extends WP_UnitTestCase {
|
||||
|
||||
/**
|
||||
* @var \Walker_Page The instance of the walker.
|
||||
*/
|
||||
public $walker;
|
||||
|
||||
/**
|
||||
* Setup.
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
/** Walker_Page class */
|
||||
require_once ABSPATH . 'wp-includes/class-walker-page.php';
|
||||
$this->walker = new Walker_Page();
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 47720
|
||||
*
|
||||
* @dataProvider data_start_el_with_empty_attributes
|
||||
*/
|
||||
public function test_start_el_with_empty_attributes( $value, $expected ) {
|
||||
$output = '';
|
||||
$page = $this->factory->post->create_and_get( array( 'post_type' => 'page' ) );
|
||||
$link = get_permalink( $page );
|
||||
|
||||
add_filter(
|
||||
'page_menu_link_attributes',
|
||||
function( $atts ) use ( $value ) {
|
||||
$atts['data-test'] = $value;
|
||||
return $atts;
|
||||
}
|
||||
);
|
||||
|
||||
$this->walker->start_el( $output, $page, 0 );
|
||||
|
||||
if ( '' !== $expected ) {
|
||||
$expected = sprintf( ' data-test="%s"', $expected );
|
||||
}
|
||||
|
||||
$this->assertSame( "<li class=\"page_item page-item-{$page->ID}\"><a href=\"{$link}\"{$expected}>{$page->post_title}</a>", $output );
|
||||
}
|
||||
|
||||
public function data_start_el_with_empty_attributes() {
|
||||
return array(
|
||||
array(
|
||||
'',
|
||||
'',
|
||||
),
|
||||
array(
|
||||
0,
|
||||
'0',
|
||||
),
|
||||
array(
|
||||
0.0,
|
||||
'0',
|
||||
),
|
||||
array(
|
||||
'0',
|
||||
'0',
|
||||
),
|
||||
array(
|
||||
null,
|
||||
'',
|
||||
),
|
||||
array(
|
||||
false,
|
||||
'',
|
||||
),
|
||||
array(
|
||||
true,
|
||||
'1',
|
||||
),
|
||||
array(
|
||||
array(),
|
||||
'',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user