Completed
Push — master ( 17dff3...f2d821 )
by mw
42:32 queued 07:38
created

ConceptDescriptionTest::testGetFingerprint()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SMW\Tests\Query\Language;
4
5
use SMW\DIWikiPage;
6
use SMW\Localizer;
7
use SMW\Query\Language\ConceptDescription;
8
use SMW\Query\Language\ThingDescription;
9
10
/**
11
 * @covers \SMW\Query\Language\ConceptDescription
12
 * @group semantic-mediawiki
13
 *
14
 * @license GNU GPL v2+
15
 * @since 2.1
16
 *
17
 * @author mwjames
18
 */
19
class ConceptDescriptionTest extends \PHPUnit_Framework_TestCase {
20
21
	public function testCanConstruct() {
22
23
		$concept = $this->getMockBuilder( '\SMW\DIWikiPage' )
24
			->disableOriginalConstructor()
25
			->getMock();
26
27
		$this->assertInstanceOf(
28
			'SMW\Query\Language\ConceptDescription',
29
			new ConceptDescription( $concept )
30
		);
31
32
		// Legacy
33
		$this->assertInstanceOf(
34
			'SMW\Query\Language\ConceptDescription',
35
			new \SMWConceptDescription( $concept )
36
		);
37
	}
38
39
	public function testCommonMethods() {
40
41
		$ns = Localizer::getInstance()->getNamespaceTextById( SMW_NS_CONCEPT );
42
43
		$concept = new DIWikiPage( 'Foo', SMW_NS_CONCEPT );
44
		$instance = new ConceptDescription( $concept );
45
46
		$this->assertEquals( $concept, $instance->getConcept() );
47
48
		$this->assertEquals( "[[{$ns}:Foo]]", $instance->getQueryString() );
49
		$this->assertEquals( " <q>[[{$ns}:Foo]]</q> ", $instance->getQueryString( true ) );
50
51
		$this->assertEquals( false, $instance->isSingleton() );
52
		$this->assertEquals( array(), $instance->getPrintRequests() );
53
54
		$this->assertEquals( 1, $instance->getSize() );
55
		$this->assertEquals( 0, $instance->getDepth() );
56
		$this->assertEquals( 4, $instance->getQueryFeatures() );
57
	}
58
59
	public function testGetFingerprint() {
60
61
		$instance = new ConceptDescription(
62
			new DIWikiPage( 'Foo', SMW_NS_CONCEPT )
63
		);
64
65
		$expected = $instance->getFingerprint();
66
67
		$instance = new ConceptDescription(
68
			new DIWikiPage( 'Bar', SMW_NS_CONCEPT )
69
		);
70
71
		$this->assertNotSame(
72
			$expected,
73
			$instance->getFingerprint()
74
		);
75
	}
76
77
	public function testPrune() {
78
79
		$instance = new ConceptDescription( new DIWikiPage( 'Foo', SMW_NS_CONCEPT ) );
80
81
		$maxsize  = 1;
82
		$maxDepth = 1;
83
		$log      = array();
84
85
		$this->assertEquals(
86
			$instance,
87
			$instance->prune( $maxsize, $maxDepth, $log )
88
		);
89
90
		$maxsize  = 0;
91
		$maxDepth = 1;
92
		$log      = array();
93
94
		$this->assertEquals(
95
			new ThingDescription(),
96
			$instance->prune( $maxsize, $maxDepth, $log )
97
		);
98
	}
99
100
}
101