| | 1424 | /** |
| | 1425 | * Checks that edit_user() correctly sanitizes the supplied email address |
| | 1426 | * |
| | 1427 | * @ticket 45714 |
| | 1428 | */ |
| | 1429 | function test_edit_user_sanitize_password() { |
| | 1430 | $_POST = $_GET = $_REQUEST = array(); |
| | 1431 | |
| | 1432 | $user = $this->factory()->user->create_and_get( array( |
| | 1433 | 'email' => 'eusp1@example.com', |
| | 1434 | ) ); |
| | 1435 | |
| | 1436 | $_POST['nickname'] = 'eusp1'; |
| | 1437 | $_POST['user_login'] = $user->user_login; |
| | 1438 | |
| | 1439 | // Success cases |
| | 1440 | foreach ( array( |
| | 1441 | 'eusp2@example.com' => 'eusp2@example.com', |
| | 1442 | 'eusp3%4@example.com' => 'eusp3%4@example.com', |
| | 1443 | 'eusp4@example.com!' => 'eusp4@example.com', |
| | 1444 | ' eusp6@example.com%aa ' => 'eusp6@example.comaa', |
| | 1445 | 'eu\'sp@example.com' => 'eu\'sp@example.com', |
| | 1446 | ) as $em_pre => $em_post ) { |
| | 1447 | $_POST['email'] = $em_pre; |
| | 1448 | |
| | 1449 | $user_id = edit_user( $user->ID ); |
| | 1450 | |
| | 1451 | $this->assertInternalType( 'int', $user_id ); |
| | 1452 | |
| | 1453 | $user = get_user_by( 'ID', $user_id ); |
| | 1454 | |
| | 1455 | $this->assertInstanceOf( 'WP_User', $user ); |
| | 1456 | $this->assertEquals( $em_post, $user->user_email ); |
| | 1457 | } |
| | 1458 | |
| | 1459 | // Failure cases (resulting in an invalid email address) |
| | 1460 | foreach ( array( |
| | 1461 | '' => '', |
| | 1462 | 'eusp5' => 'eusp5', |
| | 1463 | ) as $em_pre => $em_post ) { |
| | 1464 | $_POST['email'] = $em_pre; |
| | 1465 | $user_id = edit_user( $user->ID ); |
| | 1466 | |
| | 1467 | /** @type WP_Error $user_id */ |
| | 1468 | $this->assertInstanceOf( 'WP_Error', $user_id ); |
| | 1469 | $this->assertEquals('empty_email', $user_id->get_error_code()); |
| | 1470 | } |
| | 1471 | } |
| | 1472 | |