WordPress.org

Make WordPress Core


Ignore:
Timestamp:
07/19/2021 02:00:11 PM (6 months ago)
Author:
SergeyBiryukov
Message:

Tests: Replace assertContains() with assertStringContainsString() when used with strings.

Using the assertContains() and assertNotContains() methods with string haystacks was deprecated in PHPUnit 8 and removed in PHPUnit 9.

While WordPress test suite currently only supports PHPUnit up to 7.5.x, this allows us to switch to newer assertions ahead of adding full support for PHPUnit 8+.

These methods introduced in PHPUnit 7.5 should be used as an alternative:

  • assertStringContainsString()
  • assertStringContainsStringIgnoringCase
  • assertStringNotContainsString()
  • assertStringNotContainsStringIgnoringCase

As WordPress currently uses PHPUnit 5.7.x to run tests on PHP 5.6, polyfills for these methods were added to the WP_UnitTestCase class for PHPUnit < 7.5.

Follow-up to [51331], [51451], [51461].

Props jrf, dd32, SergeyBiryukov.
See #53363, #46149.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/privacy/wpPrivacySendErasureFulfillmentNotification.php

    r51129 r51462  
    115115
    116116        $mailer = tests_retrieve_phpmailer_instance();
    117         $this->assertContains( self::$requester_email, $mailer->get_recipient( 'to' )->address );
    118         $this->assertContains( 'Erasure Request Fulfilled', $mailer->get_sent()->subject );
    119         $this->assertContains( 'Your request to erase your personal data', $mailer->get_sent()->body );
    120         $this->assertContains( 'has been completed.', $mailer->get_sent()->body );
    121         $this->assertContains( wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ), $mailer->get_sent()->body );
    122         $this->assertContains( home_url(), $mailer->get_sent()->body );
    123 
    124         $this->assertNotContains( 'you can also read our privacy policy', $mailer->get_sent()->body );
     117        $this->assertStringContainsString( self::$requester_email, $mailer->get_recipient( 'to' )->address );
     118        $this->assertStringContainsString( 'Erasure Request Fulfilled', $mailer->get_sent()->subject );
     119        $this->assertStringContainsString( 'Your request to erase your personal data', $mailer->get_sent()->body );
     120        $this->assertStringContainsString( 'has been completed.', $mailer->get_sent()->body );
     121        $this->assertStringContainsString( wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ), $mailer->get_sent()->body );
     122        $this->assertStringContainsString( home_url(), $mailer->get_sent()->body );
     123
     124        $this->assertStringNotContainsString( 'you can also read our privacy policy', $mailer->get_sent()->body );
    125125        $this->assertTrue( (bool) get_post_meta( self::$request_id, '_wp_user_notified', true ) );
    126126    }
     
    145145        $mailer = tests_retrieve_phpmailer_instance();
    146146
    147         $this->assertContains( self::$requester_email, $mailer->get_recipient( 'to' )->address );
    148         $this->assertContains( 'you can also read our privacy policy', $mailer->get_sent()->body );
    149         $this->assertContains( get_privacy_policy_url(), $mailer->get_sent()->body );
     147        $this->assertStringContainsString( self::$requester_email, $mailer->get_recipient( 'to' )->address );
     148        $this->assertStringContainsString( 'you can also read our privacy policy', $mailer->get_sent()->body );
     149        $this->assertStringContainsString( get_privacy_policy_url(), $mailer->get_sent()->body );
    150150        $this->assertTrue( (bool) get_post_meta( self::$request_id, '_wp_user_notified', true ) );
    151151    }
     
    163163
    164164        // Should send an email.
    165         $this->assertContains( self::$requester_email, $mailer->get_recipient( 'to' )->address );
    166         $this->assertContains( 'Erasure Request Fulfilled', $mailer->get_sent()->subject );
     165        $this->assertStringContainsString( self::$requester_email, $mailer->get_recipient( 'to' )->address );
     166        $this->assertStringContainsString( 'Erasure Request Fulfilled', $mailer->get_sent()->subject );
    167167        $this->assertTrue( (bool) get_post_meta( self::$request_id, '_wp_user_notified', true ) );
    168168
     
    270270        $mailer = tests_retrieve_phpmailer_instance();
    271271
    272         $this->assertContains( 'From: Tester <tester@example.com>', $mailer->get_sent()->header );
     272        $this->assertStringContainsString( 'From: Tester <tester@example.com>', $mailer->get_sent()->header );
    273273    }
    274274
     
    354354        $mailer = tests_retrieve_phpmailer_instance();
    355355
    356         $this->assertContains( 'Solicitud de borrado completada', $mailer->get_sent()->subject );
     356        $this->assertStringContainsString( 'Solicitud de borrado completada', $mailer->get_sent()->subject );
    357357    }
    358358
     
    375375        $mailer = tests_retrieve_phpmailer_instance();
    376376
    377         $this->assertContains( 'Löschauftrag ausgeführt', $mailer->get_sent()->subject );
     377        $this->assertStringContainsString( 'Löschauftrag ausgeführt', $mailer->get_sent()->subject );
    378378    }
    379379
     
    396396        $mailer = tests_retrieve_phpmailer_instance();
    397397
    398         $this->assertContains( 'Solicitud de borrado completada', $mailer->get_sent()->subject );
     398        $this->assertStringContainsString( 'Solicitud de borrado completada', $mailer->get_sent()->subject );
    399399    }
    400400
     
    419419        $mailer = tests_retrieve_phpmailer_instance();
    420420
    421         $this->assertContains( 'Löschauftrag ausgeführt', $mailer->get_sent()->subject );
     421        $this->assertStringContainsString( 'Löschauftrag ausgeführt', $mailer->get_sent()->subject );
    422422    }
    423423
     
    445445        $mailer = tests_retrieve_phpmailer_instance();
    446446
    447         $this->assertContains( 'Erasure Request Fulfilled', $mailer->get_sent()->subject );
     447        $this->assertStringContainsString( 'Erasure Request Fulfilled', $mailer->get_sent()->subject );
    448448    }
    449449
     
    474474        $mailer = tests_retrieve_phpmailer_instance();
    475475
    476         $this->assertContains( 'Solicitud de borrado completada', $mailer->get_sent()->subject );
     476        $this->assertStringContainsString( 'Solicitud de borrado completada', $mailer->get_sent()->subject );
    477477    }
    478478}
Note: See TracChangeset for help on using the changeset viewer.