2017-07-06 18:16:05 +00:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* This file is part of the MediaWiki extension Popups.
|
|
|
|
*
|
|
|
|
* Popups is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Popups is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Popups. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @ingroup extensions
|
|
|
|
*/
|
|
|
|
use Popups\EventLogging\MWEventLogger;
|
|
|
|
use Popups\EventLogging\NullLogger;
|
|
|
|
use Popups\EventLogging\EventLoggerFactory;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group Popups
|
2017-12-27 19:53:07 +00:00
|
|
|
* @coversDefaultClass \Popups\EventLogging\EventLoggerFactory
|
2017-07-06 18:16:05 +00:00
|
|
|
*/
|
|
|
|
class EventLoggerFactoryTest extends MediaWikiTestCase {
|
|
|
|
|
|
|
|
/**
|
2018-12-18 08:54:47 +00:00
|
|
|
* @covers ::__construct
|
2017-07-06 18:16:05 +00:00
|
|
|
* @covers ::get
|
2018-12-18 08:54:47 +00:00
|
|
|
* @covers \Popups\EventLogging\MWEventLogger::__construct
|
2017-07-06 18:16:05 +00:00
|
|
|
*/
|
|
|
|
public function testReturnsMWEventWhenEventLoggingIsAvailable() {
|
2019-10-10 15:15:31 +00:00
|
|
|
$mock = $this->createMock( ExtensionRegistry::class );
|
2017-07-06 18:16:05 +00:00
|
|
|
$mock->expects( $this->once() )
|
|
|
|
->method( 'isLoaded' )
|
|
|
|
->with( 'EventLogging' )
|
|
|
|
->willReturn( true );
|
|
|
|
|
2019-02-26 11:20:59 +00:00
|
|
|
$factory = new EventLoggerFactory( $mock );
|
2018-05-08 19:48:17 +00:00
|
|
|
$this->assertInstanceOf( MWEventLogger::class,
|
|
|
|
$factory->get(),
|
|
|
|
'A functional event logger is instantiated.' );
|
2017-07-06 18:16:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-12-18 08:54:47 +00:00
|
|
|
* @covers ::__construct
|
2017-07-06 18:16:05 +00:00
|
|
|
* @covers ::get
|
|
|
|
*/
|
|
|
|
public function testReturnsMWEventWhenEventLoggingIsNotAvailable() {
|
2019-10-10 15:15:31 +00:00
|
|
|
$mock = $this->createMock( ExtensionRegistry::class );
|
2017-07-06 18:16:05 +00:00
|
|
|
$mock->expects( $this->once() )
|
|
|
|
->method( 'isLoaded' )
|
|
|
|
->with( 'EventLogging' )
|
|
|
|
->willReturn( false );
|
|
|
|
|
2019-02-26 11:20:59 +00:00
|
|
|
$factory = new EventLoggerFactory( $mock );
|
2018-05-08 19:48:17 +00:00
|
|
|
$this->assertInstanceOf( NullLogger::class,
|
|
|
|
$factory->get(),
|
|
|
|
'A no-op event logger is instantiated.' );
|
2017-07-06 18:16:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|