summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Utils/Mock/MockTitle.php
blob: 5762623795d4f7fd8c090aff06ac00cdd6a1f774 (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
<?php

namespace SMW\Tests\Utils\Mock;

/**
 *
 * @group SMW
 * @group SMWExtension
 *
 * @license GNU GPL v2+
 * @since 2.0
 *
 * @author mwjames
 */
class MockTitle extends \PHPUnit_Framework_TestCase {

	public static function buildMock( $text = __METHOD__ ) {

		$instance = new self();

		$contentModel = defined( 'CONTENT_MODEL_WIKITEXT' ) ? CONTENT_MODEL_WIKITEXT : null;

		$title = $instance->getMockBuilder( 'Title' )
			->disableOriginalConstructor()
			->getMock();

		$title->expects( $instance->any() )
			->method( 'getDBkey' )
			->will( $instance->returnValue( str_replace( ' ', '_', $text ) ) );

		$title->expects( $instance->any() )
			->method( 'getPrefixedDBkey' )
			->will( $instance->returnValue( str_replace( ' ', '_', $text ) ) );

		$title->expects( $instance->any() )
			->method( 'getContentModel' )
			->will( $instance->returnValue( $contentModel ) );

		return $title;
	}

	public static function buildMockForMainNamespace( $text = __METHOD__ ) {

		$instance = new self();

		$title = $instance->buildMock( $text );

		$title->expects( $instance->any() )
			->method( 'getNamespace' )
			->will( $instance->returnValue( NS_MAIN ) );

		$title->expects( $instance->any() )
			->method( 'getArticleID' )
			->will( $instance->returnValue( 9001 ) );

		$title->expects( $instance->any() )
			->method( 'isSpecialPage' )
			->will( $instance->returnValue( false ) );

		return $title;
	}

}