Make WordPress Core

Ticket #63986: 63986-tests.diff

File 63986-tests.diff, 1.5 KB (added by motylanogha, 3 months ago)

Unit test: IPv6 REMOTE_ADDR preserved by wpmu_log_new_registrations(). Passes against PR #9911, fails on trunk.

  • tests/phpunit/tests/multisite/wpmuLogNewRegistrations.php

    diff --git a/tests/phpunit/tests/multisite/wpmuLogNewRegistrations.php b/tests/phpunit/tests/multisite/wpmuLogNewRegistrations.php
    index 56a0915b93..26740d4725 100644
    a b class Tests_Multisite_wpmuLogNewRegistrations extends WP_UnitTestCase {  
    1818                $reg_blog = $wpdb->get_col( $wpdb->prepare( "SELECT email FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.blog_id = 1 AND IP LIKE %s", $ip ) );
    1919                $this->assertSame( $user->user_email, $reg_blog[ count( $reg_blog ) - 1 ] );
    2020        }
     21
     22        /**
     23         * Ensures an IPv6 remote address is preserved when logging a registration.
     24         *
     25         * @ticket 63986
     26         */
     27        public function test_wpmu_log_new_registrations_preserves_ipv6_address() {
     28                global $wpdb;
     29
     30                $ipv6                   = '2001:0db8:85a3:0000:0000:8a2e:0370:7334';
     31                $original_remote_addr   = isset( $_SERVER['REMOTE_ADDR'] ) ? $_SERVER['REMOTE_ADDR'] : null;
     32                $_SERVER['REMOTE_ADDR'] = $ipv6;
     33
     34                try {
     35                        wpmu_log_new_registrations( 1, 1 );
     36
     37                        $logged_ip = $wpdb->get_var( "SELECT IP FROM {$wpdb->registration_log} WHERE blog_id = 1 ORDER BY ID DESC LIMIT 1" );
     38                } finally {
     39                        if ( null === $original_remote_addr ) {
     40                                unset( $_SERVER['REMOTE_ADDR'] );
     41                        } else {
     42                                $_SERVER['REMOTE_ADDR'] = $original_remote_addr;
     43                        }
     44                }
     45
     46                $this->assertSame(
     47                        $ipv6,
     48                        $logged_ip,
     49                        'The IPv6 remote address was not stored intact in the registration log.'
     50                );
     51        }
    2152}