Passed
Push — Facets ( b72148...68bbc0 )
by Daniel
07:49 queued 03:58
created

TermTest::testListFacets()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4286
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace Wikibase\DataModel\Tests\Term;
4
5
use InvalidArgumentException;
6
use Wikibase\DataModel\Term\Term;
7
use Wikibase\DataModel\Tests\Facet\FacetContainerContractTester;
8
9
/**
10
 * @covers Wikibase\DataModel\Term\Term
11
 *
12
 * @licence GNU GPL v2+
13
 * @author Jeroen De Dauw < [email protected] >
14
 */
15
class TermTest extends \PHPUnit_Framework_TestCase {
16
17
	public function testConstructorSetsFields() {
18
		$term = new Term( 'foo', 'bar' );
19
		$this->assertEquals( 'foo', $term->getLanguageCode() );
20
		$this->assertEquals( 'bar', $term->getText() );
21
	}
22
23
	/**
24
	 * @dataProvider invalidLanguageCodeProvider
25
	 * @expectedException InvalidArgumentException
26
	 */
27
	public function testGivenInvalidLanguageCode_constructorThrowsException( $languageCode ) {
28
		new Term( $languageCode, 'bar' );
29
	}
30
31
	public function invalidLanguageCodeProvider() {
32
		return array(
33
			array( null ),
34
			array( 21 ),
35
			array( '' ),
36
		);
37
	}
38
39
	/**
40
	 * @dataProvider nonStringProvider
41
	 */
42
	public function testGivenNonStringText_constructorThrowsException( $nonString ) {
43
		$this->setExpectedException( 'InvalidArgumentException' );
44
		new Term( 'foo', $nonString );
45
	}
46
47
	public function nonStringProvider() {
48
		return array(
49
			array( null ),
50
			array( array() ),
51
			array( 42 ),
52
			array( true ),
53
		);
54
	}
55
56
	public function testEquality() {
57
		$term = new Term( 'foo', 'bar' );
58
59
		$this->assertTrue( $term->equals( $term ) );
60
		$this->assertTrue( $term->equals( clone $term ) );
61
62
		$this->assertFalse( $term->equals( new Term( 'foo', 'spam' ) ) );
63
		$this->assertFalse( $term->equals( new Term( 'spam', 'bar' ) ) );
64
		$this->assertFalse( $term->equals( new Term( 'spam', 'spam' ) ) );
65
	}
66
67
	public function testHasFacet() {
68
		$tester = new FacetContainerContractTester();
69
		$term = new Term( 'foo', 'bar' );
70
71
		$tester->testHasFacet( $term );
72
	}
73
74
	public function testListFacets() {
75
		$tester = new FacetContainerContractTester();
76
		$term = new Term( 'foo', 'bar' );
77
78
		$tester->testListFacets( $term );
79
	}
80
81
	public function testGetFacet() {
82
		$tester = new FacetContainerContractTester();
83
		$term = new Term( 'foo', 'bar' );
84
85
		$tester->testGetFacet( $term );
86
	}
87
88
	public function testAddFacet() {
89
		$tester = new FacetContainerContractTester();
90
		$term = new Term( 'foo', 'bar' );
91
92
		$tester->testAddFacet( $term );
93
	}
94
95
}
96