summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/includes/dataitems/DIWikiPageTest.php
blob: fa5fc02602038d2e71575799cac2b7ac71d41e55 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php

namespace SMW\Tests;

use SMW\DIWikiPage;

/**
 * @covers \SMW\DIWikiPage
 * @covers SMWDataItem
 *
 * @group SMW
 * @group SMWExtension
 * @group SMWDataItems
 *
 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 */
class DIWikiPageTest extends DataItemTest {

	/**
	 * @see DataItemTest::getClass
	 *
	 * @since 1.9
	 *
	 * @return string
	 */
	public function getClass() {
		return 'SMW\DIWikiPage';
	}

	/**
	 * @see DataItemTest::constructorProvider
	 *
	 * @since 1.9
	 *
	 * @return array
	 */
	public function constructorProvider() {
		return [
			[ 'Foo', NS_MAIN, '' ],
			[ 'Foo_Bar', NS_MAIN, '' ],
			[ 'Foo_Bar_Baz', NS_MAIN, '', 'spam' ],
		];
	}

	/**
	 * @dataProvider instanceProvider
	 */
	public function testGetTitleAndNewFromTitleRoundrtip( DIWikiPage $di ) {
		$newDi = DIWikiPage::newFromTitle( $di->getTitle() );
		$this->assertTrue( $newDi->equals( $di ) );
	}

	/**
	 * @dataProvider sortKeyProvider
	 */
	public function testSortKeyRoundtrip( $title, $sortkey, $expected ) {

		$instance = new DIWikiPage( $title, NS_MAIN );

		$instance->setSortKey( $sortkey );

		$this->assertEquals(
			$expected,
			$instance->getSortKey()
		);
	}

	public function testDoUnserialize() {

		$expected = new DIWikiPage( 'Foo', 0 , '', '' );

		$this->assertEquals(
			$expected,
			DIWikiPage::doUnserialize( 'Foo#0##' )
		);

		$this->assertEquals(
			$expected,
			DIWikiPage::doUnserialize( 'Foo#0##' )
		);
	}

	public function sortKeyProvider() {

		$provider[] = [
			'Some_title',
			null,
			'Some title'
		];

		$provider[] = [
			'Some_title',
			'',
			'Some title'
		];

		$provider[] = [
			'Some_title',
			'abc',
			'abc'
		];

		$provider[] = [
			'Some_title',
			'abc_def',
			'abc def'
		];

		return $provider;
	}

}