| 1357 | /** |
| 1358 | * Testing the `wp_posts_personal_data_exporter()` function. |
| 1359 | * |
| 1360 | * @ticket 43440 |
| 1361 | * @group privacy |
| 1362 | */ |
| 1363 | public function test_wp_posts_personal_data_exporter() { |
| 1364 | $args = array( |
| 1365 | 'post_title' => 'My Post', |
| 1366 | 'author' => self::$editor_id, |
| 1367 | 'post_type' => 'post', |
| 1368 | 'post_status' => 'publish', |
| 1369 | ); |
| 1370 | |
| 1371 | $test_post = self::factory()->post->create_and_get( $args ); |
| 1372 | $test_author = new WP_User( self::$editor_id ); |
| 1373 | |
| 1374 | $actual = wp_posts_personal_data_exporter( $test_author->data->user_email ); |
| 1375 | |
| 1376 | $this->assertTrue( $actual['done'] ); |
| 1377 | |
| 1378 | // Number of exported posts. |
| 1379 | $this->assertSame( 1, count( $actual['data'] ) ); |
| 1380 | |
| 1381 | // Number of exported post properties. |
| 1382 | $this->assertSame( 2, count( $actual['data'][0]['data'] ) ); |
| 1383 | |
| 1384 | // Exported group. |
| 1385 | $this->assertSame( 'posts', $actual['data'][0]['group_id'] ); |
| 1386 | $this->assertSame( 'Posts / Pages', $actual['data'][0]['group_label'] ); |
| 1387 | |
| 1388 | // Exported post properties. |
| 1389 | $this->assertSame( $test_post->post_title, $actual['data'][0]['data'][0]['value'] ); |
| 1390 | $this->assertSame( $test_post->guid, $actual['data'][0]['data'][1]['value'] ); |
| 1391 | |
| 1392 | wp_delete_post( $test_post->ID, true ); |
| 1393 | } |
| 1394 | |
| 1395 | /** |
| 1396 | * Testing the `wp_posts_personal_data_exporter()` function when a user has |
| 1397 | * a private post. |
| 1398 | * |
| 1399 | * @ticket 43440 |
| 1400 | * @group privacy |
| 1401 | */ |
| 1402 | public function test_wp_posts_personal_data_exporter_private_post() { |
| 1403 | $args = array( |
| 1404 | 'post_title' => 'My Post', |
| 1405 | 'author' => self::$editor_id, |
| 1406 | 'post_type' => 'post', |
| 1407 | 'post_status' => 'private', |
| 1408 | ); |
| 1409 | |
| 1410 | $test_post = self::factory()->post->create_and_get( $args ); |
| 1411 | $test_author = new WP_User( self::$editor_id ); |
| 1412 | |
| 1413 | $actual = wp_posts_personal_data_exporter( $test_author->data->user_email ); |
| 1414 | |
| 1415 | $this->assertTrue( $actual['done'] ); |
| 1416 | |
| 1417 | // Number of exported post properties. |
| 1418 | $this->assertSame( 2, count( $actual['data'][0]['data'] ) ); |
| 1419 | |
| 1420 | // Exported post properties. |
| 1421 | $this->assertSame( 'Private: ' . $test_post->post_title, $actual['data'][0]['data'][0]['value'] ); |
| 1422 | $this->assertSame( $test_post->ID, $actual['data'][0]['data'][1]['value'] ); |
| 1423 | |
| 1424 | wp_delete_post( $test_post->ID, true ); |
| 1425 | } |
| 1426 | |
| 1427 | /** |
| 1428 | * Testing the `wp_posts_personal_data_exporter()` function when a user has |
| 1429 | * a private post. |
| 1430 | * |
| 1431 | * @ticket 43440 |
| 1432 | * @group privacy |
| 1433 | */ |
| 1434 | public function test_wp_posts_personal_data_exporter_password_protected_post() { |
| 1435 | $args = array( |
| 1436 | 'post_title' => 'My Post', |
| 1437 | 'author' => self::$editor_id, |
| 1438 | 'post_type' => 'post', |
| 1439 | 'post_status' => 'publish', |
| 1440 | 'post_password' => 'password', |
| 1441 | ); |
| 1442 | |
| 1443 | $test_post = self::factory()->post->create_and_get( $args ); |
| 1444 | $test_author = new WP_User( self::$editor_id ); |
| 1445 | |
| 1446 | $actual = wp_posts_personal_data_exporter( $test_author->data->user_email ); |
| 1447 | |
| 1448 | $this->assertTrue( $actual['done'] ); |
| 1449 | |
| 1450 | // Number of exported post properties. |
| 1451 | $this->assertSame( 2, count( $actual['data'][0]['data'] ) ); |
| 1452 | |
| 1453 | // Exported post properties. |
| 1454 | $this->assertSame( 'Password Protected: ' . $test_post->post_title, $actual['data'][0]['data'][0]['value'] ); |
| 1455 | $this->assertSame( $test_post->ID, $actual['data'][0]['data'][1]['value'] ); |
| 1456 | |
| 1457 | wp_delete_post( $test_post->ID, true ); |
| 1458 | } |
| 1459 | |
| 1460 | /** |
| 1461 | * Testing the `wp_posts_personal_data_exporter()` function for no posts found. |
| 1462 | * |
| 1463 | * @ticket 43440 |
| 1464 | * @group privacy |
| 1465 | */ |
| 1466 | public function test_wp_posts_personal_data_exporter_no_posts_found() { |
| 1467 | $actual = wp_posts_personal_data_exporter( 'nopostsfound@local.host' ); |
| 1468 | |
| 1469 | $expected = array( |
| 1470 | 'data' => array(), |
| 1471 | 'done' => true, |
| 1472 | ); |
| 1473 | |
| 1474 | $this->assertSame( $expected, $actual ); |
| 1475 | } |
| 1476 | |
| 1477 | /** |
| 1478 | * Testing the `wp_posts_personal_data_exporter()` function with an empty second page. |
| 1479 | * |
| 1480 | * @ticket 43440 |
| 1481 | * @group privacy |
| 1482 | */ |
| 1483 | public function test_wp_posts_personal_data_exporter_second_page() { |
| 1484 | $args = array( |
| 1485 | 'post_title' => 'Some Post', |
| 1486 | 'author' => self::$editor_id, |
| 1487 | 'post_type' => 'post', |
| 1488 | 'post_status' => 'publish', |
| 1489 | ); |
| 1490 | |
| 1491 | $test_post = self::factory()->post->create_and_get( $args ); |
| 1492 | $test_author = new WP_User( self::$editor_id ); |
| 1493 | |
| 1494 | $actual = wp_posts_personal_data_exporter( $test_author->data->user_email, 2 ); |
| 1495 | |
| 1496 | $this->assertTrue( $actual['done'] ); |
| 1497 | |
| 1498 | // Number of exported comments. |
| 1499 | $this->assertSame( 0, count( $actual['data'] ) ); |
| 1500 | } |