Passed
Pull Request — master (#21)
by GIT
08:43 queued 44s
created

ApprovedByPropertyAnnotatorTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 60
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SMW\ApprovedRevs\Tests\PropertyAnnotators;
4
5
use SMW\ApprovedRevs\PropertyAnnotators\ApprovedByPropertyAnnotator;
6
use SMW\DIProperty;
7
use SMW\DIWikiPage;
8
use User;
9
10
/**
11
 * @covers \SMW\ApprovedRevs\PropertyAnnotators\ApprovedByPropertyAnnotator
12
 * @group semantic-approved-revs
13
 *
14
 * @license GNU GPL v2+
15
 * @since 1.0
16
 */
17
class ApprovedByPropertyAnnotatorTest extends \PHPUnit_Framework_TestCase {
18
19
	private $databaseLogReader;
20
21
	protected function setUp(): void {
22
		parent::setUp();
23
24
		$this->databaseLogReader = $this->getMockBuilder( '\SMW\ApprovedRevs\DatabaseLogReader' )
25
			->disableOriginalConstructor()
26
			->getMock();
27
	}
28
29
	public function testCanConstruct() {
30
31
		$this->assertInstanceOf(
32
			ApprovedByPropertyAnnotator::class,
33
			new ApprovedByPropertyAnnotator( $this->databaseLogReader )
34
		);
35
	}
36
37
	public function testAddAnnotation() {
38
39
		$user = User::newFromName( "UnitTest" );
40
41
		$semanticData = $this->getMockBuilder( '\SMW\SemanticData' )
42
			->disableOriginalConstructor()
43
			->getMock();
44
45
		$semanticData->expects( $this->once() )
46
			->method( 'addPropertyObjectValue' )
47
			->with(
48
				$this->anyThing(),
49
				$this->equalTo( DIWikiPage::newFromTitle( $user->getUserPage() ) ) );
50
51
		$annotator = new ApprovedByPropertyAnnotator(
52
			$this->databaseLogReader
53
		);
54
55
		$annotator->setApprovedBy( $user );
56
		$annotator->addAnnotation( $semanticData );
57
	}
58
59
	public function testRemoval() {
60
61
		$semanticData = $this->getMockBuilder( '\SMW\SemanticData' )
62
			->disableOriginalConstructor()
63
			->getMock();
64
65
		$semanticData->expects( $this->once() )
66
			->method( 'removeProperty' );
67
68
		$annotator = new ApprovedByPropertyAnnotator(
69
			$this->databaseLogReader
70
		);
71
72
		$annotator->setApprovedBy( false );
73
		$annotator->addAnnotation( $semanticData );
74
	}
75
76
}
77