CSP: In tests, use setMwGlobals() instead of manual set+undo
authorTimo Tijhof <krinklemail@gmail.com>
Sun, 19 Aug 2018 00:42:58 +0000 (01:42 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Sun, 19 Aug 2018 00:43:52 +0000 (01:43 +0100)
This is the idiom as used in other PHPUnit tests for MediaWiki.

Change-Id: I285e5abe57bad8b9a8a3b35d81bb3a9f5f3dbe85

tests/phpunit/includes/ContentSecurityPolicyTest.php

index 250d49d..5f0200d 100644 (file)
@@ -273,13 +273,9 @@ class ContentSecurityPolicyTest extends MediaWikiTestCase {
         * @covers ContentSecurityPolicy::isNonceRequired
         */
        public function testCSPIsEnabled( $main, $reportOnly, $expected ) {
-               global $wgCSPReportOnlyHeader, $wgCSPHeader;
-               global $wgCSPHeader;
-               $oldReport = wfSetVar( $wgCSPReportOnlyHeader, $reportOnly );
-               $oldMain = wfSetVar( $wgCSPHeader, $main );
+               $this->setMwGlobals( 'wgCSPReportOnlyHeader', $reportOnly );
+               $this->setMwGlobals( 'wgCSPHeader', $main );
                $res = ContentSecurityPolicy::isNonceRequired( RequestContext::getMain()->getConfig() );
-               wfSetVar( $wgCSPReportOnlyHeader, $oldReport );
-               wfSetVar( $wgCSPHeader, $oldMain );
                $this->assertEquals( $res, $expected );
        }