summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/includes/HighlighterTest.php
blob: 4bc78070aab9aef7b56449560a8e6bdde7bc602b (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
<?php

namespace SMW\Test;

use SMW\Highlighter;

/**
 * @covers \SMW\Highlighter
 * @group semantic-mediawiki
 *
 * @license GNU GPL v2+
 * @since 1.9
 *
 * @author mwjames
 */
class HighlighterTest extends \PHPUnit_Framework_TestCase {

	/**
	 * @dataProvider getTypeDataProvider
	 */
	public function testCanConstruct( $type ) {

		$this->assertInstanceOf(
			'\SMW\Highlighter',
			Highlighter::factory( $type )
		);
	}

	/**
	 * @dataProvider getTypeDataProvider
	 */
	public function testGetTypeId( $type, $expected ) {
		$results = Highlighter::getTypeId( $type );

		$this->assertInternalType(
			'integer',
			$results
		);

		$this->assertEquals(
			$expected,
			$results
		);
	}

	public function testDecode() {

		$this->assertEquals(
			'&<> ',
			Highlighter::decode( '&amp;&lt;&gt;&#160;<nowiki></nowiki>' )
		);
	}

	/**
	 * @dataProvider getTypeDataProvider
	 */
	public function testGetHtml( $type ) {

		$instance = Highlighter::factory( $type );

		$instance->setContent( [
			'title' => 'Foo'
		] );

		// Check without caption/content set
		$this->assertInternalType(
			'string',
			$instance->getHtml()
		);

		$instance->setContent( [
			'caption' => '123',
			'content' => 'ABC',
		] );

		// Check with caption/content set
		$this->assertInternalType(
			'string',
			$instance->getHtml()
		);
	}

	public function testHasHighlighterClass() {

		$instance = Highlighter::factory(
			Highlighter::TYPE_WARNING
		);

		$instance->setContent( [
			'title' => 'Foo'
		] );

		$this->assertTrue(
			Highlighter::hasHighlighterClass( $instance->getHtml(), 'warning' )
		);
	}

	public function getTypeDataProvider() {
		return [
			[ '' , Highlighter::TYPE_NOTYPE ],
			[ 'property', Highlighter::TYPE_PROPERTY ],
			[ 'text', Highlighter::TYPE_TEXT ],
			[ 'info', Highlighter::TYPE_INFO ],
			[ 'help', Highlighter::TYPE_HELP ],
			[ 'service', Highlighter::TYPE_SERVICE ],
			[ 'quantity', Highlighter::TYPE_QUANTITY ],
			[ 'note', Highlighter::TYPE_NOTE ],
			[ 'warning', Highlighter::TYPE_WARNING ],
			[ 'error', Highlighter::TYPE_ERROR ],
			[ 'PrOpErTy', Highlighter::TYPE_PROPERTY ],
			[ 'バカなテスト', Highlighter::TYPE_NOTYPE ],
			[ '<span>Something that should not work</span>', Highlighter::TYPE_NOTYPE ],
			[ Highlighter::TYPE_PROPERTY, Highlighter::TYPE_NOTYPE ]
		];
	}

}