1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\Tests\Query\ProfileAnnotators; |
4
|
|
|
|
5
|
|
|
use SMW\DIWikiPage; |
6
|
|
|
use SMW\Query\ProfileAnnotators\DurationProfileAnnotator; |
7
|
|
|
use SMW\Query\ProfileAnnotators\NullProfileAnnotator; |
8
|
|
|
use SMW\Tests\Utils\UtilityFactory; |
9
|
|
|
use SMWContainerSemanticData as ContainerSemanticData; |
10
|
|
|
use SMWDIContainer as DIContainer; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @covers \SMW\Query\ProfileAnnotators\DurationProfileAnnotator |
14
|
|
|
* @group semantic-mediawiki |
15
|
|
|
* |
16
|
|
|
* @license GNU GPL v2+ |
17
|
|
|
* @since 1.9 |
18
|
|
|
* |
19
|
|
|
* @author mwjames |
20
|
|
|
*/ |
21
|
|
|
class DurationProfileAnnotatorTest extends \PHPUnit_Framework_TestCase { |
22
|
|
|
|
23
|
|
|
private $semanticDataValidator; |
24
|
|
|
|
25
|
|
|
protected function setUp() { |
26
|
|
|
parent::setUp(); |
27
|
|
|
|
28
|
|
|
$this->semanticDataValidator = UtilityFactory::getInstance()->newValidatorFactory()->newSemanticDataValidator(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testCanConstruct() { |
32
|
|
|
|
33
|
|
|
$profileAnnotator = $this->getMockBuilder( '\SMW\Query\ProfileAnnotator' ) |
34
|
|
|
->disableOriginalConstructor() |
35
|
|
|
->getMock(); |
36
|
|
|
|
37
|
|
|
$this->assertInstanceOf( |
38
|
|
|
'\SMW\Query\ProfileAnnotators\DurationProfileAnnotator', |
39
|
|
|
new DurationProfileAnnotator( $profileAnnotator, 0.42 ) |
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @dataProvider durationDataProvider |
45
|
|
|
*/ |
46
|
|
|
public function testCreateProfile( $duration, $expected ) { |
47
|
|
|
|
48
|
|
|
$subject =new DIWikiPage( __METHOD__, NS_MAIN, '', 'foo' ); |
49
|
|
|
|
50
|
|
|
$container = new DIContainer( |
51
|
|
|
new ContainerSemanticData( $subject ) |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
$instance = new DurationProfileAnnotator( |
55
|
|
|
new NullProfileAnnotator( $container ), |
56
|
|
|
$duration |
57
|
|
|
); |
58
|
|
|
|
59
|
|
|
$instance->addAnnotation(); |
60
|
|
|
|
61
|
|
|
$this->semanticDataValidator->assertThatPropertiesAreSet( |
62
|
|
|
$expected, |
63
|
|
|
$instance->getContainer()->getSemanticData() |
64
|
|
|
); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function durationDataProvider() { |
68
|
|
|
|
69
|
|
|
$provider = array(); |
70
|
|
|
|
71
|
|
|
$provider[] = array( 0, array( |
72
|
|
|
'propertyCount' => 0 |
73
|
|
|
) ); |
74
|
|
|
|
75
|
|
|
$provider[] = array( 0.9001, array( |
76
|
|
|
'propertyCount' => 1, |
77
|
|
|
'propertyKeys' => array( '_ASKDU' ), |
78
|
|
|
'propertyValues' => array( 0.9001 ) |
79
|
|
|
) ); |
80
|
|
|
|
81
|
|
|
return $provider; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
} |
85
|
|
|
|