Completed
Push — master ( dd8aad...6526e1 )
by mw
04:06
created

DataValueDeserializerTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 0
cbo 4
dl 0
loc 52
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testCanConstruct() 0 7 1
A testNewDiWikiPage() 0 14 1
A testNewTimeValueForOutOfRangeTimestamp() 0 12 1
A testNewTimeValueForRawTimeFromat() 0 12 1
1
<?php
2
3
namespace SEQL\Tests;
4
5
use SEQL\DataValueDeserializer;
6
use SMW\DIWikiPage;
7
use SMW\DIProperty;
8
use SMWDITime as DITime;
9
10
/**
11
 * @covers \SEQL\DataValueDeserializer
12
 * @group semantic-external-query-lookup
13
 *
14
 * @license GNU GPL v2+
15
 * @since 1.0
16
 *
17
 * @author mwjames
18
 */
19
class DataValueDeserializerTest extends \PHPUnit_Framework_TestCase {
20
21
	public function testCanConstruct() {
22
23
		$this->assertInstanceOf(
24
			'\SEQL\DataValueDeserializer',
25
			new DataValueDeserializer( 'foo' )
26
		);
27
	}
28
29
	public function testNewDiWikiPage() {
30
31
		$instance = new DataValueDeserializer( 'foo' );
32
33
		$value = array(
34
			'namespace' => NS_MAIN,
35
			'fulltext'  => 'abc def'
36
		);
37
38
		$this->assertEquals(
39
			new DIWikiPage( 'Foo:abc_def', NS_MAIN ),
40
			$instance->newDiWikiPage( $value )
41
		);
42
	}
43
44
	public function testNewTimeValueForOutOfRangeTimestamp() {
45
46
		$instance = new DataValueDeserializer( 'foo' );
47
48
		$property = new DIProperty( 'Bar' );
49
		$property->setPropertyTypeId( '_dat' );
50
51
		$this->assertNotEquals(
52
			DITime::doUnserialize( '2/-200' ),
53
			$instance->newDataValueFrom( $property, '-2000101000000' )
54
		);
55
	}
56
57
	public function testNewTimeValueForRawTimeFromat() {
58
59
		$instance = new DataValueDeserializer( 'foo' );
60
61
		$property = new DIProperty( 'Bar' );
62
		$property->setPropertyTypeId( '_dat' );
63
64
		$this->assertEquals(
65
			DITime::doUnserialize( '2/-200' ),
66
			$instance->newDataValueFrom( $property, array( 'raw' => '2/-200' ) )->getDataItem()
67
		);
68
	}
69
70
}
71