summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/includes/storage/StoreTest.php
blob: 2b60cf469bb6e8e0fcc8e5f9166482caa8d5192f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<?php

namespace SMW\Test;

use SMW\Connection\ConnectionManager;
use SMW\DIProperty;
use SMW\DIWikiPage;
use SMW\StoreFactory;
use SMW\Tests\MwDBaseUnitTestCase;
use SMWRequestOptions;
use Title;

/**
 * Tests for the SMWStore class.
 *
 * @since 1.8
 *
 * @group SMW
 * @group SMWStore
 * @group SMWExtension
 * @group Database
 *
 * @author Nischay Nahata
 */
class StoreTest extends MwDBaseUnitTestCase {

///// Reading methods /////

	public function getSemanticDataProvider() {
		return [
			[ Title::newMainPage()->getFullText() ],
		];
	}

	/**
	* @dataProvider getSemanticDataProvider
	*/
	public function testGetSemanticData( $titleText ,$filter = false) {
		$title = Title::newFromText( $titleText );
		$subject = DIWikiPage::newFromTitle( $title );
		$store = StoreFactory::getStore();

		$this->assertInstanceOf(
			'\SMW\SemanticData',
			$store->getSemanticData( $subject, $filter ),
			"Result should be instance of SMWSemanticData."
		);
	}

	public function getPropertyValuesDataProvider() {
		return [
			[ Title::newMainPage()->getFullText(), new DIProperty('_MDAT') ],
			[ Title::newMainPage()->getFullText(), DIProperty::newFromUserLabel('Age') ],
		];
	}

	/**
	* @dataProvider getPropertyValuesDataProvider
	*/
	public function testGetPropertyValues( $titleText, DIProperty $property, $requestOptions = null ) {
		$title = Title::newFromText( $titleText );
		$subject = DIWikiPage::newFromTitle( $title );
		$store = StoreFactory::getStore();
		$result = $store->getPropertyValues( $subject, $property, $requestOptions );

		$this->assertInternalType( 'array', $result );
		$this->assertContainsOnlyInstancesOf( '\SMWDataItem', $result );
	}

	public function getPropertySubjectsDataProvider() {
		return [
			[ new DIProperty('_MDAT'), null ],
		];
	}

	/**
	* @dataProvider getPropertySubjectsDataProvider
	*/
	public function testGetPropertySubjects( DIProperty $property, $value, $requestOptions = null ) {
		$store = StoreFactory::getStore();
		$result = $store->getPropertySubjects( $property, $value, $requestOptions );

		$this->assertInstanceOf(
			'\Iterator',
			$result
		);

		foreach( $result as $page ) {
			$this->assertInstanceOf(
				'\SMW\DIWikiPage',
				$page,
				"Result should be instance of DIWikiPage."
			);
		}
	}

	public function getPropertiesDataProvider() {
		return [
			[ Title::newMainPage()->getFullText() ],
		];
	}

	/**
	* @dataProvider getPropertiesDataProvider
	*/
	public function testGetProperties( $titleText, $requestOptions = null ) {
		$title = Title::newFromText( $titleText );
		$subject = DIWikiPage::newFromTitle( $title );
		$store = StoreFactory::getStore();
		$result = $store->getProperties( $subject, $requestOptions );

		$this->assertTrue( is_array( $result ) );

		foreach( $result as $property ) {
			$this->assertInstanceOf(
				'\SMWDataItem',
				$property,
				"Result should be instance of DIProperty."
			);
		}
	}

///// Special page functions /////

	public function testGetPropertiesSpecial() {
		// Really bailing out here and making the test database dependent!!

		// This test fails on mysql http://bugs.mysql.com/bug.php?id=10327
		if( $GLOBALS['wgDBtype'] == 'mysql' ) {
			$this->assertTrue( true );
			return;
		}

		$store = StoreFactory::getStore();
		$result = $store->getPropertiesSpecial( new SMWRequestOptions() );

		$this->assertInstanceOf( '\SMW\SQLStore\Lookup\ListLookup', $result );
		foreach( $result->fetchList() as $row ) {
			$this->assertCount( 2, $row );

			$this->assertInstanceOf(
				'\SMWDataItem',
				$row[0],
				"Result should be DataItem instance."
			);
		}
	}

	public function testGetUnusedPropertiesSpecial() {
		$store = StoreFactory::getStore();
		$result = $store->getUnusedPropertiesSpecial( new SMWRequestOptions() );

		$this->assertInstanceOf( '\SMW\SQLStore\Lookup\ListLookup', $result );
		foreach( $result->fetchList() as $row ) {
			$this->assertInstanceOf(
				'\SMWDataItem',
				$row,
				"Result should be instance of DIProperty."
			);
		}
	}

	public function testGetWantedPropertiesSpecial() {
		$store = StoreFactory::getStore();
		$result = $store->getWantedPropertiesSpecial( new SMWRequestOptions() );

		$this->assertInstanceOf( '\SMW\SQLStore\Lookup\ListLookup', $result );
		foreach( $result->fetchList() as $row ) {
			$this->assertInstanceOf(
				'\SMW\DIProperty',
				$row[0],
				"Result should be instance of DIProperty."
			);
		}
	}

	public function testGetStatistics() {
		$store = StoreFactory::getStore();
		$result = $store->getStatistics();

		$this->assertTrue( is_array( $result ) );
		$this->assertArrayHasKey( 'PROPUSES', $result );
		$this->assertArrayHasKey( 'USEDPROPS', $result );
		$this->assertArrayHasKey( 'DECLPROPS', $result );
	}

	public function testConnection() {

		$store = StoreFactory::getStore();
		$store->setConnectionManager( new ConnectionManager() );

		$this->assertInstanceOf(
			'\SMW\MediaWiki\Database',
			$store->getConnection( 'mw.db' )
		);
	}

}