Completed
Push — master ( e1b3cc...52b7dd )
by Enrico
03:03
created

DummyModel::asTurtle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
class DummyModel extends BOTK\Model\AbstractModel
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
	public function asTurtle() { return '<urn:a:b> owl:sameAs <urn:a:b> .';}
6
}
7
8
class AbstractModelTest extends PHPUnit_Framework_TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
9
{
10
	protected $vocabulary =  array(
11
		'rdf'		=> 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
12
		'rdfs'		=> 'http://www.w3.org/2000/01/rdf-schema#',
13
		'owl'		=> 'http://www.w3.org/2002/07/owl#',
14
		'xsd' 		=> 'http://www.w3.org/2001/XMLSchema#',
15
		'dct' 		=> 'http://purl.org/dc/terms/',
16
		'void' 		=> 'http://rdfs.org/ns/void#',
17
		'prov' 		=> 'http://www.w3.org/ns/prov#',
18
		'schema'	=> 'http://schema.org/',
19
		'wgs' 		=> 'http://www.w3.org/2003/01/geo/wgs84_pos#',
20
		'foaf' 		=> 'http://xmlns.com/foaf/0.1/',
21
		'dq'		=> 'http://purl.org/linked-data/cube#',
22
		'daq'		=> 'http://purl.org/eis/vocab/daq#',
23
		'botk' 		=> 'http://http://linkeddata.center/botk/v1#',
24
	);
25
	
26
	
27
    /**
28
     * @dataProvider data
29
     */	
30
	public function testConstructor($data, $expectedData)
31
	{
32
		$localBusiness = new DummyModel($data);		
33
		$this->assertEquals($expectedData, $localBusiness->asArray());
34
	}
35
	public function data()
36
    {
37
    	return array( 
38
    		array( array(), array('base'=> 'http://linkeddata.center/botk/resource/'),),
39
    		array( array('base'	=> 'urn:a:','id'=>'x'), array('base'=> 'urn:a:','id'=>'x')),
40
		);
41
   	}
42
43
44
	public function testConstructorWithCustomOptions()
45
	{
46
		$localBusiness = new DummyModel(array(), array (
47
			'base'	=> array('default'	=> 'urn:a:'),
48
			'lang'	=> array('default'	=> 'en'),
49
		));
50
		$options = $localBusiness->getOptions();
51
		$this->assertEquals(
52
			array(		
53
				'default'    => 'urn:a:',
54
				'filter'    => FILTER_SANITIZE_URL,
55
            	'flags'  	=> FILTER_REQUIRE_SCALAR,
56
			),
57
			$options['base']
58
		);
59
		$this->assertEquals(array('default'    => 'en'),$options['lang']);
60
	}
61
	
62
		
63
	public function testgetVocabularies()
64
	{
65
		$obj = new DummyModel(array());
66
		
67
		$this->assertEquals($this->vocabulary,  $obj->getVocabularies());
68
	}
69
	
70
	
71 View Code Duplication
	public function testSetVocabulary()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
72
	{
73
		$vocabulary = $this->vocabulary;
74
		$vocabulary['my'] = 'urn:test:';
75
		
76
		$obj = new DummyModel(array());
77
		$obj->setVocabulary('my','urn:test:');
78
		
79
		$this->assertEquals($vocabulary,  $obj->getVocabularies());
80
	}
81
	
82
	
83 View Code Duplication
	public function testUnsetVocabulary()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
84
	{
85
		$vocabulary = $this->vocabulary;
86
		unset($vocabulary['foaf']);
87
		
88
		$obj = new DummyModel(array());
89
		$obj->unsetVocabulary('foaf');
90
		
91
		$this->assertEquals($vocabulary,  $obj->getVocabularies());
92
	}
93
	
94
95
    /**
96
     * @dataProvider uris
97
     */	
98
	public function testGetUri($data, $expectedData)
99
	{
100
		$obj = new DummyModel($data);
101
		$obj->setIdGenerator(function($d){return'abc';});
0 ignored issues
show
Unused Code introduced by
The parameter $d is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
102
		$this->assertEquals($expectedData, $obj->getUri());
103
	}
104
	public function uris()
105
    {
106
    	return array( 
107
	    	array( array(),	'http://linkeddata.center/botk/resource/abc'),
108
	    	array( array('base'=>'http://example.com/resource/'),	'http://example.com/resource/abc'),
109
	    	array( array('base'=>'http://example.com/resource/', 'id'=>'efg'),	'http://example.com/resource/efg'),
110
	    	array( array('uri'=>'http://example.com/resource/ijk'),	'http://example.com/resource/ijk'),	
111
		);
112
   	}
113
114 View Code Duplication
	public function testTurtleHeader()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
115
	{		
116
		$obj = new DummyModel(array());
117
		$s ="";
118
		foreach( $this->vocabulary as $p=>$v){
119
			$s.= "@prefix $p: <$v> .\n";
120
		}
121
		
122
		$this->assertEquals($s,  $obj->getTurtleHeader());
123
	}
124
	
125
	
126 View Code Duplication
	public function testTurtleHeaderWithBase()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
127
	{		
128
		$obj = new DummyModel(array());
129
		$s ="@base <urn:a:b> .\n";
130
		foreach( $this->vocabulary as $p=>$v){
131
			$s.= "@prefix $p: <$v> .\n";
132
		}
133
		
134
		$this->assertEquals($s,  $obj->getTurtleHeader('urn:a:b'));
135
	}
136
	
137
	
138
139
	public function testAsString()
140
	{		
141
		$obj = new DummyModel(array());
142
		$s= $obj->getTurtleHeader() ."\n<urn:a:b> owl:sameAs <urn:a:b> .";
143
		
144
		$this->assertEquals($s,  (string)$obj);
145
	}
146
147
}
148
149