summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Query/ScoreSetTest.php
blob: 32b78908156761b70dd2d8f2baea0354e3e2b93c (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
<?php

namespace SMW\Tests\Query;

use SMW\DIWikiPage;
use SMW\Query\ScoreSet;

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

	public function testCanConstruct() {

		$this->assertInstanceOf(
			ScoreSet::class,
			new ScoreSet()
		);
	}

	public function testAddScore() {

		$instance = new ScoreSet();

		$instance->addScore( 'Foo', 0.1 );

		$this->assertEquals(
			0.1,
			$instance->getScore( 'Foo' )
		);

		$this->assertFalse(
			$instance->getScore( 'Bar' )
		);
	}

	public function testAddScore_DIWikiPage() {

		$dataItem = DIWikiPage::newFromText( 'Bar' );
		$instance = new ScoreSet();

		$instance->addScore( $dataItem, 10 );

		$this->assertEquals(
		10,
			$instance->getScore( $dataItem )
		);
	}

	public function testGetScores() {

		$instance = new ScoreSet();

		$instance->addScore( 'Foo', 42 );
		$instance->addScore( 'Bar', 1001 );

		$this->assertEquals(
			[
				[ 'Foo', 42 ],
				[ 'Bar', 1001 ]
			],
			$instance->getScores()
		);
	}

	public function testAsTable() {

		$instance = new ScoreSet();

		$instance->addScore( 'Foo', 42 );
		$instance->addScore( 'Bar', 1001, 5 );
		$instance->addScore( 'Foobar', 1 );

		$table = $instance->asTable();

		$this->assertContains(
			'<tr><td>42</td><td>Foo</td><td>0</td></tr>',
			$table
		);

		$this->assertContains(
			'<tr><td>1001</td><td>Bar</td><td>5</td></tr>',
			$table
		);
	}

}