<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[56072] trunk: Media: Only show {U+201C}Copy{U+201D} and {U+201C}Download{U+201D} actions when an attachment URL is available.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/56072">56072</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/56072","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>SergeyBiryukov</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2023-06-27 16:26:15 +0000 (Tue, 27 Jun 2023)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Media: Only show {U+201C}Copy{U+201D} and {U+201C}Download{U+201D} actions when an attachment URL is available.
Includes unit tests to verify the logic for displaying row actions in the Media Library in certain scenarios, e.g. with and without the {U+201C}Trash{U+201D} or {U+201C}Unattached{U+201D} filter.
Follow-up to <a href="https://core.trac.wordpress.org/changeset/55949">[55949]</a>.
Props costdev, kebbet, mukesh27, oglekler.
Fixes <a href="https://core.trac.wordpress.org/ticket/57893">#57893</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadminincludesclasswpmedialisttablephp">trunk/src/wp-admin/includes/class-wp-media-list-table.php</a></li>
<li><a href="#trunktestsphpunittestsadminwpMediaListTablephp">trunk/tests/phpunit/tests/admin/wpMediaListTable.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadminincludesclasswpmedialisttablephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/class-wp-media-list-table.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/class-wp-media-list-table.php 2023-06-27 16:25:18 UTC (rev 56071)
+++ trunk/src/wp-admin/includes/class-wp-media-list-table.php 2023-06-27 16:26:15 UTC (rev 56072)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -816,24 +816,28 @@
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $actions['copy'] = sprintf(
- '<span class="copy-to-clipboard-container"><button type="button" class="button-link copy-attachment-url media-library" data-clipboard-text="%s" aria-label="%s">%s</button><span class="success hidden" aria-hidden="true">%s</span></span>',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $attachment_url ) {
+ $actions['copy'] = sprintf(
+ '<span class="copy-to-clipboard-container"><button type="button" class="button-link copy-attachment-url media-library" data-clipboard-text="%s" aria-label="%s">%s</button><span class="success hidden" aria-hidden="true">%s</span></span>',
+ esc_url( $attachment_url ),
+ /* translators: %s: Attachment title. */
+ esc_attr( sprintf( __( 'Copy “%s” URL to clipboard' ), $att_title ) ),
+ __( 'Copy URL' ),
+ __( 'Copied!' )
+ );
+ }
+ }
+
+ if ( $attachment_url ) {
+ $actions['download'] = sprintf(
+ '<a href="%s" aria-label="%s" download>%s</a>',
</ins><span class="cx" style="display: block; padding: 0 10px"> esc_url( $attachment_url ),
</span><span class="cx" style="display: block; padding: 0 10px"> /* translators: %s: Attachment title. */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- esc_attr( sprintf( __( 'Copy “%s” URL to clipboard' ), $att_title ) ),
- __( 'Copy URL' ),
- __( 'Copied!' )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ esc_attr( sprintf( __( 'Download “%s”' ), $att_title ) ),
+ __( 'Download file' )
</ins><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $actions['download'] = sprintf(
- '<a href="%s" aria-label="%s" download>%s</a>',
- esc_url( $attachment_url ),
- /* translators: %s: Attachment title. */
- esc_attr( sprintf( __( 'Download “%s”' ), $att_title ) ),
- __( 'Download file' )
- );
-
</del><span class="cx" style="display: block; padding: 0 10px"> if ( $this->detached && current_user_can( 'edit_post', $post->ID ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $actions['attach'] = sprintf(
</span><span class="cx" style="display: block; padding: 0 10px"> '<a href="#the-list" onclick="findPosts.open( \'media[]\', \'%s\' ); return false;" class="hide-if-no-js aria-button-if-js" aria-label="%s">%s</a>',
</span></span></pre></div>
<a id="trunktestsphpunittestsadminwpMediaListTablephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/admin/wpMediaListTable.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/admin/wpMediaListTable.php 2023-06-27 16:25:18 UTC (rev 56071)
+++ trunk/tests/phpunit/tests/admin/wpMediaListTable.php 2023-06-27 16:26:15 UTC (rev 56072)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4,14 +4,112 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @group admin
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> class Tests_Admin_wpMediaListTable extends WP_UnitTestCase {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * A list table for testing.
+ *
+ * @var WP_Media_List_Table
+ */
+ protected static $list_table;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * A reflection of the `$is_trash` property.
+ *
+ * @var ReflectionProperty
+ */
+ protected static $is_trash;
+
+ /**
+ * The original value of the `$is_trash` property.
+ *
+ * @var bool|null
+ */
+ protected static $is_trash_original;
+
+ /**
+ * A reflection of the `$detached` property.
+ *
+ * @var ReflectionProperty
+ */
+ protected static $detached;
+
+ /**
+ * The original value of the `$detached` property.
+ *
+ * @var bool|null
+ */
+ protected static $detached_original;
+
+ /**
+ * The ID of an 'administrator' user for testing.
+ *
+ * @var int
+ */
+ protected static $admin;
+
+ /**
+ * The ID of a 'subscriber' user for testing.
+ *
+ * @var int
+ */
+ protected static $subscriber;
+
+ /**
+ * A post for testing.
+ *
+ * @var WP_Post
+ */
+ protected static $post;
+
+ /**
+ * An attachment for testing.
+ *
+ * @var WP_Post
+ */
+ protected static $attachment;
+
</ins><span class="cx" style="display: block; padding: 0 10px"> public static function set_up_before_class() {
</span><span class="cx" style="display: block; padding: 0 10px"> parent::set_up_before_class();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> require_once ABSPATH . 'wp-admin/includes/class-wp-media-list-table.php';
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ self::$list_table = new WP_Media_List_Table();
+ self::$is_trash = new ReflectionProperty( self::$list_table, 'is_trash' );
+ self::$detached = new ReflectionProperty( self::$list_table, 'detached' );
+
+ self::$is_trash->setAccessible( true );
+ self::$is_trash_original = self::$is_trash->getValue( self::$list_table );
+ self::$is_trash->setAccessible( false );
+
+ self::$detached->setAccessible( true );
+ self::$detached_original = self::$detached->getValue( self::$list_table );
+ self::$detached->setAccessible( false );
+
+ // Create users.
+ self::$admin = self::factory()->user->create( array( 'role' => 'administrator' ) );
+ self::$subscriber = self::factory()->user->create( array( 'role' => 'subscriber' ) );
+
+ // Create posts.
+ self::$post = self::factory()->post->create_and_get();
+ self::$attachment = self::factory()->attachment->create_and_get(
+ array(
+ 'post_name' => 'attachment-name',
+ 'file' => 'image.jpg',
+ 'post_mime_type' => 'image/jpeg',
+ )
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Restores reflections to their original values.
+ */
+ public function tear_down() {
+ self::set_is_trash( self::$is_trash_original );
+ self::set_detached( self::$detached_original );
+
+ parent::tear_down();
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Tests that a call to WP_Media_List_Table::prepare_items() on a site without any scheduled events
</span><span class="cx" style="display: block; padding: 0 10px"> * does not result in a PHP warning.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -49,4 +147,325 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // If this test does not error out due to the PHP warning, we're good.
</span><span class="cx" style="display: block; padding: 0 10px"> $mock->prepare_items();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ /**
+ * Tests that `WP_Media_List_Table::_get_row_actions()` only includes an action
+ * in certain scenarios.
+ *
+ * @ticket 57893
+ *
+ * @covers WP_Media_List_Table::_get_row_actions
+ *
+ * @dataProvider data_get_row_actions_should_include_action
+ *
+ * @param string $action The action that should be included.
+ * @param string $role The role of the current user.
+ * @param bool|null $trash Whether the attachment filter is currently 'trash',
+ * or `null` to leave as-is.
+ * @param bool|null $detached Whether the attachment filter is currently 'detached',
+ * or `null` to leave as-is.
+ */
+ public function test_get_row_actions_should_include_action( $action, $role, $trash, $detached ) {
+ if ( 'admin' === $role ) {
+ wp_set_current_user( self::$admin );
+ } elseif ( 'subscriber' === $role ) {
+ wp_set_current_user( self::$subscriber );
+ }
+
+ if ( null !== $trash ) {
+ self::set_is_trash( $trash );
+ }
+
+ if ( null !== $detached ) {
+ self::set_detached( $detached );
+ }
+
+ $_get_row_actions = new ReflectionMethod( self::$list_table, '_get_row_actions' );
+ $_get_row_actions->setAccessible( true );
+ $actions = $_get_row_actions->invoke( self::$list_table, self::$post, 'att_title' );
+ $_get_row_actions->setAccessible( false );
+
+ $this->assertIsArray( $actions, 'An array was not returned.' );
+ $this->assertArrayHasKey( $action, $actions, "'$action' was not included in the actions." );
+ }
+
+ /**
+ * Data provider.
+ *
+ * @return array[]
+ */
+ public function data_get_row_actions_should_include_action() {
+ return array(
+ '"edit" while not on "trash"' => array(
+ 'action' => 'edit',
+ 'role' => 'admin',
+ 'trash' => false,
+ 'detached' => null,
+ ),
+ '"untrash" while on "trash"' => array(
+ 'action' => 'untrash',
+ 'role' => 'admin',
+ 'trash' => true,
+ 'detached' => null,
+ ),
+ '"delete" while on "trash"' => array(
+ 'action' => 'delete',
+ 'role' => 'admin',
+ 'trash' => true,
+ 'detached' => null,
+ ),
+ '"view" while not on "trash"' => array(
+ 'action' => 'view',
+ 'role' => 'admin',
+ 'trash' => false,
+ 'detached' => null,
+ ),
+ '"attach" while on "detached"' => array(
+ 'action' => 'attach',
+ 'role' => 'admin',
+ 'trash' => null,
+ 'detached' => true,
+ ),
+ );
+ }
+
+ /**
+ * Tests that `WP_Media_List_Table::_get_row_actions()` does not include an action
+ * in certain scenarios.
+ *
+ * @ticket 57893
+ *
+ * @covers WP_Media_List_Table::_get_row_actions
+ *
+ * @dataProvider data_get_row_actions_should_not_include_action
+ *
+ * @param string $action The action that should not be included.
+ * @param string $role The role of the current user.
+ * @param bool|null $trash Whether the attachment filter is currently 'trash',
+ * or `null` to leave as-is.
+ * @param bool|null $detached Whether the attachment filter is currently 'detached',
+ * or `null` to leave as-is.
+ */
+ public function test_get_row_actions_should_not_include_action( $action, $role, $trash, $detached ) {
+ if ( 'admin' === $role ) {
+ wp_set_current_user( self::$admin );
+ } elseif ( 'subscriber' === $role ) {
+ wp_set_current_user( self::$subscriber );
+ }
+
+ if ( null !== $trash ) {
+ self::set_is_trash( $trash );
+ }
+
+ if ( null !== $detached ) {
+ self::set_detached( $detached );
+ }
+
+ $_get_row_actions = new ReflectionMethod( self::$list_table, '_get_row_actions' );
+ $_get_row_actions->setAccessible( true );
+ $actions = $_get_row_actions->invoke( self::$list_table, self::$post, 'att_title' );
+ $_get_row_actions->setAccessible( false );
+
+ $this->assertIsArray( $actions, 'An array was not returned.' );
+ $this->assertArrayNotHasKey( $action, $actions, "'$action' was included in the actions." );
+ }
+
+ /**
+ * Data provider.
+ *
+ * @return array[]
+ */
+ public function data_get_row_actions_should_not_include_action() {
+ return array(
+ '"edit" while on "trash"' => array(
+ 'action' => 'edit',
+ 'role' => 'admin',
+ 'trash' => true,
+ 'detached' => null,
+ ),
+ '"edit" with incorrect capabilities' => array(
+ 'action' => 'edit',
+ 'role' => 'subscriber',
+ 'trash' => false,
+ 'detached' => null,
+ ),
+ '"untrash" while not on "trash"' => array(
+ 'action' => 'untrash',
+ 'role' => 'administrator',
+ 'trash' => false,
+ 'detached' => null,
+ ),
+ '"untrash" with incorrect capabilities' => array(
+ 'action' => 'untrash',
+ 'role' => 'subscriber',
+ 'trash' => true,
+ 'detached' => null,
+ ),
+ '"trash" while not on "trash"' => array(
+ 'action' => 'trash',
+ 'role' => 'administrator',
+ 'trash' => false,
+ 'detached' => null,
+ ),
+ '"trash" with incorrect capabilities' => array(
+ 'action' => 'trash',
+ 'role' => 'subscriber',
+ 'trash' => true,
+ 'detached' => null,
+ ),
+ '"view" while on "trash"' => array(
+ 'action' => 'view',
+ 'role' => 'administrator',
+ 'trash' => true,
+ 'detached' => null,
+ ),
+ '"attach" with incorrect capabilities' => array(
+ 'action' => 'attach',
+ 'role' => 'subscriber',
+ 'trash' => null,
+ 'detached' => true,
+ ),
+ '"attach" when not on "detached"' => array(
+ 'action' => 'attach',
+ 'role' => 'administrator',
+ 'trash' => null,
+ 'detached' => false,
+ ),
+ '"copy" when on "trash"' => array(
+ 'action' => 'copy',
+ 'role' => 'administrator',
+ 'trash' => true,
+ 'detached' => null,
+ ),
+ );
+ }
+
+ /**
+ * Tests that `WP_Media_List_Table::_get_row_actions()` does not include the 'view' action
+ * when a permalink is not available.
+ *
+ * @ticket 57893
+ *
+ * @covers WP_Media_List_Table::_get_row_actions
+ */
+ public function test_get_row_actions_should_not_include_view_without_a_permalink() {
+ self::set_is_trash( false );
+
+ // Ensure the permalink is `false`.
+ add_filter( 'post_link', '__return_false', 10, 0 );
+
+ $_get_row_actions = new ReflectionMethod( self::$list_table, '_get_row_actions' );
+ $_get_row_actions->setAccessible( true );
+ $actions = $_get_row_actions->invoke( self::$list_table, self::$post, 'att_title' );
+ $_get_row_actions->setAccessible( false );
+
+ $this->assertIsArray( $actions, 'An array was not returned.' );
+ $this->assertArrayNotHasKey( 'view', $actions, '"view" was included in the actions.' );
+ }
+
+ /**
+ * Tests that `WP_Media_List_Table::_get_row_actions()` includes the 'copy' action.
+ *
+ * @ticket 57893
+ *
+ * @covers WP_Media_List_Table::_get_row_actions
+ */
+ public function test_get_row_actions_should_include_copy() {
+ self::set_is_trash( false );
+
+ $_get_row_actions = new ReflectionMethod( self::$list_table, '_get_row_actions' );
+ $_get_row_actions->setAccessible( true );
+ $actions = $_get_row_actions->invoke( self::$list_table, self::$attachment, 'att_title' );
+ $_get_row_actions->setAccessible( false );
+
+ $this->assertIsArray( $actions, 'An array was not returned.' );
+ $this->assertArrayHasKey( 'copy', $actions, '"copy" was not included in the actions.' );
+ }
+
+ /**
+ * Tests that `WP_Media_List_Table::_get_row_actions()` does not include the 'copy' action
+ * when an attachment URL is not available.
+ *
+ * @ticket 57893
+ *
+ * @covers WP_Media_List_Table::_get_row_actions
+ */
+ public function test_get_row_actions_should_not_include_copy_without_an_attachment_url() {
+ self::set_is_trash( false );
+
+ // Ensure the attachment URL is `false`.
+ add_filter( 'wp_get_attachment_url', '__return_false', 10, 0 );
+
+ $_get_row_actions = new ReflectionMethod( self::$list_table, '_get_row_actions' );
+ $_get_row_actions->setAccessible( true );
+ $actions = $_get_row_actions->invoke( self::$list_table, self::$attachment, 'att_title' );
+ $_get_row_actions->setAccessible( false );
+
+ $this->assertIsArray( $actions, 'An array was not returned.' );
+ $this->assertArrayNotHasKey( 'copy', $actions, '"copy" was included in the actions.' );
+ }
+
+ /**
+ * Tests that `WP_Media_List_Table::_get_row_actions()` includes the 'download' action.
+ *
+ * @ticket 57893
+ *
+ * @covers WP_Media_List_Table::_get_row_actions
+ */
+ public function test_get_row_actions_should_include_download() {
+ $_get_row_actions = new ReflectionMethod( self::$list_table, '_get_row_actions' );
+ $_get_row_actions->setAccessible( true );
+ $actions = $_get_row_actions->invoke( self::$list_table, self::$attachment, 'att_title' );
+ $_get_row_actions->setAccessible( false );
+
+ $this->assertIsArray( $actions, 'An array was not returned.' );
+ $this->assertArrayHasKey( 'download', $actions, '"download" was not included in the actions.' );
+ }
+
+ /**
+ * Tests that `WP_Media_List_Table::_get_row_actions()` does not include the 'download' action
+ * when an attachment URL is not available.
+ *
+ * @ticket 57893
+ *
+ * @covers WP_Media_List_Table::_get_row_actions
+ */
+ public function test_get_row_actions_should_not_include_download_without_an_attachment_url() {
+ // Ensure the attachment URL is `false`.
+ add_filter( 'wp_get_attachment_url', '__return_false', 10, 0 );
+
+ $_get_row_actions = new ReflectionMethod( self::$list_table, '_get_row_actions' );
+ $_get_row_actions->setAccessible( true );
+ $actions = $_get_row_actions->invoke( self::$list_table, self::$attachment, 'att_title' );
+ $_get_row_actions->setAccessible( false );
+
+ $this->assertIsArray( $actions, 'An array was not returned.' );
+ $this->assertArrayNotHasKey( 'download', $actions, '"download" was included in the actions.' );
+ }
+
+ /**
+ * Sets the `$is_trash` property.
+ *
+ * Helper method.
+ *
+ * @param bool $is_trash Whether the attachment filter is currently 'trash'.
+ */
+ private static function set_is_trash( $is_trash ) {
+ self::$is_trash->setAccessible( true );
+ self::$is_trash->setValue( self::$list_table, $is_trash );
+ self::$is_trash->setAccessible( false );
+ }
+
+ /**
+ * Sets the `$detached` property.
+ *
+ * Helper method.
+ *
+ * @param bool $detached Whether the attachment filter is currently 'detached'.
+ */
+ private static function set_detached( $detached ) {
+ self::$detached->setAccessible( true );
+ self::$detached->setValue( self::$list_table, $detached );
+ self::$detached->setAccessible( false );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>
</body>
</html>