summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Utils/Fixtures/FixturesProvider.php
blob: b3f3893ecdf2f75322d12434b3d88f995a862463 (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
<?php

namespace SMW\Tests\Utils\Fixtures;

use RuntimeException;
use SMW\Store;
use SMW\Tests\Utils\Fixtures\Facts\BerlinFactsheet;
use SMW\Tests\Utils\Fixtures\Facts\FranceFactsheet;
use SMW\Tests\Utils\Fixtures\Facts\ParisFactsheet;
use SMW\Tests\Utils\Fixtures\Properties\AreaProperty;
use SMW\Tests\Utils\Fixtures\Properties\BookRecordProperty;
use SMW\Tests\Utils\Fixtures\Properties\CityCategory;
use SMW\Tests\Utils\Fixtures\Properties\FoundedProperty;
use SMW\Tests\Utils\Fixtures\Properties\LocatedInProperty;
use SMW\Tests\Utils\Fixtures\Properties\PopulationDensityProperty;
use SMW\Tests\Utils\Fixtures\Properties\PopulationProperty;
use SMW\Tests\Utils\Fixtures\Properties\StatusProperty;
use SMW\Tests\Utils\Fixtures\Properties\TitleProperty;
use SMW\Tests\Utils\Fixtures\Properties\UrlProperty;
use SMW\Tests\Utils\Fixtures\Properties\YearProperty;

/**
 * @license GNU GPL v2+
 * @since 2.1
 *
 * @author mwjames
 */
class FixturesProvider {

	private $factsheets = null;
	private $properties = null;
	private $categories = null;

	/**
	 * @since 2.1
	 */
	public function setupDependencies( Store $store ) {

		// This needs to happen before access to a property object is granted

		// $pageCreator = UtilityFactory::getInstance()->newPageCreator();

		foreach ( $this->getListOfPropertyInstances() as $propertyInstance ) {
			$store->updateData( $propertyInstance->getDependencies() );
		}
	}

	/**
	 * @since 2.1
	 *
	 * @return array
	 */
	public function getListOfFactsheetInstances() {
		return [
			'berlin' => new BerlinFactsheet(),
			'paris'  => new ParisFactsheet(),
			'france'  => new FranceFactsheet()
		];
	}

	/**
	 * @since 2.1
	 *
	 * @return array
	 */
	public function getListOfPropertyInstances() {
		return [
			'area' => new AreaProperty(),
			'populationdensity' => new PopulationDensityProperty(),
		//	'capitalof' => new CapitalOfProperty(),
			'status' => new StatusProperty(),
			'population' => new PopulationProperty(),
			'founded' => new FoundedProperty(),
			'locatedin' => new LocatedInProperty(),
			'bookrecord' => new BookRecordProperty(),
			'year' => new YearProperty(),
			'title' => new TitleProperty(),
			'url' => new UrlProperty()
		];
	}

	/**
	 * @since 2.1
	 *
	 * @return array
	 */
	public function getListOfCategoryInstances() {
		return [
			'city' => new CityCategory()
		];
	}

	/**
	 * @since 2.1
	 *
	 * @return DIProperty
	 * @throws RuntimeException
	 */
	public function getProperty( $id ) {

		$id = strtolower( $id );

		if ( $this->properties === null ) {
			$this->properties = $this->getListOfPropertyInstances();
		};

		if ( isset( $this->properties[$id] ) ) {
			return $this->properties[$id]->getProperty();
		}

		throw new RuntimeException( "$id is an unknown requested property" );
	}

	/**
	 * @since 2.1
	 *
	 * @return DIProperty
	 * @throws RuntimeException
	 */
	public function getCategory( $id ) {

		$id = strtolower( $id );

		if ( $this->categories === null ) {
			$this->categories = $this->getListOfCategoryInstances();
		};

		if ( isset( $this->categories[$id] ) ) {
			return $this->categories[$id];
		}

		throw new RuntimeException( "$id is an unknown requested property" );
	}

	/**
	 * @since 2.1
	 *
	 * @return Factsheet
	 * @throws RuntimeException
	 */
	public function getFactsheet( $id ) {

		$id = strtolower( $id );

		if ( $this->factsheets === null ) {
			$this->factsheets = $this->getListOfFactsheetInstances();
		};

		if ( isset( $this->factsheets[$id] ) ) {
			return $this->factsheets[$id];
		}

		throw new RuntimeException( "$id is an unknown requested fact" );
	}

	/**
	 * @since 2.1
	 *
	 * @return FixturesCleaner
	 */
	public function getCleaner() {
		return new FixturesCleaner();
	}

}