|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Wikibase\TermStore\MediaWiki\Tests\Unit\PackagePrivate; |
|
4
|
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
|
6
|
|
|
use Wikibase\DataModel\Entity\ItemId; |
|
7
|
|
|
use Wikibase\TermStore\MediaWiki\PackagePrivate\InMemoryEntityTermStore; |
|
8
|
|
|
|
|
9
|
|
|
class InMemoryEntityTermStoreTest extends TestCase { |
|
10
|
|
|
|
|
11
|
|
|
public function testHasExactTermsReturnsTrueWhenTermsHaveBeenSet() { |
|
12
|
|
|
list( $entityId, $termsArray ) = $this->getEntityIdAndTermsArray(); |
|
13
|
|
|
$termStore = new InMemoryEntityTermStore(); |
|
14
|
|
|
|
|
15
|
|
|
$termStore->setTerms( $entityId, $termsArray ); |
|
16
|
|
|
|
|
17
|
|
|
$this->assertTrue( |
|
18
|
|
|
$termStore->hasExactTerms( $entityId, $termsArray ) |
|
19
|
|
|
); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function testHasExactTermsReturnsFalseWhenTermsNeverBeenSet() { |
|
23
|
|
|
list( $entityId, $termsArray ) = $this->getEntityIdAndTermsArray(); |
|
24
|
|
|
$termStore = new InMemoryEntityTermStore(); |
|
25
|
|
|
|
|
26
|
|
|
$this->assertFalse( |
|
27
|
|
|
$termStore->hasExactTerms( $entityId, $termsArray ) |
|
28
|
|
|
); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function testHasExactTermsReturnsFalseWhenTermsHaveBeenUnset() { |
|
32
|
|
|
list( $entityId, $termsArray ) = $this->getEntityIdAndTermsArray(); |
|
33
|
|
|
$termStore = new InMemoryEntityTermStore(); |
|
34
|
|
|
|
|
35
|
|
|
$termStore->setTerms( $entityId, $termsArray ); |
|
36
|
|
|
$termStore->unsetTerms( $entityId ); |
|
37
|
|
|
|
|
38
|
|
|
$this->assertFalse( |
|
39
|
|
|
$termStore->hasExactTerms( $entityId, $termsArray ) |
|
40
|
|
|
); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function testHasNoTermsReturnsFalseWhenTermsHaveBeenSet() { |
|
44
|
|
|
list( $entityId, $termsArray ) = $this->getEntityIdAndTermsArray(); |
|
45
|
|
|
$termStore = new InMemoryEntityTermStore(); |
|
46
|
|
|
|
|
47
|
|
|
$termStore->setTerms( $entityId, $termsArray ); |
|
48
|
|
|
|
|
49
|
|
|
$this->assertFalse( |
|
50
|
|
|
$termStore->hasNoTerms( $entityId ) |
|
51
|
|
|
); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function testHasNoTermsReturnsTrueWhenTermsNeverBeenSet() { |
|
55
|
|
|
list( $entityId, $termsArray ) = $this->getEntityIdAndTermsArray(); |
|
|
|
|
|
|
56
|
|
|
$termStore = new InMemoryEntityTermStore(); |
|
57
|
|
|
|
|
58
|
|
|
$this->assertTrue( |
|
59
|
|
|
$termStore->hasNoTerms( $entityId ) |
|
60
|
|
|
); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function testHasNoTermsReturnsTrueWhenTermsHaveBeenUnset() { |
|
64
|
|
|
list( $entityId, $termsArray ) = $this->getEntityIdAndTermsArray(); |
|
65
|
|
|
$termStore = new InMemoryEntityTermStore(); |
|
66
|
|
|
|
|
67
|
|
|
$termStore->setTerms( $entityId, $termsArray ); |
|
68
|
|
|
$termStore->unsetTerms( $entityId ); |
|
69
|
|
|
|
|
70
|
|
|
$this->assertTrue( |
|
71
|
|
|
$termStore->hasNoTerms( $entityId ) |
|
72
|
|
|
); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
private function getEntityIdAndTermsArray(): array { |
|
76
|
|
|
return [ |
|
77
|
|
|
new ItemId( 'Q123' ), |
|
78
|
|
|
[ |
|
79
|
|
|
'label' => [ |
|
80
|
|
|
'en' => 'some label', |
|
81
|
|
|
'de' => 'another label', |
|
82
|
|
|
], |
|
83
|
|
|
'alias' => [ |
|
84
|
|
|
'en' => [ 'alias', 'another alias' ], |
|
85
|
|
|
'de' => 'de alias' |
|
86
|
|
|
] |
|
87
|
|
|
] |
|
88
|
|
|
]; |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
This checks looks for assignemnts to variables using the
list(...)function, where not all assigned variables are subsequently used.Consider the following code example.
Only the variables
$aand$care used. There was no need to assign$b.Instead, the list call could have been.