Changeset 7794
- Timestamp:
- 10/04/2026 08:58:32 AM (5 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/testcases/users/functions/functions.php
r7698 r7794 18 18 /** 19 19 * @covers ::bbp_redirect_login 20 * @todo Implement test_bbp_redirect_login().21 20 */ 22 21 public function test_bbp_redirect_login() { 23 // Remove the following lines when you implement this test.24 $this-> markTestIncomplete(25 'This test has not been implemented yet.'26 );22 $this->assertSame( home_url(), bbp_redirect_login() ); 23 $this->assertSame( home_url(), bbp_redirect_login( admin_url() ) ); 24 $this->assertSame( 'https://example.org/target', bbp_redirect_login( home_url(), 'https://example.org/target' ) ); 25 $this->assertSame( 'https://example.org/manual', bbp_redirect_login( 'https://example.org/manual' ) ); 27 26 } 28 27 29 28 /** 30 29 * @covers ::bbp_is_anonymous 31 * @todo Implement test_bbp_is_anonymous().32 30 */ 33 31 public function test_bbp_is_anonymous() { 34 // Remove the following lines when you implement this test. 35 $this->markTestIncomplete( 36 'This test has not been implemented yet.' 37 ); 32 $old_user = get_current_user_id(); 33 add_filter( 'bbp_allow_anonymous', '__return_true' ); 34 35 try { 36 $this->set_current_user( 0 ); 37 $this->assertTrue( bbp_is_anonymous() ); 38 $this->set_current_user( $this->factory->user->create() ); 39 $this->assertFalse( bbp_is_anonymous() ); 40 $this->set_current_user( 0 ); 41 remove_filter( 'bbp_allow_anonymous', '__return_true' ); 42 $this->assertFalse( bbp_is_anonymous() ); 43 } finally { 44 remove_filter( 'bbp_allow_anonymous', '__return_true' ); 45 $this->set_current_user( $old_user ); 46 } 38 47 } 39 48 40 49 /** 41 50 * @covers ::bbp_current_anonymous_user_data 42 * @todo Implement test_bbp_current_anonymous_user_data().43 51 */ 44 52 public function test_bbp_current_anonymous_user_data() { 45 // Remove the following lines when you implement this test. 46 $this->markTestIncomplete( 47 'This test has not been implemented yet.' 48 ); 53 $name = 'comment_author_' . COOKIEHASH; 54 $old = isset( $_COOKIE[ $name ] ) ? $_COOKIE[ $name ] : null; 55 56 try { 57 $_COOKIE[ $name ] = 'A & B'; 58 $this->expectOutputString( 'A & B' ); 59 bbp_current_anonymous_user_data( 'name' ); 60 } finally { 61 if ( null === $old ) { 62 unset( $_COOKIE[ $name ] ); 63 } else { 64 $_COOKIE[ $name ] = $old; 65 } 66 } 49 67 } 50 68 51 69 /** 52 70 * @covers ::bbp_get_current_anonymous_user_data 53 * @todo Implement test_bbp_get_current_anonymous_user_data().54 71 */ 55 72 public function test_bbp_get_current_anonymous_user_data() { 56 // Remove the following lines when you implement this test. 57 $this->markTestIncomplete( 58 'This test has not been implemented yet.' 59 ); 73 $name = 'comment_author_' . COOKIEHASH; 74 $old = isset( $_COOKIE[ $name ] ) ? $_COOKIE[ $name ] : null; 75 76 try { 77 $_COOKIE[ $name ] = 'Guest'; 78 $this->assertSame( 'Guest', bbp_get_current_anonymous_user_data( 'name' ) ); 79 $this->assertSame( 'Guest', bbp_get_current_anonymous_user_data( 'comment_author' ) ); 80 $this->assertSame( 'Guest', bbp_get_current_anonymous_user_data()['comment_author'] ); 81 $this->assertIsArray( bbp_get_current_anonymous_user_data( 'unknown' ) ); 82 } finally { 83 if ( null === $old ) { 84 unset( $_COOKIE[ $name ] ); 85 } else { 86 $_COOKIE[ $name ] = $old; 87 } 88 } 60 89 } 61 90 … … 73 102 /** 74 103 * @covers ::bbp_current_author_ip 75 * @todo Implement test_bbp_current_author_ip().76 104 */ 77 105 public function test_bbp_current_author_ip() { 78 // Remove the following lines when you implement this test. 79 $this->markTestIncomplete( 80 'This test has not been implemented yet.' 81 ); 106 $old_address = isset( $_SERVER['REMOTE_ADDR'] ) ? $_SERVER['REMOTE_ADDR'] : null; 107 108 try { 109 unset( $_SERVER['REMOTE_ADDR'] ); 110 $this->assertSame( '127.0.0.1', bbp_current_author_ip() ); 111 $_SERVER['REMOTE_ADDR'] = '2001:db8::1<script>'; 112 $this->assertSame( '2001:db8::1c', bbp_current_author_ip() ); 113 } finally { 114 if ( null === $old_address ) { 115 unset( $_SERVER['REMOTE_ADDR'] ); 116 } else { 117 $_SERVER['REMOTE_ADDR'] = $old_address; 118 } 119 } 82 120 } 83 121 84 122 /** 85 123 * @covers ::bbp_current_author_ua 86 * @todo Implement test_bbp_current_author_ua().87 124 */ 88 125 public function test_bbp_current_author_ua() { 89 // Remove the following lines when you implement this test. 90 $this->markTestIncomplete( 91 'This test has not been implemented yet.' 92 ); 126 $old_agent = isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : null; 127 128 try { 129 unset( $_SERVER['HTTP_USER_AGENT'] ); 130 $this->assertSame( '', bbp_current_author_ua() ); 131 $_SERVER['HTTP_USER_AGENT'] = str_repeat( 'a', 255 ); 132 $this->assertSame( str_repeat( 'a', 254 ), bbp_current_author_ua() ); 133 } finally { 134 if ( null === $old_agent ) { 135 unset( $_SERVER['HTTP_USER_AGENT'] ); 136 } else { 137 $_SERVER['HTTP_USER_AGENT'] = $old_agent; 138 } 139 } 93 140 } 94 141
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)