| 1 | <?php |
| 2 | /** |
| 3 | * Test the `_wp_privacy_completed_request()` function. |
| 4 | * |
| 5 | * @package WordPress\UnitTests |
| 6 | * |
| 7 | * @since 4.9.6 |
| 8 | */ |
| 9 | |
| 10 | /** |
| 11 | * Tests_PrivacyCompletedRequest class. |
| 12 | * |
| 13 | * @group privacy |
| 14 | * @covers _wp_privacy_completed_request |
| 15 | * |
| 16 | * @since 4.9.6 |
| 17 | */ |
| 18 | class Tests_PrivacyCompletedRequest extends WP_UnitTestCase { |
| 19 | /** |
| 20 | * Request ID |
| 21 | * |
| 22 | * @since 4.9.6 |
| 23 | * |
| 24 | * @var int $request_id |
| 25 | */ |
| 26 | protected static $request_id; |
| 27 | |
| 28 | /** |
| 29 | * Create fixtures. |
| 30 | * |
| 31 | * @param WP_UnitTest_Factory $factory Factory. |
| 32 | */ |
| 33 | public static function wpSetUpBeforeClass( $factory ) { |
| 34 | self::$request_id = wp_create_user_request( 'requester@example.com', 'export_personal_data' ); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * The function should return error for invalid request ID. |
| 39 | * |
| 40 | * @ticket 43913 |
| 41 | */ |
| 42 | public function test__wp_privacy_completed_request_should_return_error_for_invalid_request_id() { |
| 43 | $actual = _wp_privacy_completed_request( 0 ); |
| 44 | $this->assertWPError( $actual ); |
| 45 | $this->assertSame( 'privacy_request_error', $actual->get_error_code() ); |
| 46 | |
| 47 | $actual = _wp_privacy_completed_request( PHP_INT_MAX ); |
| 48 | $this->assertWPError( $actual ); |
| 49 | $this->assertSame( 'privacy_request_error', $actual->get_error_code() ); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * The function should mark a request as completed. |
| 54 | * |
| 55 | * @ticket 43913 |
| 56 | */ |
| 57 | public function test__wp_privacy_completed_request_should_mark_request_completed() { |
| 58 | $this->assertSame( 'request-pending', get_post_status( self::$request_id ) ); |
| 59 | $this->assertSame( self::$request_id, _wp_privacy_completed_request( self::$request_id ) ); |
| 60 | $this->assertSame( 'request-completed', get_post_status( self::$request_id ) ); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * The function should log the request timestamp. |
| 65 | * |
| 66 | * @ticket 43913 |
| 67 | */ |
| 68 | public function test__wp_privacy_completed_request_should_log_request_timestamp() { |
| 69 | $this->assertEmpty( get_post_meta( self::$request_id, '_wp_user_request_completed_timestamp', true ) ); |
| 70 | $this->assertSame( self::$request_id, _wp_privacy_completed_request( self::$request_id ) ); |
| 71 | $this->assertNotEmpty( get_post_meta( self::$request_id, '_wp_user_request_completed_timestamp', true ) ); |
| 72 | } |
| 73 | } |