1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\Tests\Query\ProfileAnnotators; |
4
|
|
|
|
5
|
|
|
use SMW\DIWikiPage; |
6
|
|
|
use SMW\Query\ProfileAnnotators\ParametersProfileAnnotator; |
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\ParametersProfileAnnotator |
14
|
|
|
* @group semantic-mediawiki |
15
|
|
|
* |
16
|
|
|
* @license GNU GPL v2+ |
17
|
|
|
* @since 1.9 |
18
|
|
|
* |
19
|
|
|
* @author mwjames |
20
|
|
|
*/ |
21
|
|
|
class ParametersProfileAnnotatorTest 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
|
|
|
$query = $this->getMockBuilder( '\SMWQuery' ) |
38
|
|
|
->disableOriginalConstructor() |
39
|
|
|
->getMock(); |
40
|
|
|
|
41
|
|
|
$this->assertInstanceOf( |
42
|
|
|
'\SMW\Query\ProfileAnnotators\ParametersProfileAnnotator', |
43
|
|
|
new ParametersProfileAnnotator( $profileAnnotator, $query ) |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testCreateProfile() { |
48
|
|
|
|
49
|
|
|
$subject =new DIWikiPage( __METHOD__, NS_MAIN, '', 'foo' ); |
50
|
|
|
|
51
|
|
|
$container = new DIContainer( |
52
|
|
|
new ContainerSemanticData( $subject ) |
53
|
|
|
); |
54
|
|
|
|
55
|
|
|
$query = $this->getMockBuilder( '\SMWQuery' ) |
56
|
|
|
->disableOriginalConstructor() |
57
|
|
|
->getMock(); |
58
|
|
|
|
59
|
|
|
$query->expects( $this->once() ) |
60
|
|
|
->method( 'getLimit' ) |
61
|
|
|
->will( $this->returnValue( 42 ) ); |
62
|
|
|
|
63
|
|
|
$query->expects( $this->once() ) |
64
|
|
|
->method( 'getOffset' ) |
65
|
|
|
->will( $this->returnValue( 0 ) ); |
66
|
|
|
|
67
|
|
|
$query->expects( $this->once() ) |
68
|
|
|
->method( 'getQueryMode' ) |
69
|
|
|
->will( $this->returnValue( 1 ) ); |
70
|
|
|
|
71
|
|
|
$instance = new ParametersProfileAnnotator( |
72
|
|
|
new NullProfileAnnotator( $container ), |
73
|
|
|
$query |
74
|
|
|
); |
75
|
|
|
|
76
|
|
|
$instance->addAnnotation(); |
77
|
|
|
|
78
|
|
|
$expected = array( |
79
|
|
|
'propertyCount' => 1, |
80
|
|
|
'propertyKeys' => array( '_ASKPA' ), |
81
|
|
|
'propertyValues' => array( '{"limit":42,"offset":0,"sort":[],"order":[],"mode":1}' ) |
82
|
|
|
); |
83
|
|
|
|
84
|
|
|
$this->semanticDataValidator->assertThatPropertiesAreSet( |
85
|
|
|
$expected, |
86
|
|
|
$instance->getContainer()->getSemanticData() |
87
|
|
|
); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
} |
91
|
|
|
|