1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\Tests\SQLStore\QueryEngine\Fulltext; |
4
|
|
|
|
5
|
|
|
use SMW\SQLStore\QueryEngine\Fulltext\SearchTable; |
6
|
|
|
use SMW\DataItemFactory; |
7
|
|
|
use SMWDataItem as DataItem; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @covers \SMW\SQLStore\QueryEngine\Fulltext\SearchTable |
11
|
|
|
* @group semantic-mediawiki |
12
|
|
|
* |
13
|
|
|
* @license GNU GPL v2+ |
14
|
|
|
* @since 2.5 |
15
|
|
|
* |
16
|
|
|
* @author mwjames |
17
|
|
|
*/ |
18
|
|
|
class SearchTableTest extends \PHPUnit_Framework_TestCase { |
19
|
|
|
|
20
|
|
|
private $store; |
21
|
|
|
private $dataItemFactory; |
22
|
|
|
|
23
|
|
|
protected function setUp() { |
24
|
|
|
|
25
|
|
|
$this->dataItemFactory = new DataItemFactory(); |
26
|
|
|
|
27
|
|
|
$this->store = $this->getMockBuilder( '\SMW\SQLStore\SQLStore' ) |
28
|
|
|
->disableOriginalConstructor() |
29
|
|
|
->getMock(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testCanConstruct() { |
33
|
|
|
|
34
|
|
|
$this->assertInstanceOf( |
35
|
|
|
'\SMW\SQLStore\QueryEngine\Fulltext\SearchTable', |
36
|
|
|
new SearchTable( $this->store ) |
37
|
|
|
); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testIsEnabled() { |
41
|
|
|
|
42
|
|
|
$instance = new SearchTable( |
43
|
|
|
$this->store |
44
|
|
|
); |
45
|
|
|
|
46
|
|
|
$instance->setEnabled( true ); |
47
|
|
|
|
48
|
|
|
$this->assertTrue( |
49
|
|
|
$instance->isEnabled() |
50
|
|
|
); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testGetPropertyExemptionList() { |
54
|
|
|
|
55
|
|
|
$instance = new SearchTable( |
56
|
|
|
$this->store |
57
|
|
|
); |
58
|
|
|
|
59
|
|
|
$instance->setPropertyExemptionList( |
60
|
|
|
array( '_TEXT','fo oo' ) |
61
|
|
|
); |
62
|
|
|
|
63
|
|
|
$this->assertEquals( |
64
|
|
|
array( '_TEXT', 'fo_oo' ), |
65
|
|
|
$instance->getPropertyExemptionList() |
66
|
|
|
); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function testIsExemptedProperty() { |
70
|
|
|
|
71
|
|
|
$instance = new SearchTable( |
72
|
|
|
$this->store |
73
|
|
|
); |
74
|
|
|
|
75
|
|
|
$instance->setIndexableDataTypes( |
76
|
|
|
SMW_FT_BLOB | SMW_FT_URI |
77
|
|
|
); |
78
|
|
|
|
79
|
|
|
$instance->setPropertyExemptionList( |
80
|
|
|
array( '_TEXT' ) |
81
|
|
|
); |
82
|
|
|
|
83
|
|
|
$property = $this->dataItemFactory->newDIProperty( '_TEXT' ); |
84
|
|
|
|
85
|
|
|
$this->assertTrue( |
86
|
|
|
$instance->isExemptedProperty( $property ) |
87
|
|
|
); |
88
|
|
|
|
89
|
|
|
$property = $this->dataItemFactory->newDIProperty( 'Foo' ); |
90
|
|
|
$property->setPropertyTypeId( '_uri' ); |
91
|
|
|
|
92
|
|
|
$this->assertFalse( |
93
|
|
|
$instance->isExemptedProperty( $property ) |
94
|
|
|
); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function testIsValidType() { |
98
|
|
|
|
99
|
|
|
$instance = new SearchTable( |
100
|
|
|
$this->store |
101
|
|
|
); |
102
|
|
|
|
103
|
|
|
$instance->setIndexableDataTypes( |
104
|
|
|
SMW_FT_BLOB | SMW_FT_URI |
105
|
|
|
); |
106
|
|
|
|
107
|
|
|
$this->assertTrue( |
108
|
|
|
$instance->isValidByType( DataItem::TYPE_BLOB ) |
109
|
|
|
); |
110
|
|
|
|
111
|
|
|
$this->assertFalse( |
112
|
|
|
$instance->isValidByType( DataItem::TYPE_WIKIPAGE ) |
113
|
|
|
); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function testHasMinTokenLength() { |
117
|
|
|
|
118
|
|
|
$instance = new SearchTable( |
119
|
|
|
$this->store |
120
|
|
|
); |
121
|
|
|
|
122
|
|
|
$instance->setMinTokenSize( 4 ); |
123
|
|
|
|
124
|
|
|
$this->assertFalse( |
125
|
|
|
$instance->hasMinTokenLength( 'bar' ) |
126
|
|
|
); |
127
|
|
|
|
128
|
|
|
$this->assertFalse( |
129
|
|
|
$instance->hasMinTokenLength( 'テスト' ) |
130
|
|
|
); |
131
|
|
|
|
132
|
|
|
$this->assertTrue( |
133
|
|
|
$instance->hasMinTokenLength( 'test' ) |
134
|
|
|
); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
} |
138
|
|
|
|