Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,12 @@ public function print_js_template_row() {
$classes .= ' hidden';
}

printf( '<td class="%s" data-colname="%s">', esc_attr( $classes ), esc_attr( wp_strip_all_tags( $display_name ) ) );
// The primary column is a `<th scope="row">` row header, matching the
// server-rendered markup in WP_List_Table::single_row_columns().
$tag = $is_primary ? 'th' : 'td';
$scope = $is_primary ? ' scope="row"' : '';

printf( '<%1$s class="%2$s" data-colname="%3$s"%4$s>', $tag, esc_attr( $classes ), esc_attr( wp_strip_all_tags( $display_name ) ), $scope );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add translators comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mukeshpanchal27. I looked into this, and I don't think a translators comment applies on this line — could you double-check?

This printf() only assembles the opening tag:
printf( '<%1$s class="%2$s" data-colname="%3$s"%4$s>', $tag, esc_attr( $classes ), esc_attr( wp_strip_all_tags( $display_name ) ), $scope );
The %1$s–%4$s placeholders are filled by $tag (th/td), $classes, $display_name, and $scope — none of them is a gettext call, so there's no translatable string here for a translators comment to describe. (The change from %s to numbered placeholders is just to keep the format readable now that there are four arguments.)

Happy to add one if you were pointing at a different line — let me know.


switch ( $column_name ) {
case 'name':
Expand Down Expand Up @@ -259,7 +264,7 @@ public function print_js_template_row() {
'</span></button>';
}

echo '</td>';
echo "</{$tag}>";
}

echo '</tr>';
Expand Down
59 changes: 59 additions & 0 deletions tests/phpunit/tests/admin/wpApplicationPasswordsListTable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

/**
* @group admin
* @group application-passwords
*
* @covers WP_Application_Passwords_List_Table
*/
class Tests_Admin_wpApplicationPasswordsListTable extends WP_UnitTestCase {

/**
* @var WP_Application_Passwords_List_Table
*/
private $table;

public function set_up() {
parent::set_up();
$this->table = _get_list_table(
'WP_Application_Passwords_List_Table',
array( 'screen' => 'application-passwords-user' )
);
}

/**
* Ensures the JavaScript row template used for a password created via AJAX
* renders the primary column as a `<th scope="row">` row header, matching
* the server-rendered markup from WP_List_Table::single_row_columns().
*
* @ticket 65707
*
* @covers WP_Application_Passwords_List_Table::print_js_template_row
*/
public function test_print_js_template_row_uses_th_row_header_for_primary_column() {
ob_start();
$this->table->print_js_template_row();
$html = ob_get_clean();

// Assert on the tag structure and `scope="row"` rather than the localized
// column label, so the test does not depend on the current locale or on
// filters that adjust the column headers.
$this->assertMatchesRegularExpression(
'/<th class="name column-name has-row-actions column-primary" data-colname="[^"]*" scope="row">/',
$html,
'The primary column should be rendered as a <th scope="row"> row header.'
);
Comment on lines +41 to +45

$this->assertStringNotContainsString(
'<td class="name column-name',
$html,
'The primary column should not be rendered as a <td> cell.'
);

$this->assertStringContainsString(
'<td class="created column-created"',
$html,
'Non-primary columns should still be rendered as <td> cells.'
);
}
}
Loading