WordPress.org

Make WordPress Core


Ignore:
Timestamp:
08/15/17 09:15:53 (5 months ago)
Author:
johnbillion
Message:

Options, Meta APIs: Update the multisite unit tests after [41254], [41164], and [41163].

This moves some more previously Multisite-only tests into the main test suite, and makes small adjustments to their assertions.

See #39118, #16470, #39117

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/user/multisite.php

    r41225 r41255  
    452452    } 
    453453 
    454  
    455     /** 
    456      * Ensure blog's admin e-mail change notification emails do not contain encoded HTML entities 
    457      * @ticket 40015 
    458      */ 
    459     function test_ms_new_admin_email_notification_html_entities_decoded() { 
    460         reset_phpmailer_instance(); 
    461  
    462         $existing_email = get_option( 'admin_email' ); 
    463         $new_email = 'new-admin-email@test.dev'; 
    464  
    465         // Give the site and blog a name containing HTML entities 
    466         update_site_option( 'site_name', ''Test' site's "name" has <html entities> &' ); 
    467         update_option( 'blogname', ''Test' blog's "name" has <html entities> &' ); 
    468  
    469         update_option_new_admin_email( $existing_email, $new_email ); 
    470  
    471         $mailer = tests_retrieve_phpmailer_instance(); 
    472  
    473         $recipient = $mailer->get_recipient( 'to' ); 
    474         $email = $mailer->get_sent(); 
    475  
    476         // Assert reciepient is correct 
    477         $this->assertSame( $new_email, $recipient->address, 'Admin email change notification recipient not as expected' ); 
    478  
    479         // Assert that HTML entites have been decode in body and subject 
    480         $this->assertContains( '\'Test\' site\'s "name" has <html entities> &', $email->body, 'Email body does not contain the decoded HTML entities' ); 
    481         $this->assertNotContains( '&#039;Test&#039; site&#039;s &quot;name&quot; has &lt;html entities&gt; &amp;', 'Email body does contains HTML entities' ); 
    482         $this->assertContains( '\'Test\' blog\'s "name" has <html entities> &', $email->subject, 'Email subject does not contain the decoded HTML entities' ); 
    483         $this->assertNotContains( '&#039;Test&#039; blog&#039;s &quot;name&quot; has &lt;html entities&gt; &amp;', $email->subject, $email->subject, 'Email subject does contains HTML entities' ); 
    484     } 
    485  
    486     /** 
    487      * A confirmation email should not be sent if the new admin email: 
    488      * - Matches the existing admin email, or 
    489      * - is not a valid email 
    490      * 
    491      * @dataProvider data_user_admin_email_confirmation_emails 
    492      */ 
    493     function test_ms_new_admin_email_confirmation_not_sent_when_email_invalid( $email, $message ) { 
    494         reset_phpmailer_instance(); 
    495  
    496         update_option_new_admin_email( get_option( 'admin_email' ), $email ); 
    497  
    498         $mailer = tests_retrieve_phpmailer_instance(); 
    499  
    500         $this->assertFalse( $mailer->get_sent(), $message ); 
    501     } 
    502  
    503     /** 
    504      * Data provider for test_ms_new_admin_email_confirmation_not_sent_when_email_invalid(). 
    505      * 
    506      * @return array { 
    507      *     @type array { 
    508      *         @type string $email   The new email for admin_email 
    509      *         @type string $message An error message to display if the test fails 
    510      *     } 
    511      * } 
    512      */ 
    513     function data_user_admin_email_confirmation_emails() { 
    514         return array( 
    515             array( 
    516                 get_option( 'admin_email' ), 
    517                 'A confirmation email should not be sent if the current admin email matches the new email', 
    518             ), 
    519             array( 
    520                 'not an email', 
    521                 'A confirmation email should not be sent if it is not a valid email', 
    522             ) 
    523         ); 
    524     } 
    525  
    526     /** 
    527      * A confirmation e-mail should not be sent if user's new e-mail: 
    528      * - Matches their existing email, or 
    529      * - is not a valid e-mail, or 
    530      * - Matches another user's email 
    531      * 
    532      * @dataProvider data_user_change_email_confirmation_emails 
    533      */ 
    534     function test_ms_profile_email_confirmation_not_sent_invalid_email( $email, $message ) { 
    535  
    536         $old_current = get_current_user_id(); 
    537  
    538         $user_id = self::factory()->user->create( array( 
    539             'role'       => 'subscriber', 
    540             'user_email' => 'email@test.dev', 
    541         ) ); 
    542         wp_set_current_user( $user_id ); 
    543  
    544         self::factory()->user->create( array( 
    545             'role'       => 'subscriber', 
    546             'user_email' => 'another-user@test.dev', 
    547         ) ); 
    548  
    549         reset_phpmailer_instance(); 
    550  
    551         // Set $_POST['email'] with new e-mail and $_POST['id'] with user's ID. 
    552         $_POST['user_id'] = $user_id; 
    553         $_POST['email'] = $email; 
    554         send_confirmation_on_profile_email(); 
    555  
    556         $mailer = tests_retrieve_phpmailer_instance(); 
    557  
    558         $this->assertFalse( $mailer->get_sent(), $message ); 
    559  
    560         wp_set_current_user( $old_current ); 
    561     } 
    562  
    563     /** 
    564      * Data provider for test_ms_profile_email_confirmation_not_sent_invalid_email(). 
    565      * 
    566      * @return array { 
    567      *     @type array { 
    568      *         @type string $email   The user's new e-amil. 
    569      *         @type string $message An error message to display if the test fails 
    570      *     } 
    571      * } 
    572      */ 
    573     function data_user_change_email_confirmation_emails() { 
    574         return array( 
    575             array( 
    576                 'email@test.dev', 
    577                 'Confirmation e-mail should not be sent if it matches the user\'s existing e-mail', 
    578             ), 
    579             array( 
    580                 'not an email', 
    581                 'Confirmation e-mail should not be sent if it is not a valid e-mail', 
    582             ), 
    583             array( 
    584                 'another-user@test.dev', 
    585                 'Confirmation e-mail should not be sent if it matches another user\'s e-mail', 
    586             ), 
    587         ); 
    588     } 
    589  
    590454} 
    591455 
Note: See TracChangeset for help on using the changeset viewer.