summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/CacheFactoryTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/CacheFactoryTest.php')
-rw-r--r--www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/CacheFactoryTest.php170
1 files changed, 170 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/CacheFactoryTest.php b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/CacheFactoryTest.php
new file mode 100644
index 00000000..93021425
--- /dev/null
+++ b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/CacheFactoryTest.php
@@ -0,0 +1,170 @@
+<?php
+
+namespace SMW\Tests;
+
+use Onoi\Cache\Cache;
+use Onoi\Cache\NullCache;
+use SMW\CacheFactory;
+
+/**
+ * @covers \SMW\CacheFactory
+ * @group semantic-mediawiki
+ *
+ * @license GNU GPL v2+
+ * @since 2.2
+ *
+ * @author mwjames
+ */
+class CacheFactoryTest extends \PHPUnit_Framework_TestCase {
+
+ use PHPUnitCompat;
+
+ public function testCanConstruct() {
+
+ $this->assertInstanceOf(
+ '\SMW\CacheFactory',
+ new CacheFactory( 'hash' )
+ );
+ }
+
+ public function testGetMainCacheType() {
+
+ $instance = new CacheFactory( 'hash' );
+
+ $this->assertEquals(
+ 'hash',
+ $instance->getMainCacheType()
+ );
+
+ $instance = new CacheFactory( CACHE_NONE );
+
+ $this->assertEquals(
+ CACHE_NONE,
+ $instance->getMainCacheType()
+ );
+ }
+
+ public function testGetCachePrefix() {
+
+ $instance = new CacheFactory( 'hash' );
+
+ $this->assertInternalType(
+ 'string',
+ $instance->getCachePrefix()
+ );
+ }
+
+ public function testGetPurgeCacheKey() {
+
+ $title = $this->getMockBuilder( '\Title' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $title->expects( $this->once() )
+ ->method( 'getArticleID' )
+ ->will( $this->returnValue( 42 ) );
+
+ $instance = new CacheFactory( 'hash' );
+
+ $this->assertInternalType(
+ 'string',
+ $instance->getPurgeCacheKey( $title )
+ );
+ }
+
+ public function testCanConstructCacheOptions() {
+
+ $instance = new CacheFactory( 'hash' );
+
+ $cacheOptions = $instance->newCacheOptions( [
+ 'useCache' => true,
+ 'ttl' => 0
+ ] );
+
+ $this->assertTrue(
+ $cacheOptions->useCache
+ );
+ }
+
+ public function testIncompleteCacheOptionsThrowsException() {
+
+ $instance = new CacheFactory( 'hash' );
+
+ $this->setExpectedException( 'RuntimeException' );
+
+ $cacheOptions = $instance->newCacheOptions( [
+ 'useCache' => true
+ ] );
+ }
+
+ public function testCanConstructFixedInMemoryCache() {
+
+ $instance = new CacheFactory( 'hash' );
+
+ $this->assertInstanceOf(
+ 'Onoi\Cache\Cache',
+ $instance->newFixedInMemoryCache()
+ );
+ }
+
+ public function testCanConstructNullCache() {
+
+ $instance = new CacheFactory( 'hash' );
+
+ $this->assertInstanceOf(
+ 'Onoi\Cache\Cache',
+ $instance->newNullCache()
+ );
+ }
+
+ public function testCanConstructMediaWikiCompositeCache() {
+
+ $instance = new CacheFactory( 'hash' );
+
+ $this->assertInstanceOf(
+ 'Onoi\Cache\Cache',
+ $instance->newMediaWikiCompositeCache( CACHE_NONE )
+ );
+
+ $this->assertInstanceOf(
+ 'Onoi\Cache\Cache',
+ $instance->newMediaWikiCompositeCache( $instance->getMainCacheType() )
+ );
+ }
+
+ public function testCanConstructMediaWikiCache() {
+
+ $instance = new CacheFactory();
+
+ $this->assertInstanceOf(
+ Cache::class,
+ $instance->newMediaWikiCache( 'hash' )
+ );
+ }
+
+ public function testCanConstructCacheByType() {
+
+ $instance = new CacheFactory();
+
+ $this->assertInstanceOf(
+ NullCache::class,
+ $instance->newCacheByType( CACHE_NONE )
+ );
+
+ $this->assertInstanceOf(
+ Cache::class,
+ $instance->newCacheByType( 'hash' )
+ );
+ }
+
+ public function testCanConstructBlobStore() {
+
+ $instance = new CacheFactory( 'hash' );
+
+ $this->assertInstanceOf(
+ 'Onoi\BlobStore\BlobStore',
+ $instance->newBlobStore( 'foo', CACHE_NONE )
+ );
+ }
+
+}