summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Query/Language/NamespaceDescriptionTest.php
blob: 4d35298bd9956932704f4eb9f9e9320c1916a83e (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\Query\Language;

use SMW\Localizer;
use SMW\Query\Language\NamespaceDescription;
use SMW\Query\Language\ThingDescription;

/**
 * @covers \SMW\Query\Language\NamespaceDescription
 * @group semantic-mediawiki
 *
 * @license GNU GPL v2+
 * @since 2.1
 *
 * @author mwjames
 */
class NamespaceDescriptionTest extends \PHPUnit_Framework_TestCase {

	public function testCanConstruct() {

		$namespace = NS_MAIN;

		$this->assertInstanceOf(
			'SMW\Query\Language\NamespaceDescription',
			new NamespaceDescription( $namespace )
		);

		// Legacy
		$this->assertInstanceOf(
			'SMW\Query\Language\NamespaceDescription',
			new \SMWNamespaceDescription( $namespace )
		);
	}

	public function testCommonMethods() {

		$namespace = NS_MAIN;

		$instance = new NamespaceDescription( $namespace );

		$this->assertEquals( $namespace, $instance->getNamespace() );

		$this->assertEquals( "[[:+]]", $instance->getQueryString() );
		$this->assertEquals( " <q>[[:+]]</q> ", $instance->getQueryString( true ) );

		$this->assertEquals( false, $instance->isSingleton() );
		$this->assertEquals( [], $instance->getPrintRequests() );

		$this->assertEquals( 1, $instance->getSize() );
		$this->assertEquals( 0, $instance->getDepth() );
		$this->assertEquals( 8, $instance->getQueryFeatures() );
	}

	public function testGetQueryStringForCategoryNamespace() {

		$namespace = NS_CATEGORY;

		$ns = Localizer::getInstance()->getNamespaceTextById( $namespace );
		$instance = new NamespaceDescription( $namespace );

		$this->assertEquals(
			"[[:{$ns}:+]]",
			$instance->getQueryString()
		);

		$this->assertEquals(
			" <q>[[:{$ns}:+]]</q> ",
			$instance->getQueryString( true )
		);
	}

	public function testPrune() {

		$instance = new NamespaceDescription( NS_MAIN );

		$maxsize  = 1;
		$maxDepth = 1;
		$log      = [];

		$this->assertEquals(
			$instance,
			$instance->prune( $maxsize, $maxDepth, $log )
		);

		$maxsize  = 0;
		$maxDepth = 1;
		$log      = [];

		$this->assertEquals(
			new ThingDescription(),
			$instance->prune( $maxsize, $maxDepth, $log )
		);
	}

}