summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/TypesRegistryTest.php
blob: 440e12db51352e8072a292a5a3bdc084b327f53e (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
<?php

namespace SMW\Tests;

use SMW\TypesRegistry;

/**
 * @covers \SMW\TypesRegistry
 * @group semantic-mediawiki
 *
 * @license GNU GPL v2+
 * @since 3.0
 *
 * @author mwjames
 */
class TypesRegistryTest extends \PHPUnit_Framework_TestCase {

	public function testGetDataTypeList() {

		$this->assertInternalType(
			'array',
			TypesRegistry::getDataTypeList()
		);
	}

	public function testGetPropertyList() {

		$this->assertInternalType(
			'array',
			TypesRegistry::getPropertyList()
		);
	}

	public function testGetFixedPropertyIdList() {

		$propertyList = TypesRegistry::getPropertyList();

		foreach ( TypesRegistry::getFixedPropertyIdList() as $key => $id ) {
			$this->assertArrayHasKey( $key, $propertyList );
		}
	}

	/**
	 * @dataProvider typeList
	 */
	public function testTypeList_FirstCharUnderscore( $key, $def ) {
		$this->assertTrue( $key{0} === '_' );
	}

	/**
	 * @dataProvider typeList
	 */
	public function testTypeList_ClassExists( $key, $def ) {
		$this->assertTrue( class_exists( $def[0] ) );
	}

	/**
	 * @dataProvider propertyList
	 */
	public function testPropertyList_FirstCharUnderscore( $key, $def ) {
		$this->assertTrue( $key{0} === '_' );
	}

	public function typeList() {

		$excludes = [];

		// Requires Maps/Semantic Maps hence remove from the
		// test list
		$excludes = [ '_geo', '_gpo' ];

		foreach ( TypesRegistry::getDataTypeList() as $key => $def ) {

			if ( in_array( $key, $excludes ) ) {
				continue;
			}

			yield[ $key, $def ];
		}
	}

	public function propertyList() {

		$excludes = [];

		foreach ( TypesRegistry::getPropertyList() as $key => $def ) {

			if ( in_array( $key, $excludes ) ) {
				continue;
			}

			yield[ $key, $def ];
		}
	}

}