summaryrefslogtreecommitdiff
path: root/bin/reevotech/vendor/addwiki/mediawiki-datamodel/tests/TitleTest.php
blob: 2c4d73da6d1dade9b31b59afb2098ac00626073e (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
<?php

namespace Mediawiki\DataModel\Test;

use Mediawiki\DataModel\Title;

/**
 * @covers \Mediawiki\DataModel\Title
 * @author Addshore
 */
class TitleTest extends \PHPUnit_Framework_TestCase {

	/**
	 * @dataProvider provideValidConstruction
	 */
	public function testValidConstruction( $title, $ns ) {
		$titleObj = new Title( $title, $ns );
		$this->assertEquals( $title, $titleObj->getText() );
		$this->assertEquals( $title, $titleObj->getTitle() );
		$this->assertEquals( $ns, $titleObj->getNs() );
	}

	public function provideValidConstruction() {
		return array(
			array( 'fooo', 0 ),
			array( 'Foo:Bar', 15 ),
			array( 'FooBar:Bar', 9999 ),
		);
	}

	/**
	 * @dataProvider provideInvalidConstruction
	 */
	public function testInvalidConstruction( $title, $ns ) {
		$this->setExpectedException( 'InvalidArgumentException' );
		new Title( $title, $ns );
	}

	public function provideInvalidConstruction() {
		return array(
			array( array(), array() ),
			array( 'foo', array() ),
			array( array(), 1 ),
			array( null, 1 ),
			array( null, null ),
			array( 'foo', null ),
		);
	}

	public function testJsonRoundTrip() {
		$title = new Title( 'Foo', 19 );
		$json = $title->jsonSerialize();
		$this->assertEquals( $title, Title::jsonDeserialize( $json ) );
	}

}