Debian Codegraph @

tests/phpunit/includes/content/Transform/PreSaveTransformParamsValueTest.php

raw symbols SCIP
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 * @since 1.42
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 * @covers \MediaWiki\Content\Transform\PreSaveTransformParamsValue
34 * @group Database
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 * @dataProvider provideParserOptions
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 }