Completed
Push — master ( d581f7...34ba15 )
by mw
02:38
created

testTryToRedeclareTypeOfPredefinedPropertyThrowsException()   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
c 1
b 0
f 1
dl 0
loc 11
rs 9.4286
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace SEQL\ByHttpRequest\Tests;
4
5
use SEQL\ByHttpRequest\ResponsePropertyList;
6
use SMW\DIProperty;
7
8
/**
9
 * @covers \SEQL\ByHttpRequest\ResponsePropertyList
10
 * @group semantic-external-query-lookup
11
 *
12
 * @license GNU GPL v2+
13
 * @since 1.0
14
 *
15
 * @author mwjames
16
 */
17
class ResponsePropertyListTest extends \PHPUnit_Framework_TestCase {
18
19
	public function testCanConstruct() {
20
21
		$this->assertInstanceOf(
22
			'\SEQL\ByHttpRequest\ResponsePropertyList',
23
			new ResponsePropertyList( 'abc' )
24
		);
25
	}
26
27
	public function testGetPropertyForCategory() {
28
29
		$value = array(
30
			'label' => 'Category', 'mode' => 0
31
		);
32
33
		$property = new DIProperty( '_INST' );
34
		$property->setInterwiki( 'abc' );
35
36
		$instance = new ResponsePropertyList( 'abc' );
37
		$instance->addToPropertyList( $value );
38
39
		$this->assertEquals(
40
			$property,
41
			$instance->getProperty( 'Category' )
42
		);
43
44
		$this->assertEquals(
45
			$property,
46
			$instance->getProperty( '_INST' )
47
		);
48
	}
49
50
	public function testGetPropertyForRedirectedProperty() {
51
52
		$value = array(
53
			'label' => 'Foo', 'mode' => 2, 'redi' => 'was redirect from Bar' , 'typeid' => '_wpg'
54
		);
55
56
		$property = new DIProperty( 'Foo' );
57
		$property->setInterwiki( 'abc' );
58
		$property->setPropertyTypeId( '_wpg' );
59
60
		$instance = new ResponsePropertyList( 'abc' );
61
		$instance->addToPropertyList( $value );
62
63
		$this->assertEquals(
64
			$property,
65
			$instance->getProperty( 'Foo' )
66
		);
67
68
		$this->assertEquals(
69
			$property,
70
			$instance->getProperty( 'was redirect from Bar' )
71
		);
72
73
		$this->assertEquals(
74
			array( 'Foo' => $property ),
75
			$instance->getPropertyList()
76
		);
77
	}
78
79
	public function testTryToRedeclareTypeOfPredefinedPropertyThrowsException() {
80
81
		$value = array(
82
			'label' => 'Modification date', 'mode' => 2, 'typeid' => '_wpg'
83
		);
84
85
		$instance = new ResponsePropertyList( 'abc' );
86
87
		$this->setExpectedException( 'RuntimeException' );
88
		$instance->addToPropertyList( $value );
89
	}
90
91
}
92