| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
namespace MediaWiki\Extension\CategoryTree\Tests; |
| 22 |
|
| 23 |
use MediaWiki\Category\Category; |
| 24 |
use MediaWiki\Extension\CategoryTree\CategoryCache; |
| 25 |
use MediaWiki\Title\TitleValue; |
| 26 |
use MediaWikiIntegrationTestCase; |
| 27 |
use Wikimedia\Rdbms\IConnectionProvider; |
| 28 |
use Wikimedia\TestingAccessWrapper; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
class CategoryCacheTest extends MediaWikiIntegrationTestCase { |
| 35 |
|
| 36 |
public function testConstruct() { |
| 37 |
new CategoryCache( |
| 38 |
$this->createMock( IConnectionProvider::class ) |
| 39 |
); |
| 40 |
$this->addToAssertionCount( 1 ); |
| 41 |
} |
| 42 |
|
| 43 |
public function testDoQuery() { |
| 44 |
|
| 45 |
$this->editPage( |
| 46 |
new TitleValue( NS_MAIN, 'CategoryTreeCategoryCacheTest' ), |
| 47 |
'[[Category:Exists]]' |
| 48 |
); |
| 49 |
|
| 50 |
$categoryCache = TestingAccessWrapper::newFromObject( |
| 51 |
$this->getServiceContainer()->get( 'CategoryTree.CategoryCache' ) |
| 52 |
); |
| 53 |
|
| 54 |
$categoryCache->doQuery( [ |
| 55 |
new TitleValue( NS_CATEGORY, 'Exists' ), |
| 56 |
new TitleValue( NS_CATEGORY, 'Missed' ), |
| 57 |
] ); |
| 58 |
|
| 59 |
$this->assertCount( 2, $categoryCache->cache ); |
| 60 |
$this->assertArrayHasKey( 'Exists', $categoryCache->cache ); |
| 61 |
$this->assertInstanceOf( Category::class, $categoryCache->cache['Exists'] ); |
| 62 |
$this->assertArrayHasKey( 'Missed', $categoryCache->cache ); |
| 63 |
$this->assertNull( $categoryCache->cache['Missed'] ); |
| 64 |
} |
| 65 |
|
| 66 |
public function testGetCategory() { |
| 67 |
|
| 68 |
$this->editPage( |
| 69 |
new TitleValue( NS_MAIN, 'CategoryTreeCategoryCacheTest' ), |
| 70 |
'[[Category:Exists]]' |
| 71 |
); |
| 72 |
|
| 73 |
$categoryCache = TestingAccessWrapper::newFromObject( |
| 74 |
$this->getServiceContainer()->get( 'CategoryTree.CategoryCache' ) |
| 75 |
); |
| 76 |
$title = new TitleValue( NS_CATEGORY, 'Exists' ); |
| 77 |
|
| 78 |
|
| 79 |
$this->assertCount( 0, $categoryCache->cache ); |
| 80 |
$this->assertInstanceOf( Category::class, $categoryCache->getCategory( $title ) ); |
| 81 |
$this->assertCount( 1, $categoryCache->cache ); |
| 82 |
|
| 83 |
|
| 84 |
$this->assertInstanceOf( Category::class, $categoryCache->getCategory( $title ) ); |
| 85 |
} |
| 86 |
} |