Debian Codegraph @

tests/phpunit/unit/includes/Message/UserGroupMembershipParamTest.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\Message;
23
24 use MediaWiki\Message\UserGroupMembershipParam;
25 use MediaWiki\User\UserIdentity;
26 use MediaWiki\User\UserIdentityValue;
27 use MediaWikiUnitTestCase;
28
29 /**
30 * @covers \MediaWiki\Message\UserGroupMembershipParam
31 */
32 class UserGroupMembershipParamTest extends MediaWikiUnitTestCase {
33
34 protected string $group;
35 protected UserIdentity $member;
36
37 protected function setUp(): void {
38 parent::setUp();
39 $this->group = 'users';
40 $this->member = new UserIdentityValue( 1, 'MockUser' );
41 }
42
43 public function testConstruct() {
44 $param = @new UserGroupMembershipParam( $this->group, $this->member );
45 $this->assertSame( $this->group, $param->getGroup() );
46 $this->assertSame( $this->member, $param->getMember() );
47 }
48
49 public function testGetGroup() {
50 $groupMock = 'users';
51 $userNameMock = 'MockUser';
52 $userIdentityMock = new UserIdentityValue( 1, $userNameMock );
53 $param = @new UserGroupMembershipParam( $groupMock, $userIdentityMock );
54 $this->assertSame( $groupMock, $param->getGroup(),
55 'Group name should match the constructor argument.' );
56 }
57
58 public function testGetMember() {
59 $groupMock = 'users';
60 $userNameMock = 'MockUser';
61 $userIdentityMock = new UserIdentityValue( 1, $userNameMock );
62 $param = @new UserGroupMembershipParam( $groupMock, $userIdentityMock );
63 $this->assertSame( $userIdentityMock, $param->getMember(),
64 'User identity object should match the constructor argument.' );
65 }
66
67 public function testToString() {
68 // More mock parameters aimed at a different group and user.
69 $groupMock = 'sysop';
70 $userIdentityMock = new UserIdentityValue( 2, 'MockAdminUser' );
71
72 // Create the UserGroupMembershipParam instance with mocks.
73 $param = @new UserGroupMembershipParam( $groupMock, $userIdentityMock );
74 $expectedString = 'sysop:MockAdminUser';
75 // Asserting if the string representation is as expected.
76 $this->assertSame( $expectedString, (string)$param,
77 'String representation should combine group and user name.' );
78 }
79 }