|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SG\Tests\Cache; |
|
4
|
|
|
|
|
5
|
|
|
use SG\Cache\ElementsCacheBuilder; |
|
6
|
|
|
use SG\Cache\GlossaryCache; |
|
7
|
|
|
|
|
8
|
|
|
use Lingo\Element; |
|
9
|
|
|
|
|
10
|
|
|
use SMWDIWikiPage as DIWikiPage; |
|
11
|
|
|
use SMWDIBlob as DIBlob; |
|
12
|
|
|
|
|
13
|
|
|
use Title; |
|
14
|
|
|
use HashBagOStuff; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @covers \SG\Cache\ElementsCacheBuilder |
|
18
|
|
|
* |
|
19
|
|
|
* @ingroup Test |
|
20
|
|
|
* |
|
21
|
|
|
* @group SG |
|
22
|
|
|
* @group SGExtension |
|
23
|
|
|
* @group extension-semantic-glossary |
|
24
|
|
|
* |
|
25
|
|
|
* @license GNU GPL v2+ |
|
26
|
|
|
* @since 1.1 |
|
27
|
|
|
* |
|
28
|
|
|
* @author mwjames |
|
29
|
|
|
*/ |
|
30
|
|
|
class ElementsCacheBuilderTest extends \PHPUnit_Framework_TestCase { |
|
31
|
|
|
|
|
32
|
|
|
public function testCanConstruct() { |
|
33
|
|
|
|
|
34
|
|
|
$store = $this->getMockBuilder( '\SMW\Store' ) |
|
35
|
|
|
->disableOriginalConstructor() |
|
36
|
|
|
->getMockForAbstractClass(); |
|
37
|
|
|
|
|
38
|
|
|
$glossaryCache = $this->getMock( '\SG\Cache\GlossaryCache' ); |
|
39
|
|
|
|
|
40
|
|
|
$this->assertInstanceOf( |
|
41
|
|
|
'\SG\Cache\ElementsCacheBuilder', |
|
42
|
|
|
new ElementsCacheBuilder( $store, $glossaryCache ) |
|
43
|
|
|
); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function testGetTermsForSingleTermWithDefinitionOnNonCachedResult() { |
|
47
|
|
|
|
|
48
|
|
|
$page = DIWikiPage::newFromTitle( Title::newFromText( __METHOD__ ) ); |
|
49
|
|
|
|
|
50
|
|
|
$queryResult = $this->getMockBuilder( '\stdClass' ) |
|
51
|
|
|
->disableOriginalConstructor() |
|
52
|
|
|
->setMethods( array( 'getResults' ) ) |
|
53
|
|
|
->getMock(); |
|
54
|
|
|
|
|
55
|
|
|
$queryResult->expects( $this->once() ) |
|
56
|
|
|
->method( 'getResults' ) |
|
57
|
|
|
->will( $this->returnValue( array( $page ) ) ); |
|
58
|
|
|
|
|
59
|
|
|
$store = $this->getMockBuilder( 'SMWStore' ) |
|
60
|
|
|
->disableOriginalConstructor() |
|
61
|
|
|
->getMockForAbstractClass(); |
|
62
|
|
|
|
|
63
|
|
|
$store->expects( $this->once() ) |
|
64
|
|
|
->method( 'getQueryResult' ) |
|
65
|
|
|
->will( $this->returnValue( $queryResult ) ); |
|
66
|
|
|
|
|
67
|
|
|
// at() position depends on the sequence as to when a method is called |
|
68
|
|
|
|
|
69
|
|
|
$store->expects( $this->at( 1 ) ) |
|
70
|
|
|
->method( 'getPropertyValues' ) |
|
71
|
|
|
->will( $this->returnValue( array( new DIBlob( ' Foo term ' ) ) ) ); |
|
72
|
|
|
|
|
73
|
|
|
$store->expects( $this->at( 2 ) ) |
|
74
|
|
|
->method( 'getPropertyValues' ) |
|
75
|
|
|
->will( $this->returnValue( array( new DIBlob( ' some Definition ' ) ) ) ); |
|
76
|
|
|
|
|
77
|
|
|
$glossaryCache = new GlossaryCache( new HashBagOStuff() ); |
|
78
|
|
|
|
|
79
|
|
|
$instance = new ElementsCacheBuilder( |
|
80
|
|
|
$store, |
|
81
|
|
|
$glossaryCache |
|
82
|
|
|
); |
|
83
|
|
|
|
|
84
|
|
|
$results = $instance->getElements(); |
|
85
|
|
|
|
|
86
|
|
|
$this->assertEquals( |
|
87
|
|
|
$results, |
|
88
|
|
|
$glossaryCache->getCache()->get( $glossaryCache->getKeyForSubject( $page ) ) |
|
89
|
|
|
); |
|
90
|
|
|
|
|
91
|
|
|
$this->assertLingoElement( |
|
92
|
|
|
'Foo term', |
|
93
|
|
|
'some Definition', |
|
94
|
|
|
null, |
|
95
|
|
|
null, |
|
96
|
|
|
$results[0] |
|
97
|
|
|
); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
protected function assertLingoElement( $term, $definition, $link, $style, $result ) { |
|
101
|
|
|
|
|
102
|
|
|
$this->assertEquals( $term, $result[ Element::ELEMENT_TERM ] ); |
|
103
|
|
|
$this->assertEquals( $definition, $result[ Element::ELEMENT_DEFINITION ] ); |
|
104
|
|
|
$this->assertEquals( $link, $result[ Element::ELEMENT_LINK ] ); |
|
105
|
|
|
$this->assertEquals( $style, $result[ Element::ELEMENT_STYLE ] ); |
|
106
|
|
|
|
|
107
|
|
|
$this->assertInstanceOf( |
|
108
|
|
|
'SMWDIWikiPage', |
|
109
|
|
|
$result[ Element::ELEMENT_SOURCE ] |
|
110
|
|
|
); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
} |
|
114
|
|
|
|