Make WordPress Core


Ignore:
Timestamp:
10/02/2025 09:46:07 PM (5 months ago)
Author:
joedolson
Message:

Privacy: A11y: Show time of privacy request status change.

Add the date and time of privacy request status changes in the privacy requests table. Previously, human_time_diff() was used in the first 24 hours, and only the date after 24 hours. Change the output to display both date and time after 24 hours, using the format used for comments.

Props birgire, desrosj, afercia, xkon, tz-media, garrett-eclipse, sirlouen, sukhendu2002, sajjad67, fakhriaz, joedolson.
Fixes #44267.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/admin/wpPrivacyRequestsTable.php

    r60729 r60891  
    210210        $this->assertSame( $expected, $this->get_mocked_class_instance()->get_views() );
    211211    }
     212
     213    /**
     214     * Test the get_timestamp_as_date method formats timestamps correctly.
     215     *
     216     * @ticket 44267
     217     *
     218     * @covers WP_Privacy_Requests_Table::get_timestamp_as_date
     219     */
     220    public function test_get_timestamp_as_date() {
     221        $table = $this->get_mocked_class_instance();
     222
     223        $reflection = new ReflectionClass( $table );
     224        $method     = $reflection->getMethod( 'get_timestamp_as_date' );
     225        $method->setAccessible( true );
     226
     227        $date_format = __( 'Y/m/d' );
     228        $time_format = __( 'g:i a' );
     229
     230        $current_time = time();
     231
     232        $this->assertSame( '', $method->invoke( $table, '' ) );
     233
     234        // Test recent timestamp (less than 24 hours ago).
     235        $recent_time = $current_time - HOUR_IN_SECONDS;
     236        $result      = $method->invoke( $table, $recent_time );
     237        $this->assertStringContainsString( 'ago', $result );
     238
     239        $old_time = $current_time - 2 * DAY_IN_SECONDS;
     240        $result   = $method->invoke( $table, $old_time );
     241
     242        $date_part = date_i18n( $date_format, $old_time );
     243        $time_part = date_i18n( $time_format, $old_time );
     244
     245        $this->assertStringContainsString( $date_part, $result );
     246        $this->assertStringContainsString( 'at', $result );
     247        $this->assertStringContainsString( $time_part, $result );
     248    }
    212249}
Note: See TracChangeset for help on using the changeset viewer.