2016-12-20 21:54:47 +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
|
|
|
|
*/
|
2017-07-06 18:16:05 +00:00
|
|
|
|
2023-11-29 12:39:47 +00:00
|
|
|
use MediaWiki\User\Options\UserOptionsLookup;
|
2020-01-26 19:22:03 +00:00
|
|
|
use Popups\PopupsContext;
|
|
|
|
use Popups\PopupsGadgetsIntegration;
|
2016-12-20 21:54:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create an initializable Popups context.
|
|
|
|
* It's bit dirty approach but we do not have a DependencyInject/ServiceLocator for extension
|
|
|
|
* modules and we don't want to put tests-related logic inside real classes.
|
|
|
|
*
|
|
|
|
* This wrapper extends PopupsContext and allows to Initialize context by creating new instance
|
|
|
|
* and allows to override/reset cached static PopupsContext instance.
|
|
|
|
*
|
|
|
|
* Used for testing only
|
|
|
|
* @codeCoverageIgnore
|
|
|
|
*/
|
|
|
|
class PopupsContextTestWrapper extends PopupsContext {
|
|
|
|
|
|
|
|
/**
|
2017-01-11 21:52:07 +00:00
|
|
|
* Override constructor so we can create new instances for testing.
|
2017-01-04 16:33:40 +00:00
|
|
|
*
|
2017-07-12 20:16:55 +00:00
|
|
|
* @param Config $config MediaWiki config
|
|
|
|
* @param ExtensionRegistry $extensionRegistry MediaWiki extension registry
|
|
|
|
* @param PopupsGadgetsIntegration|null $gadgetsIntegration Gadgets integration helper
|
2021-06-06 13:07:08 +00:00
|
|
|
* @param UserOptionsLookup $userOptionsLookup
|
2016-12-20 21:54:47 +00:00
|
|
|
*/
|
2021-06-06 13:07:08 +00:00
|
|
|
public function __construct(
|
|
|
|
Config $config,
|
|
|
|
ExtensionRegistry $extensionRegistry,
|
|
|
|
PopupsGadgetsIntegration $gadgetsIntegration,
|
|
|
|
UserOptionsLookup $userOptionsLookup
|
|
|
|
) {
|
2019-01-16 14:31:11 +00:00
|
|
|
$gadgetsIntegration = $gadgetsIntegration ?:
|
2017-01-11 21:52:07 +00:00
|
|
|
new PopupsGadgetsIntegration( $config, $extensionRegistry );
|
2017-01-04 16:33:40 +00:00
|
|
|
|
2021-06-06 13:07:08 +00:00
|
|
|
parent::__construct(
|
|
|
|
$config,
|
|
|
|
$extensionRegistry,
|
|
|
|
$gadgetsIntegration,
|
|
|
|
$userOptionsLookup
|
|
|
|
);
|
2016-12-20 21:54:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allow to reset cached instance
|
|
|
|
*/
|
|
|
|
public static function resetTestInstance() {
|
|
|
|
self::$instance = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Override cached instance
|
|
|
|
*
|
2017-07-12 20:16:55 +00:00
|
|
|
* @param PopupsContext $testInstance PopupsContext/Mock class to test
|
2016-12-20 21:54:47 +00:00
|
|
|
*/
|
|
|
|
public static function injectTestInstance( PopupsContext $testInstance ) {
|
|
|
|
self::$instance = $testInstance;
|
|
|
|
}
|
2019-02-26 10:55:57 +00:00
|
|
|
|
2016-12-20 21:54:47 +00:00
|
|
|
}
|