Make WordPress Core

Changeset 41255


Ignore:
Timestamp:
08/15/2017 09:15:53 AM (7 years 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

Location:
trunk/tests/phpunit/tests
Files:
2 edited

Legend:

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

    r41171 r41255  
    11401140
    11411141    /**
     1142     * Ensure blog's admin email change notification emails do not contain encoded HTML entities
     1143     * @ticket 40015
     1144     */
     1145    function test_new_admin_email_notification_html_entities_decoded() {
     1146        reset_phpmailer_instance();
     1147
     1148        wp_set_current_user( self::$admin_id );
     1149
     1150        $existing_email = get_option( 'admin_email' );
     1151        $new_email = 'new-admin-email@test.dev';
     1152
     1153        // Give the site a name containing HTML entities
     1154        update_option( 'blogname', ''Test' blog's "name" has <html entities> &' );
     1155
     1156        update_option_new_admin_email( $existing_email, $new_email );
     1157
     1158        $mailer = tests_retrieve_phpmailer_instance();
     1159
     1160        $recipient = $mailer->get_recipient( 'to' );
     1161        $email = $mailer->get_sent();
     1162
     1163        // Assert reciepient is correct
     1164        $this->assertSame( $new_email, $recipient->address, 'Admin email change notification recipient not as expected' );
     1165
     1166        // Assert that HTML entites have been decode in body and subject
     1167        $this->assertContains( '\'Test\' blog\'s "name" has <html entities> &', $email->subject, 'Email subject does not contain the decoded HTML entities' );
     1168        $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' );
     1169    }
     1170
     1171    /**
     1172     * A confirmation email should not be sent if the new admin email:
     1173     * - Matches the existing admin email, or
     1174     * - is not a valid email
     1175     *
     1176     * @dataProvider data_user_admin_email_confirmation_emails
     1177     */
     1178    function test_new_admin_email_confirmation_not_sent_when_email_invalid( $email, $message ) {
     1179        reset_phpmailer_instance();
     1180
     1181        update_option_new_admin_email( get_option( 'admin_email' ), $email );
     1182
     1183        $mailer = tests_retrieve_phpmailer_instance();
     1184
     1185        $this->assertFalse( $mailer->get_sent(), $message );
     1186    }
     1187
     1188    /**
     1189     * Data provider for test_ms_new_admin_email_confirmation_not_sent_when_email_invalid().
     1190     *
     1191     * @return array {
     1192     *     @type array {
     1193     *         @type string $email   The new email for admin_email
     1194     *         @type string $message An error message to display if the test fails
     1195     *     }
     1196     * }
     1197     */
     1198    function data_user_admin_email_confirmation_emails() {
     1199        return array(
     1200            array(
     1201                get_option( 'admin_email' ),
     1202                'A confirmation email should not be sent if the current admin email matches the new email',
     1203            ),
     1204            array(
     1205                'not an email',
     1206                'A confirmation email should not be sent if it is not a valid email',
     1207            )
     1208        );
     1209    }
     1210
     1211    /**
     1212     * A confirmation email should not be sent if user's new email:
     1213     * - Matches their existing email, or
     1214     * - is not a valid email, or
     1215     * - Matches another user's email
     1216     *
     1217     * @dataProvider data_user_change_email_confirmation_emails
     1218     */
     1219    function test_profile_email_confirmation_not_sent_invalid_email( $email, $message ) {
     1220
     1221        $old_current = get_current_user_id();
     1222
     1223        $user_id = self::factory()->user->create( array(
     1224            'role'       => 'subscriber',
     1225            'user_email' => 'email@test.dev',
     1226        ) );
     1227        wp_set_current_user( $user_id );
     1228
     1229        self::factory()->user->create( array(
     1230            'role'       => 'subscriber',
     1231            'user_email' => 'another-user@test.dev',
     1232        ) );
     1233
     1234        reset_phpmailer_instance();
     1235
     1236        // Set $_POST['email'] with new email and $_POST['id'] with user's ID.
     1237        $_POST['user_id'] = $user_id;
     1238        $_POST['email'] = $email;
     1239        send_confirmation_on_profile_email();
     1240
     1241        $mailer = tests_retrieve_phpmailer_instance();
     1242
     1243        $this->assertFalse( $mailer->get_sent(), $message );
     1244
     1245        wp_set_current_user( $old_current );
     1246    }
     1247
     1248    /**
     1249     * Data provider for test_ms_profile_email_confirmation_not_sent_invalid_email().
     1250     *
     1251     * @return array {
     1252     *     @type array {
     1253     *         @type string $email   The user's new e-amil.
     1254     *         @type string $message An error message to display if the test fails
     1255     *     }
     1256     * }
     1257     */
     1258    function data_user_change_email_confirmation_emails() {
     1259        return array(
     1260            array(
     1261                'email@test.dev',
     1262                'Confirmation email should not be sent if it matches the user\'s existing email',
     1263            ),
     1264            array(
     1265                'not an email',
     1266                'Confirmation email should not be sent if it is not a valid email',
     1267            ),
     1268            array(
     1269                'another-user@test.dev',
     1270                'Confirmation email should not be sent if it matches another user\'s email',
     1271            ),
     1272        );
     1273    }
     1274
     1275    /**
    11421276     * Checks that calling edit_user() with no password returns an error when adding, and doesn't when updating.
    11431277     *
  • 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', '&#039;Test&#039; site&#039;s &quot;name&quot; has &lt;html entities&gt; &amp;' );
    467         update_option( 'blogname', '&#039;Test&#039; blog&#039;s &quot;name&quot; has &lt;html entities&gt; &amp;' );
    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.