Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "EventListenerRegistry.php: Call to a member function getArticleID() on null" #2692

Merged
merged 1 commit into from Sep 23, 2017
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+87 −15
Diff settings

Always

Just for now

@@ -3,6 +3,7 @@
namespace SMW;
use ObjectCache;
use Title;
use Onoi\Cache\CacheFactory as OnoiCacheFactory;
use RuntimeException;
@@ -46,30 +47,40 @@ public function getMainCacheType() {
*
* @return string
*/
public function getCachePrefix() {
public static function getCachePrefix() {
return $GLOBALS['wgCachePrefix'] === false ? wfWikiID() : $GLOBALS['wgCachePrefix'];
}
/**
* @since 2.2
*
* @param string $key
* @param Title|integer|string $key
*
* @return string
*/
public function getFactboxCacheKey( $key ) {
return $this->getCachePrefix() . ':smw:fc:' . md5( $key );
public static function getFactboxCacheKey( $key ) {
if ( $key instanceof Title ) {
$key = $key->getArticleID();
}
return self::getCachePrefix() . ':smw:fc:' . md5( $key );
}
/**
* @since 2.2
*
* @param string $key
* @param Title|integer|string $key
*
* @return string
*/
public function getPurgeCacheKey( $key ) {
return $this->getCachePrefix() . ':smw:arc:' . md5( $key );
public static function getPurgeCacheKey( $key ) {
if ( $key instanceof Title ) {
$key = $key->getArticleID();
}
return self::getCachePrefix() . ':smw:arc:' . md5( $key );
}
/**
@@ -47,14 +47,14 @@ private function addListenersToCollection() {
if ( $dispatchContext->has( 'subject' ) ) {
$title = $dispatchContext->get( 'subject' )->getTitle();
} else{
} else {
$title = $dispatchContext->get( 'title' );
}
$applicationFactory = ApplicationFactory::getInstance();
$applicationFactory->getCache()->delete(
$applicationFactory->newCacheFactory()->getFactboxCacheKey( $title->getArticleID() )
$applicationFactory->newCacheFactory()->getFactboxCacheKey( $title )
);
}
);
@@ -52,6 +52,42 @@ public function testGetCachePrefix() {
);
}
public function testGetFactboxCacheKey() {
$title = $this->getMockBuilder( '\Title' )
->disableOriginalConstructor()
->getMock();
$title->expects( $this->once() )
->method( 'getArticleID' )
->will( $this->returnValue( 42 ) );
$instance = new CacheFactory( 'hash' );
$this->assertInternalType(
'string',
$instance->getFactboxCacheKey( $title )
);
}
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' );
@@ -19,9 +19,11 @@
class EventListenerRegistryTest extends \PHPUnit_Framework_TestCase {
private $testEnvironment;
private $eventDispatcherFactory;
protected function setUp() {
$this->testEnvironment = new TestEnvironment();
$this->eventDispatcherFactory = EventDispatcherFactory::getInstance();
}
protected function tearDown() {
@@ -35,7 +37,7 @@ public function testCanConstruct() {
->getMock();
$this->assertInstanceOf(
'\SMW\EventListenerRegistry',
EventListenerRegistry::class,
new EventListenerRegistry( $eventListenerCollection )
);
}
@@ -61,11 +63,12 @@ public function testListenerCollection() {
public function testCanExecuteRegisteredListeners() {
$instance = new EventListenerRegistry(
EventDispatcherFactory::getInstance()->newGenericEventListenerCollection()
$this->eventDispatcherFactory->newGenericEventListenerCollection()
);
$this->verifyExporterResetEvent( $instance );
$this->verifyFactboxCacheDeleteEvent( $instance );
$this->verifyFactboxCacheDeleteEventOnEmpty( $instance );
$this->verifyCachedPropertyValuesPrefetcherResetEvent( $instance );
$this->verifyCachedPrefetcherResetEvent( $instance );
$this->verifyCachedUpdateMarkerDeleteEvent( $instance );
@@ -95,7 +98,7 @@ public function verifyFactboxCacheDeleteEvent( EventListenerCollection $instance
$this->testEnvironment->registerObject( 'Cache', $cache );
$dispatchContext = EventDispatcherFactory::getInstance()->newDispatchContext();
$dispatchContext = $this->eventDispatcherFactory->newDispatchContext();
$dispatchContext->set(
'title',
@@ -109,9 +112,31 @@ public function verifyFactboxCacheDeleteEvent( EventListenerCollection $instance
);
}
public function verifyFactboxCacheDeleteEventOnEmpty( EventListenerCollection $instance ) {
$cache = $this->getMockBuilder( '\Onoi\Cache\Cache' )
->disableOriginalConstructor()
->getMock();
$this->testEnvironment->registerObject( 'Cache', $cache );
$dispatchContext = $this->eventDispatcherFactory->newDispatchContext();
$dispatchContext->set(
'title',
''
);
$this->assertListenerExecuteFor(
'factbox.cache.delete',
$instance,
$dispatchContext
);
}
public function verifyCachedPropertyValuesPrefetcherResetEvent( EventListenerCollection $instance ) {
$dispatchContext = EventDispatcherFactory::getInstance()->newDispatchContext();
$dispatchContext = $this->eventDispatcherFactory->newDispatchContext();
$title = $this->getMockBuilder( '\Title' )
->disableOriginalConstructor()
@@ -135,7 +160,7 @@ public function verifyCachedPropertyValuesPrefetcherResetEvent( EventListenerCol
public function verifyCachedPrefetcherResetEvent( EventListenerCollection $instance ) {
$dispatchContext = EventDispatcherFactory::getInstance()->newDispatchContext();
$dispatchContext = $this->eventDispatcherFactory->newDispatchContext();
$title = $this->getMockBuilder( '\Title' )
->disableOriginalConstructor()
@@ -159,7 +184,7 @@ public function verifyCachedPrefetcherResetEvent( EventListenerCollection $insta
public function verifyCachedUpdateMarkerDeleteEvent( EventListenerCollection $instance ) {
$dispatchContext = EventDispatcherFactory::getInstance()->newDispatchContext();
$dispatchContext = $this->eventDispatcherFactory->newDispatchContext();
$subject = $this->getMockBuilder( '\SMW\DIWikiPage' )
->disableOriginalConstructor()
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.