Allow MediaWikiTestCase::insertPage to use given User
authorMusikAnimal <musikanimal@gmail.com>
Fri, 29 Jun 2018 19:56:22 +0000 (15:56 -0400)
committerMusikAnimal <musikanimal@gmail.com>
Fri, 29 Jun 2018 21:04:33 +0000 (17:04 -0400)
Sometimes you need to create pages with a non-sysop.
Example: I31aedcb9af7584fa5504916c67ca10f205ec9910

Change-Id: I9e48f7c00efbce8c2de3f5db3a74462d47ae8f64

tests/phpunit/MediaWikiTestCase.php

index 4140c23..f363d83 100644 (file)
@@ -1075,12 +1075,14 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase {
         * @param string|Title $pageName Page name or title
         * @param string $text Page's content
         * @param int $namespace Namespace id (name cannot already contain namespace)
+        * @param User $user If null, static::getTestSysop()->getUser() is used.
         * @return array Title object and page id
         */
        protected function insertPage(
                $pageName,
                $text = 'Sample page for unit test.',
-               $namespace = null
+               $namespace = null,
+               User $user = null
        ) {
                if ( is_string( $pageName ) ) {
                        $title = Title::newFromText( $pageName, $namespace );
@@ -1088,7 +1090,9 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase {
                        $title = $pageName;
                }
 
-               $user = static::getTestSysop()->getUser();
+               if ( !$user ) {
+                       $user = static::getTestSysop()->getUser();
+               }
                $comment = __METHOD__ . ': Sample page for unit test.';
 
                $page = WikiPage::factory( $title );