Completed
Pull Request — master (#14)
by Jeroen De
16:10
created

SubpageParentAnnotatorTest::testAddAnnotation()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 29
rs 8.8571
cc 1
eloc 20
nc 1
nop 0
1
<?php
2
3
namespace SBL\Tests;
4
5
use SBL\SubpageParentAnnotator;
6
use SMW\DIWikiPage;
7
use SMW\DIProperty;
8
use Title;
9
10
/**
11
 * @covers \SBL\SubpageParentAnnotator
12
 * @group semantic-breadcrumb-links
13
 *
14
 * @license GNU GPL v2+
15
 * @since 1.0
16
 *
17
 * @author mwjames
18
 */
19
class SubpageParentAnnotatorTest extends \PHPUnit_Framework_TestCase {
20
21
	private $parserData;
22
23
	protected function setUp() {
24
25
		$title = Title::newFromText( 'Foo/Bar' );
26
27
		$this->parserData = $this->getMockBuilder( '\SMW\ParserData' )
28
			->disableOriginalConstructor()
29
			->getMock();
30
31
		$this->parserData->expects( $this->any() )
32
			->method( 'getTitle' )
33
			->will( $this->returnValue( $title ) );
34
	}
35
36
	public function testCanConstruct() {
37
38
		$this->assertInstanceOf(
39
			'\SBL\SubpageParentAnnotator',
40
			new SubpageParentAnnotator( $this->parserData )
41
		);
42
	}
43
44
	public function testAddAnnotation() {
45
46
		$property = DIProperty::newFromUserLabel( SBL_PROP_PARENTPAGE );
47
		$subject = DIWikiPage::newFromText( 'Foo' );
48
49
		$semanticData = $this->getMockBuilder( '\SMW\SemanticData' )
50
			->disableOriginalConstructor()
51
			->getMock();
52
53
		$semanticData->expects( $this->once() )
54
			->method( 'getPropertyValues' )
55
			->will( $this->returnValue( array() ) );
56
57
		$semanticData->expects( $this->once() )
58
			->method( 'addPropertyObjectValue' )
59
			->with(
60
				$this->equalTo( $property ),
61
				$this->equalTo( $subject ) );
62
63
		$this->parserData->expects( $this->atLeastOnce() )
64
			->method( 'getSemanticData' )
65
			->will( $this->returnValue( $semanticData ) );
66
67
		$instance = new SubpageParentAnnotator(
68
			$this->parserData
69
		);
70
71
		$instance->addAnnotation();
72
	}
73
74
	public function testDisabledAnnotationFunctionality() {
75
76
		$this->parserData->expects( $this->never() )
77
			->method( 'getSemanticData' );
78
79
		$instance = new SubpageParentAnnotator(
80
			$this->parserData
81
		);
82
83
		$instance->setSubpageParentAnnotationState( false );
84
		$instance->addAnnotation();
85
	}
86
87
	public function testDisabledAnnotationFunctionalityDueToPreexisingValues() {
88
89
		$semanticData = $this->getMockBuilder( '\SMW\SemanticData' )
90
			->disableOriginalConstructor()
91
			->getMock();
92
93
		$semanticData->expects( $this->once() )
94
			->method( 'getPropertyValues' )
95
			->will( $this->returnValue( array( 'Foo' ) ) );
96
97
		$semanticData->expects( $this->never() )
98
			->method( 'addPropertyObjectValue' );
99
100
		$this->parserData->expects( $this->atLeastOnce() )
101
			->method( 'getSemanticData' )
102
			->will( $this->returnValue( $semanticData ) );
103
104
		$instance = new SubpageParentAnnotator(
105
			$this->parserData
106
		);
107
108
		$instance->setSubpageParentAnnotationState( true );
109
		$instance->addAnnotation();
110
	}
111
112
}
113