Completed
Push — master ( f2f6e8...470987 )
by mw
33:59
created

SubSemanticDataTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SMW\Tests\DataModel;
4
5
use SMW\DataModel\SubSemanticData;
6
use SMW\DataModel\ContainerSemanticData;
7
use SMW\DataItemFactory;
8
use SMW\SemanticData;
9
10
/**
11
 * @covers \SMW\DataModel\SubSemanticData
12
 * @group semantic-mediawiki
13
 *
14
 * @license GNU GPL v2+
15
 * @since 2.5
16
 *
17
 * @author mwjames
18
 */
19
class SubSemanticDataTest extends \PHPUnit_Framework_TestCase {
20
21
	private $dataItemFactory;
22
23
	protected function setUp() {
24
		parent::setUp();
25
26
		$this->dataItemFactory = new DataItemFactory();
27
	}
28
29
	public function testCanConstruct() {
30
31
		$this->assertInstanceOf(
32
			SubSemanticData::class,
33
			new SubSemanticData( $this->dataItemFactory->newDIWikiPage( __METHOD__, NS_MAIN ) )
34
		);
35
	}
36
37
	public function testAddSubSemanticData() {
38
39
		$instance = new SubSemanticData(
40
			$this->dataItemFactory->newDIWikiPage( __METHOD__, NS_MAIN )
41
		);
42
43
		$this->assertEmpty(
44
			$instance->getSubSemanticData()
45
		);
46
47
		$containerSemanticData = new ContainerSemanticData(
48
			$this->dataItemFactory->newDIWikiPage( __METHOD__, NS_MAIN, '', 'Foo' )
49
		);
50
51
		$instance->addSubSemanticData(
52
			$containerSemanticData
53
		);
54
55
		$this->assertNotEmpty(
56
			$instance->getSubSemanticData()
57
		);
58
	}
59
60
	public function testAddSubSemanticDataWithMismatchedSubjectThrowsException() {
61
62
		$instance = new SubSemanticData(
63
			$this->dataItemFactory->newDIWikiPage( __METHOD__, NS_MAIN )
64
		);
65
66
		$this->setExpectedException( '\SMW\Exception\SubSemanticDataException');
67
68
		$instance->addSubSemanticData(
69
			ContainerSemanticData::makeAnonymousContainer( true, true )
70
		);
71
	}
72
73
	public function testRemoveSubSemanticData() {
74
75
		$instance = new SubSemanticData(
76
			$this->dataItemFactory->newDIWikiPage( __METHOD__, NS_MAIN )
77
		);
78
79
		$containerSemanticData = new ContainerSemanticData(
80
			$this->dataItemFactory->newDIWikiPage( __METHOD__, NS_MAIN, '', 'Foo' )
81
		);
82
83
		$instance->addSubSemanticData(
84
			$containerSemanticData
85
		);
86
87
		$this->assertTrue(
88
			$instance->hasSubSemanticData( 'Foo' )
89
		);
90
91
		$instance->removeSubSemanticData(
92
			$containerSemanticData
93
		);
94
95
		$this->assertFalse(
96
			$instance->hasSubSemanticData( 'Foo' )
97
		);
98
	}
99
100
}
101