| | 1 | <?php |
| | 2 | |
| | 3 | /** |
| | 4 | * @group wp-login |
| | 5 | */ |
| | 6 | class Tests_WP_Login extends WP_UnitTestCase { |
| | 7 | |
| | 8 | /** |
| | 9 | * Include just the PHP functions of a file for testing. |
| | 10 | */ |
| | 11 | public function include_php_functions( $path ) { |
| | 12 | $inc_lines = array(); |
| | 13 | $in_func = $in_script = false; |
| | 14 | $lines = explode( "\n", file_get_contents( ABSPATH . '/wp-login.php' ) ); |
| | 15 | foreach ( $lines as $line ) { |
| | 16 | if ( $in_func ) { |
| | 17 | $inc_lines[] = $line; |
| | 18 | if ( 0 === strpos( $line, '}' ) ) { |
| | 19 | $in_func = false; |
| | 20 | } |
| | 21 | } elseif ( $in_script ) { |
| | 22 | if ( 0 === strpos( $line, '</script' ) ) { |
| | 23 | $in_script = false; |
| | 24 | } |
| | 25 | } elseif ( 0 === strpos( $line, '<script' ) ) { |
| | 26 | $in_script = true; |
| | 27 | } elseif ( 0 === strpos( $line, 'function ' ) ) { |
| | 28 | $in_func = true; |
| | 29 | $inc_lines[] = $line; |
| | 30 | } |
| | 31 | } |
| | 32 | if ( $inc_lines ) { |
| | 33 | $inc = implode( "\n", $inc_lines ); |
| | 34 | eval( $inc ); |
| | 35 | } |
| | 36 | } |
| | 37 | |
| | 38 | public function setUp() { |
| | 39 | $this->include_php_functions( ABSPATH . '/wp-login.php' ); |
| | 40 | } |
| | 41 | |
| | 42 | /** |
| | 43 | * Check can retrieve password when email address includes apostrophes. |
| | 44 | * |
| | 45 | * @ticket 36322 |
| | 46 | */ |
| | 47 | function test_retrieve_password_email_unslashed() { |
| | 48 | $email = 'sean.o\'dough@example.com'; |
| | 49 | $slashed_email = wp_slash( $email ); |
| | 50 | |
| | 51 | // Add user. |
| | 52 | $_POST = array(); |
| | 53 | $_POST['user_login'] = 'Sean O Dough'; |
| | 54 | $_POST['role'] = 'subscriber'; |
| | 55 | $_POST['email'] = $slashed_email; |
| | 56 | $_POST['first_name'] = 'Seán'; |
| | 57 | $_POST['last_name'] = 'O\\\'Dough'; |
| | 58 | $_POST['nickname'] = 'O\\\'Doughie'; |
| | 59 | $_POST['display_name'] = 'Seán O\\\'Dough'; |
| | 60 | $_POST['pass1'] = $_POST['pass2'] = 'password'; |
| | 61 | |
| | 62 | $user_id = edit_user(); |
| | 63 | $user = get_user_by( 'ID', $user_id ); |
| | 64 | |
| | 65 | $this->assertInternalType( 'int', $user_id ); |
| | 66 | $this->assertInstanceOf( 'WP_User', $user ); |
| | 67 | $this->assertEquals( $_POST['user_login'], $user->user_login ); |
| | 68 | $this->assertEquals( $email, $user->user_email ); |
| | 69 | |
| | 70 | // Retrieve password by email. |
| | 71 | $_POST = array(); |
| | 72 | $_POST['user_login'] = $slashed_email; |
| | 73 | |
| | 74 | $response = retrieve_password(); |
| | 75 | $this->assertTrue( $response ); |
| | 76 | } |
| | 77 | } |