summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/Translate/tests/phpunit/WikiPageMessageGroupSerializationTest.php
blob: 7012c643679664486067841adf1ee523ba3a0e86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
/**
 * @author Abijeet Patro
 * @license GPL-2.0-or-later
 * @file
 */

 /**
  * @group medium
  */
class WikiPageMessageGroupSerializationTest extends MediaWikiTestCase {
	protected function setUp() {
		parent::setUp();

		$this->setTemporaryHook(
			'TranslatePostInitGroups',
			function ( &$list ) {
				$pageMessageGroup = new WikiPageMessageGroup( 'pageid', 'mypage' );
				$pageMessageGroup->setLabel( 'thelabel' ); // Example
				$pageMessageGroup->setNamespace( 5 ); // Example
				$list['pageid'] = $pageMessageGroup;
				$pageMessageGroup->setIgnored( [ 'hello', 'world' ] );

				$anotherPageMessageGroup = new WikiPageMessageGroup( 'anotherpageid', 'mypage' );
				$anotherPageMessageGroup->setLabel( 'thelabel' ); // Example
				$anotherPageMessageGroup->setNamespace( 5 ); // Example

				$list['anotherpageid'] = $anotherPageMessageGroup;

				return false;
			}
		);

		$mg = MessageGroups::singleton();
		$mg->setCache( new WANObjectCache( [ 'cache' => wfGetCache( 'hash' ) ] ) );
		$mg->recache();
	}

	public function testDataSerialization() {
		$groups = MessageGroups::getAllGroups();

		$serialized = serialize( $groups );
		$unserializedGroups = unserialize( $serialized );

		$this->assertCount( 2, $unserializedGroups,
			'after serialization there are 2 groups.' );

		$pageMessageGroup = $unserializedGroups['pageid'];
		$this->assertEquals( $pageMessageGroup->getId(), 'pageid',
			'after serialization id is set' );
		$this->assertInstanceOf( Title::class, $pageMessageGroup->getTitle(),
			'after serialization title property is an instance of the Title class.' );
		$this->assertEquals( 5, $pageMessageGroup->getNamespace(),
			'after serialization namespace is not empty' );
		$this->assertEquals( $pageMessageGroup->getTitle()->getPrefixedText(),
			$pageMessageGroup->getLabel(), 'after serialization label is not empty' );
		$this->assertCount( 2, $pageMessageGroup->getIgnored(),
			'after serialization ignored has 2 values.' );
	}

}