|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Wikibase\EntityStore\Cache; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Common\Cache\ArrayCache; |
|
6
|
|
|
use Wikibase\DataModel\Entity\ItemId; |
|
7
|
|
|
use Wikibase\DataModel\Term\Term; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @covers Wikibase\EntityStore\Cache\EntityIdForTermCache |
|
11
|
|
|
* |
|
12
|
|
|
* @licence GPLv2+ |
|
13
|
|
|
* @author Thomas Pellissier Tanon |
|
14
|
|
|
*/ |
|
15
|
|
|
class EntityIdForTermCacheTest extends \PHPUnit_Framework_TestCase { |
|
16
|
|
|
|
|
17
|
|
|
public function testFetch() { |
|
18
|
|
|
$cache = new EntityIdForTermCache( new ArrayCache() ); |
|
19
|
|
|
$cache->save( new Term( 'en', 'foo' ), 'item', [ new ItemId( 'Q42' ) ] ); |
|
20
|
|
|
|
|
21
|
|
|
$this->assertEquals( [ new ItemId( 'Q42' ) ], $cache->fetch( new Term( 'en', 'foo' ), 'item' ) ); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function testFetchWithException() { |
|
25
|
|
|
$this->setExpectedException( '\OutOfBoundsException' ); |
|
26
|
|
|
|
|
27
|
|
|
$cache = new EntityIdForTermCache( new ArrayCache() ); |
|
28
|
|
|
$cache->fetch( new Term( 'en', 'foo' ), 'item' ); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function testContainsTrue() { |
|
32
|
|
|
$cache = new EntityIdForTermCache( new ArrayCache() ); |
|
33
|
|
|
$cache->save( new Term( 'en', 'foo' ), 'item', [ new ItemId( 'Q42' ) ] ); |
|
34
|
|
|
|
|
35
|
|
|
$this->assertTrue( $cache->contains( new Term( 'en', 'foo' ), 'item' ) ); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testContainsFalse() { |
|
39
|
|
|
$cache = new EntityIdForTermCache( new ArrayCache() ); |
|
40
|
|
|
|
|
41
|
|
|
$this->assertFalse( $cache->contains( new Term( 'en', 'foo' ), 'item' ) ); |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
|