| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
namespace MediaWiki\Tests\Content\Transform; |
| 23 |
|
| 24 |
use MediaWiki\Content\Transform\PreSaveTransformParamsValue; |
| 25 |
use MediaWiki\Page\PageReference; |
| 26 |
use MediaWiki\Parser\ParserOptions; |
| 27 |
use MediaWiki\Title\Title; |
| 28 |
use MediaWiki\User\User; |
| 29 |
use MediaWiki\User\UserIdentity; |
| 30 |
use MediaWikiIntegrationTestCase; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
class PreSaveTransformParamsValueTest extends MediaWikiIntegrationTestCase { |
| 37 |
|
| 38 |
protected PageReference $page; |
| 39 |
protected UserIdentity $user; |
| 40 |
protected ParserOptions $parserOptions; |
| 41 |
|
| 42 |
protected function setUp(): void { |
| 43 |
parent::setUp(); |
| 44 |
$this->page = $this->createMock( PageReference::class ); |
| 45 |
$this->user = $this->createMock( UserIdentity::class ); |
| 46 |
$this->parserOptions = $this->createMock( ParserOptions::class ); |
| 47 |
} |
| 48 |
|
| 49 |
public function testConstruct() { |
| 50 |
$params = new PreSaveTransformParamsValue( $this->page, $this->user, $this->parserOptions ); |
| 51 |
$this->assertSame( $this->page, $params->getPage() ); |
| 52 |
$this->assertSame( $this->user, $params->getUser() ); |
| 53 |
$this->assertSame( $this->parserOptions, $params->getParserOptions() ); |
| 54 |
} |
| 55 |
|
| 56 |
public function testGetPage() { |
| 57 |
$title = Title::newFromText( 'TestPage' ); |
| 58 |
$page = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $title ); |
| 59 |
$params = new PreSaveTransformParamsValue( $page, $this->user, $this->parserOptions ); |
| 60 |
$this->assertSame( $page, $params->getPage() ); |
| 61 |
} |
| 62 |
|
| 63 |
public function testGetUser() { |
| 64 |
$user = $this->getTestUser(); |
| 65 |
$params = new PreSaveTransformParamsValue( $this->page, $user->getUserIdentity(), $this->parserOptions ); |
| 66 |
$expectedUser = $user->getUserIdentity(); |
| 67 |
$actualUser = $params->getUser(); |
| 68 |
$this->assertEquals( $expectedUser->getId(), $actualUser->getId(), 'User IDs do not match' ); |
| 69 |
$this->assertEquals( $expectedUser->getName(), $actualUser->getName(), 'User names do not match' ); |
| 70 |
$this->assertEquals( $expectedUser->getWikiId(), $actualUser->getWikiId(), 'Wiki IDs do not match' ); |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
public function testGetParserOptions( $options ) { |
| 77 |
$title = Title::newFromText( 'TestPage' ); |
| 78 |
$page = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $title ); |
| 79 |
$params = new PreSaveTransformParamsValue( $page, $this->user, $options ); |
| 80 |
$this->assertSame( $options, $params->getParserOptions() ); |
| 81 |
} |
| 82 |
|
| 83 |
public function provideParserOptions(): array { |
| 84 |
$user = new User(); |
| 85 |
$options = ParserOptions::newFromUser( $user ); |
| 86 |
return [ |
| 87 |
[ $options ], |
| 88 |
[ ParserOptions::newFromUser( $user ) ], |
| 89 |
]; |
| 90 |
} |
| 91 |
} |