1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\Tests\SQLStore\QueryDependency; |
4
|
|
|
|
5
|
|
|
use SMW\SQLStore\QueryDependency\QueryReferenceBacklinks; |
6
|
|
|
use SMW\Tests\TestEnvironment; |
7
|
|
|
use SMW\DataItemFactory; |
8
|
|
|
use SMW\RequestOptions; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @covers \SMW\SQLStore\QueryDependency\QueryReferenceBacklinks |
12
|
|
|
* @group semantic-mediawiki |
13
|
|
|
* |
14
|
|
|
* @license GNU GPL v2+ |
15
|
|
|
* @since 2.5 |
16
|
|
|
* |
17
|
|
|
* @author mwjames |
18
|
|
|
*/ |
19
|
|
|
class QueryReferenceBacklinksTest extends \PHPUnit_Framework_TestCase { |
20
|
|
|
|
21
|
|
|
private $dataItemFactory; |
22
|
|
|
|
23
|
|
|
protected function setUp() { |
24
|
|
|
parent::setUp(); |
25
|
|
|
|
26
|
|
|
$this->dataItemFactory = new DataItemFactory(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
protected function tearDown() { |
30
|
|
|
parent::tearDown(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testCanConstruct() { |
34
|
|
|
|
35
|
|
|
$queryDependencyLinksStore = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\QueryDependencyLinksStore' ) |
36
|
|
|
->disableOriginalConstructor() |
37
|
|
|
->getMock(); |
38
|
|
|
|
39
|
|
|
$this->assertInstanceOf( |
40
|
|
|
'\SMW\SQLStore\QueryDependency\QueryReferenceBacklinks', |
41
|
|
|
new QueryReferenceBacklinks( $queryDependencyLinksStore ) |
42
|
|
|
); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testAddQueryReferenceBacklinksTo() { |
46
|
|
|
|
47
|
|
|
$subject = $this->dataItemFactory->newDIWikiPage( 'Bar', NS_MAIN, '', '' ); |
48
|
|
|
|
49
|
|
|
$semanticData = $this->getMockBuilder( '\SMW\SemanticData' ) |
50
|
|
|
->disableOriginalConstructor() |
51
|
|
|
->getMock(); |
52
|
|
|
|
53
|
|
|
$semanticData->expects( $this->atLeastOnce() ) |
54
|
|
|
->method( 'getSubject' ) |
55
|
|
|
->will( $this->returnValue( $subject ) ); |
56
|
|
|
|
57
|
|
|
$semanticData->expects( $this->any() ) |
58
|
|
|
->method( 'addPropertyObjectValue' ) |
59
|
|
|
->with( |
60
|
|
|
$this->equalTo( $this->dataItemFactory->newDIProperty( '_ASK' ) ), |
61
|
|
|
$this->equalTo( $this->dataItemFactory->newDIWikiPage( 'Foo', NS_MAIN ) ) ); |
62
|
|
|
|
63
|
|
|
$queryDependencyLinksStore = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\QueryDependencyLinksStore' ) |
64
|
|
|
->disableOriginalConstructor() |
65
|
|
|
->getMock(); |
66
|
|
|
|
67
|
|
|
$queryDependencyLinksStore->expects( $this->once() ) |
68
|
|
|
->method( 'isEnabled' ) |
69
|
|
|
->will( $this->returnValue( true ) ); |
70
|
|
|
|
71
|
|
|
$queryDependencyLinksStore->expects( $this->any() ) |
72
|
|
|
->method( 'findEmbeddedQueryIdListBySubject' ) |
73
|
|
|
->with( $this->equalTo( $subject ) ) |
74
|
|
|
->will( $this->returnValue( array( 'Foo#0##' => 42 ) ) ); |
75
|
|
|
|
76
|
|
|
$queryDependencyLinksStore->expects( $this->once() ) |
77
|
|
|
->method( 'findEmbeddedQueryTargetLinksHashListBySubject' ) |
78
|
|
|
->will( $this->returnValue( array( 'Foo#0##' ) ) ); |
79
|
|
|
|
80
|
|
|
$instance = new QueryReferenceBacklinks( |
81
|
|
|
$queryDependencyLinksStore |
82
|
|
|
); |
83
|
|
|
|
84
|
|
|
$requestOptions = new RequestOptions(); |
85
|
|
|
|
86
|
|
|
$this->assertTrue( |
87
|
|
|
$instance->addReferenceLinksTo( $semanticData, $requestOptions ) |
88
|
|
|
); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function testFindQueryReferenceBacklinks() { |
92
|
|
|
|
93
|
|
|
$subject = $this->dataItemFactory->newDIWikiPage( 'Bar', NS_MAIN, '', '' ); |
94
|
|
|
|
95
|
|
|
$queryDependencyLinksStore = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\QueryDependencyLinksStore' ) |
96
|
|
|
->disableOriginalConstructor() |
97
|
|
|
->getMock(); |
98
|
|
|
|
99
|
|
|
$queryDependencyLinksStore->expects( $this->any() ) |
100
|
|
|
->method( 'findEmbeddedQueryTargetLinksHashListBySubject' ) |
101
|
|
|
->will( $this->returnValue( array( 'Foo#0##' ) ) ); |
102
|
|
|
|
103
|
|
|
$instance = new QueryReferenceBacklinks( |
104
|
|
|
$queryDependencyLinksStore |
105
|
|
|
); |
106
|
|
|
|
107
|
|
|
$requestOptions = new RequestOptions(); |
108
|
|
|
|
109
|
|
|
$this->assertEquals( |
110
|
|
|
array( 'Foo#0##' ), |
111
|
|
|
$instance->findReferenceLinks( $subject, $requestOptions ) |
112
|
|
|
); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function testInspectFurtherLinkRequirement() { |
116
|
|
|
|
117
|
|
|
$property = $this->dataItemFactory->newDIProperty( '_ASK' ); |
118
|
|
|
$subject = $this->dataItemFactory->newDIWikiPage( 'Bar', NS_MAIN, '', '' ); |
119
|
|
|
|
120
|
|
|
$queryDependencyLinksStore = $this->getMockBuilder( '\SMW\SQLStore\QueryDependency\QueryDependencyLinksStore' ) |
121
|
|
|
->disableOriginalConstructor() |
122
|
|
|
->getMock(); |
123
|
|
|
|
124
|
|
|
$instance = new QueryReferenceBacklinks( |
125
|
|
|
$queryDependencyLinksStore |
126
|
|
|
); |
127
|
|
|
|
128
|
|
|
$html = ''; |
129
|
|
|
|
130
|
|
|
$this->assertFalse( |
131
|
|
|
$instance->doesRequireFurtherLink( $property, $subject, $html ) |
132
|
|
|
); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
} |
136
|
|
|
|