Completed
Push — master ( 274d0e...9fc64f )
by mw
34:08
created

testGetPropertyDescriptionForPredefinedProperty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 11
rs 9.4285
c 1
b 0
f 1
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace SMW\Tests;
4
5
use SMW\PropertySpecificationLookup;
6
use SMW\DIProperty;
7
use SMWDIContainer as DIContainer;
8
use SMWContainerSemanticData as ContainerSemanticData;
9
10
/**
11
 * @covers \SMW\PropertySpecificationLookup
12
 * @group semantic-mediawiki
13
 *
14
 * @license GNU GPL v2+
15
 * @since 2.4
16
 *
17
 * @author mwjames
18
 */
19
class PropertySpecificationLookupTest extends \PHPUnit_Framework_TestCase {
20
21
	private $store;
22
23
	protected function setUp() {
24
		parent::setUp();
25
26
		$this->store = $this->getMockBuilder( '\SMW\Store' )
27
			->disableOriginalConstructor()
28
			->getMockForAbstractClass();
29
	}
30
31
	public function testCanConstruct() {
32
33
		$this->assertInstanceOf(
34
			'\SMW\PropertySpecificationLookup',
35
			new PropertySpecificationLookup( $this->store )
36
		);
37
	}
38
39
	public function testGetPropertyDescriptionForPredefinedProperty() {
40
41
		$instance = new PropertySpecificationLookup(
42
			$this->store
43
		);
44
45
		$this->assertInternalType(
46
			'string',
47
			$instance->getPropertyDescriptionFor( new DIProperty( '_PDESC' ) )
48
		);
49
	}
50
51
	public function testGetPropertyDescriptionForPredefinedPropertyViaCacheForLanguageCode() {
52
53
		$cache = $this->getMockBuilder( '\Onoi\Cache\Cache' )
54
			->disableOriginalConstructor()
55
			->getMockForAbstractClass();
56
57
		$cache->expects( $this->once() )
58
			->method( 'contains' )
59
			->will( $this->returnValue( true ) );
60
61
		$cache->expects( $this->once() )
62
			->method( 'fetch' )
63
			->with( $this->stringContains( 'foo:smw:pspec:' ) )
64
			->will( $this->returnValue( array( 'en:-' => 1001 ) ) );
65
66
		$instance = new PropertySpecificationLookup(
67
			$this->store,
68
			$cache
69
		);
70
71
		$instance->setCachePrefix( 'foo' );
72
		$instance->setLanguageCode( 'en' );
73
74
		$this->assertEquals(
75
			1001,
76
			$instance->getPropertyDescriptionFor( new DIProperty( '_PDESC' ) )
77
		);
78
	}
79
80
	public function testTryToGetLocalPropertyDescriptionForUserdefinedProperty() {
81
82
		$property = new DIProperty( 'SomeProperty' );
83
84
		$this->store->expects( $this->once() )
85
			->method( 'getPropertyValues' )
86
			->with(
87
				$this->equalTo( $property->getDiWikiPage() ),
88
				$this->equalTo( new DIProperty( '_PDESC' ) ),
89
				$this->anything() )
90
			->will( $this->returnValue( array(
91
				new DIContainer( ContainerSemanticData::makeAnonymousContainer() ) ) ) );
92
93
		$instance = new PropertySpecificationLookup(
94
			$this->store
95
		);
96
97
		$this->assertInternalType(
98
			'string',
99
			$instance->getPropertyDescriptionFor( $property )
100
		);
101
	}
102
103
}
104