jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/349924 )
Change subject: New hook handler base classes ...................................................................... New hook handler base classes * Added Hook base classes ** Added reference implementations for hooks * Added new Config factory Change-Id: I6b75430ee4bdd5aa9b225dafa7dd46bedef61f40 --- M extension.json M includes/CoreHooks.php A src/Config.php A src/Hooks/BeforePageDisplay.php A src/Hooks/Hook.php A src/Hooks/LinkEnd.php A src/Hooks/LinkEnd/AddDataTitle.php A src/Hooks/LinkEnd/AddDataUserName.php A src/Hooks/LoadExtensionSchemaUpdates.php A src/Hooks/MakeGlobalVariablesScript.php A src/Hooks/PageContentSaveComplete.php A src/Hooks/ParserFirstCallInit.php A src/Hooks/SkinTemplateNavigation.php A src/Hooks/SoftwareInfo.php A src/Hooks/SoftwareInfo/AddBlueSpice.php A src/Hooks/UserCan.php A src/Hooks/UserGetRights.php A tests/phpunit/Hooks/LinkEnd/AddDataTitleTest.php A tests/phpunit/Hooks/LinkEnd/AddDataUserNameTest.php A tests/phpunit/Hooks/SoftwareInfo/AddBlueSpiceTest.php 20 files changed, 994 insertions(+), 47 deletions(-) Approvals: Pwirth: Looks good to me, approved jenkins-bot: Verified diff --git a/extension.json b/extension.json index 4149638..6b6a86c 100644 --- a/extension.json +++ b/extension.json @@ -396,9 +396,12 @@ }, "Hooks": { "SetupAfterCache": "BsCoreHooks::onSetupAfterCache", - "SoftwareInfo": "BsCoreHooks::onSoftwareInfo", + "SoftwareInfo": "BlueSpice\\Hooks\\SoftwareInfo\\AddBlueSpice::callback", "BeforePageDisplay": "BsCoreHooks::onBeforePageDisplay", - "LinkEnd": "BsCoreHooks::onLinkEnd", + "LinkEnd": [ + "BlueSpice\\Hooks\\LinkEnd\\AddDataTitle::callback", + "BlueSpice\\Hooks\\LinkEnd\\AddDataUserName::callback" + ], "LinkerMakeMediaLinkFile": "BsCoreHooks::onLinkerMakeMediaLinkFile", "ThumbnailBeforeProduceHTML": "BsCoreHooks::onThumbnailBeforeProduceHTML", "MakeGlobalVariablesScript": "BsCoreHooks::onMakeGlobalVariablesScript", @@ -431,6 +434,9 @@ }, "ConfigFiles": [] }, + "ConfigRegistry": { + "bsg": "BlueSpice\\Config::newInstance" + }, "AutoloadClasses": { "BsCore": "includes/Core.class.php", "BsCoreHooks": "includes/CoreHooks.php", diff --git a/includes/CoreHooks.php b/includes/CoreHooks.php index 7f15b3d..e53c7ac 100755 --- a/includes/CoreHooks.php +++ b/includes/CoreHooks.php @@ -53,16 +53,6 @@ return true; } - /** - * Called by Special:Version for returning information about the software - * @param Array $aSoftware: The array of software in format 'name' => 'version'. - */ - public static function onSoftwareInfo( &$aSoftware ) { - global $bsgBlueSpiceExtInfo; - $aSoftware['[http://bluespice.com/ ' . $bsgBlueSpiceExtInfo['name'] . '] ([' . SpecialPage::getTitleFor( 'SpecialCredits' )->getFullURL() . ' Credits])'] = $bsgBlueSpiceExtInfo['version']; - return true; - } - public static function setup() { HTMLForm::$typeMappings['staticimage'] = 'HTMLStaticImageFieldOverride'; HTMLForm::$typeMappings['link'] = 'HTMLInfoFieldOverride'; @@ -314,41 +304,6 @@ } return true; } - - /** - * Adds additional data to links generated by the framework. This allows us - * to add more functionality to the UI. - * @param SkinTemplate $skin - * @param Title $target - * @param array $options - * @param string $html - * @param array $attribs - * @param string $ret - * @return boolean Always true to keep hook running - */ - public static function onLinkEnd( $skin, $target, $options, &$html, &$attribs, &$ret ) { - //We add the original title to a link. This may be the same content as - //"title" attribute, but it doesn't have to. I.e. in red links - $attribs['data-bs-title'] = $target->getPrefixedText(); - - if( $target->getNamespace() == NS_USER && $target->isSubpage() === false ) { - //Linker::userLink adds class "mw-userlink" by default - /*if( !isset($attribs['class']) ) { - $attribs['class'] = ''; - } - $attribs['class'] .= ' user';*/ - if( $target->getText() == $html ) { - $html = htmlspecialchars( - BsUserHelper::getUserDisplayName( - User::newFromName( $target->getText() ) - ) - ); - $attribs['data-bs-username'] = $target->getText(); - } - } - return true; - } - /** * Adds data attributes to media link tags diff --git a/src/Config.php b/src/Config.php new file mode 100644 index 0000000..1ec57d9 --- /dev/null +++ b/src/Config.php @@ -0,0 +1,9 @@ +<?php + +namespace BlueSpice; + +class Config extends \GlobalVarConfig { + public static function newInstance() { + return new self( 'bsg' ); + } +} diff --git a/src/Hooks/BeforePageDisplay.php b/src/Hooks/BeforePageDisplay.php new file mode 100644 index 0000000..f60998d --- /dev/null +++ b/src/Hooks/BeforePageDisplay.php @@ -0,0 +1,49 @@ +<?php + +namespace BlueSpice\Hooks; + +abstract class BeforePageDisplay extends BlueSpice\Hooks\Hook { + + /** + * + * @var \OutputPage + */ + protected $out = null; + + /** + * + * @var \Skin + */ + protected $skin = null; + + /** + * + * @param \OutputPage $out + * @param \Skin $skin + * @return boolean + */ + public static function callback( $out, $skin ) { + $className = static::class; + $hookHandler = new $className( + null, + null, + $out, + $skin + ); + return $hookHandler->process(); + } + + /** + * + * @param \IContextSource $context + * @param \Config $config + * @param \OutputPage $out + * @param \Skin $skin + */ + public function __construct( $context, $config, $out, $skin ) { + parent::__construct( $context, $config ); + + $this->out = $out; + $this->skin = $skin; + } +} \ No newline at end of file diff --git a/src/Hooks/Hook.php b/src/Hooks/Hook.php new file mode 100644 index 0000000..78dc028 --- /dev/null +++ b/src/Hooks/Hook.php @@ -0,0 +1,68 @@ +<?php +namespace BlueSpice\Hooks; + +abstract class Hook { + + /** + * + * @var \IContextSource + */ + private $context = null; + + /** + * + * @var \Config + */ + private $config = null; + + + /** + * Normally both parameters are NULL on instantiation. This is because we + * perform a lazy loading out of performance reasons. But for the sake of + * testablity we keep the DI here + * @param \IContextSource $context + * @param \Config $config + */ + public function __construct( $context, $config ) { + $this->context = $context; + $this->config = $config; + } + + /** + * + * @return \IContextSource + */ + protected function getContext() { + if( $this->context instanceof \IContextSource === false ) { + $this->context = \RequestContext::getMain(); + } + return $this->context; + } + + /** + * + * @var string + */ + protected static $configName = 'main'; + + /** + * + * @return \Config + */ + protected function getConfig() { + if( $this->config instanceof \Config === false ) { + $this->config = \MediaWiki\MediaWikiServices::getInstance() + ->getConfigFactory()->makeConfig( static::$configName ); + } + + return $this->config; + } + + public function process() { + \Profiler::instance()->scopedProfileIn( "Hook ". __METHOD__ ); + $result = $this->doProcess(); + return $result; + } + + protected abstract function doProcess(); +} \ No newline at end of file diff --git a/src/Hooks/LinkEnd.php b/src/Hooks/LinkEnd.php new file mode 100644 index 0000000..87f4c6d --- /dev/null +++ b/src/Hooks/LinkEnd.php @@ -0,0 +1,90 @@ +<?php + +namespace BlueSpice\Hooks; + +abstract class LinkEnd extends Hook { + + /** + * + * @var \DummyLinker + */ + protected $dummy = null; + + /** + * + * @var \Title + */ + protected $target = null; + + /** + * + * @var array + */ + protected $options = []; + + /** + * + * @var string + */ + protected $html = ''; + + /** + * + * @var array + */ + protected $attribs = []; + + /** + * + * @var string + */ + protected $ret = ''; + + /** + * Adds additional data to links generated by the framework. This allows us + * to add more functionality to the UI. + * @param \DummyLinker $dummy + * @param \Title $target + * @param array $options + * @param string $html + * @param array $attribs + * @param string $ret + * @return boolean Always true to keep hook running + */ + public static function callback( \DummyLinker $dummy, \Title $target, $options, &$html, &$attribs, &$ret ) { + $className = static::class; + $hookHandler = new $className( + null, + null, + $dummy, + $target, + $options, + $html, + $attribs, + $ret + ); + return $hookHandler->process(); + } + + /** + * + * @param \IContextSource $context + * @param \Config $config + * @param \DummyLinker $dummy + * @param \Title $target + * @param array $options + * @param string $html + * @param array $attribs + * @param string $ret + */ + public function __construct( $context, $config, \DummyLinker $dummy, \Title $target, $options, &$html, &$attribs, &$ret ) { + parent::__construct( $context, $config ); + + $this->dummy =& $dummy; + $this->target = $target; + $this->options = $options; + $this->html =& $html; + $this->attribs =& $attribs; + $this->ret =& $ret; + } +} \ No newline at end of file diff --git a/src/Hooks/LinkEnd/AddDataTitle.php b/src/Hooks/LinkEnd/AddDataTitle.php new file mode 100644 index 0000000..9294a33 --- /dev/null +++ b/src/Hooks/LinkEnd/AddDataTitle.php @@ -0,0 +1,12 @@ +<?php + +namespace BlueSpice\Hooks\LinkEnd; + +class AddDataTitle extends \BlueSpice\Hooks\LinkEnd { + protected function doProcess() { + //We add the original title to a link. This may be the same content as + //"title" attribute, but it doesn't have to. I.e. in red links + $this->attribs['data-bs-title'] = $this->target->getPrefixedDBkey(); + return true; + } +} \ No newline at end of file diff --git a/src/Hooks/LinkEnd/AddDataUserName.php b/src/Hooks/LinkEnd/AddDataUserName.php new file mode 100644 index 0000000..496268d --- /dev/null +++ b/src/Hooks/LinkEnd/AddDataUserName.php @@ -0,0 +1,21 @@ +<?php + +namespace BlueSpice\Hooks\LinkEnd; + +class AddDataUserName extends \BlueSpice\Hooks\LinkEnd { + protected function doProcess() { + if( $this->target->getNamespace() !== NS_USER || $this->target->isSubpage() ) { + return true; + } + + $user = \User::newFromName( $this->target->getText() ); + + if( $this->target->getText() === $this->html ) { + $this->html = htmlspecialchars( + \BsCore::getUserDisplayName( $user ) + ); + } + + $this->attribs['data-bs-username'] = $user->getName(); + } +} \ No newline at end of file diff --git a/src/Hooks/LoadExtensionSchemaUpdates.php b/src/Hooks/LoadExtensionSchemaUpdates.php new file mode 100644 index 0000000..57009f6 --- /dev/null +++ b/src/Hooks/LoadExtensionSchemaUpdates.php @@ -0,0 +1,39 @@ +<?php + +namespace BlueSpice\Hooks; + +abstract class LoadExtensionSchemaUpdates extends Hook { + + /** + * + * @var \DatabaseUpdater + */ + protected $updater = null; + + /** + * + * @param \DatabaseUpdater $updater + * @return boolean + */ + public static function callback( $updater ) { + $className = static::class; + $hookHandler = new $className( + null, + null, + $updater + ); + return $hookHandler->process(); + } + + /** + * + * @param \IContextSource $context + * @param \Config $config + * @param \DatabaseUpdater $updater + */ + public function __construct( $context, $config, $updater ) { + parent::__construct( $context, $config ); + + $this->updater = $updater; + } +} \ No newline at end of file diff --git a/src/Hooks/MakeGlobalVariablesScript.php b/src/Hooks/MakeGlobalVariablesScript.php new file mode 100644 index 0000000..908551e --- /dev/null +++ b/src/Hooks/MakeGlobalVariablesScript.php @@ -0,0 +1,41 @@ +<?php + +namespace BlueSpice\Hooks; + +abstract class MakeGlobalVariablesScript extends Hook { + + /** + * + * @var array + */ + protected $vars = []; + + /** + * + * @var \OutputPage + */ + protected $out = null; + /** + * + * @param array$vars + * @param \OutputPage $out + * @return boolean + */ + public static function callback( &$vars, $out ) { + $className = static::class; + $hookHandler = new $className( + null, + null, + $vars, + $out + ); + return $hookHandler->process(); + } + + public function __construct( $context, $config, &$vars, $out ) { + parent::__construct( $context, $config ); + + $this->vars =& $vars; + $this->out = $out; + } +} \ No newline at end of file diff --git a/src/Hooks/PageContentSaveComplete.php b/src/Hooks/PageContentSaveComplete.php new file mode 100644 index 0000000..e6aa230 --- /dev/null +++ b/src/Hooks/PageContentSaveComplete.php @@ -0,0 +1,138 @@ +<?php + +namespace BlueSpice\Hooks; + +abstract class PageContentSaveComplete extends Hook { + + /** + * + * @var \WikiPage + */ + protected $wikipage = null; + + /** + * + * @var \User + */ + protected $user = null; + + /** + * + * @var \Content + */ + protected $content = null; + + /** + * + * @var string + */ + protected $summary = ''; + + /** + * + * @var boolean + */ + protected $isMinor = false; + + /** + * + * @var boolean + */ + protected $isWatch = false; + + /** + * + * @var int + */ + protected $section = 0; + + /** + * + * @var int + */ + protected $flags = 0; + + /** + * + * @var \Revision + */ + protected $revision = null; + + /** + * + * @var \Status + */ + protected $status = null; + + /** + * + * @var int + */ + protected $baseRevId = 0; + + /** + * + * @param \WikiPage $wikipage + * @param \User $user + * @param \Content $content + * @param string $summary + * @param boolean $isMinor + * @param boolean $isWatch + * @param section $section + * @param int $flags + * @param \Revision $revision + * @param \Status $status + * @param int $baseRevId + * @return boolean + */ + public static function callback( $wikipage, $user, $content, $summary, $isMinor, $isWatch, $section, $flags, $revision, $status, $baseRevId ) { + $className = static::class; + $hookHandler = new $className( + null, + null, + $wikipage, + $user, + $content, + $summary, + $isMinor, + $isWatch, + $section, + $flags, + $revision, + $status, + $baseRevId + ); + return $hookHandler->process(); + } + + /** + * + * @param \IContextSource $context + * @param \Context $config + * @param \WikiPage $wikipage + * @param \User $user + * @param \Content $content + * @param string $summary + * @param boolean $isMinor + * @param boolean $isWatch + * @param section $section + * @param int $flags + * @param \Revision $revision + * @param \Status $status + * @param int $baseRevId + */ + public function __construct( $context, $config, $wikipage, $user, $content, $summary, $isMinor, $isWatch, $section, $flags, $revision, $status, $baseRevId ) { + parent::__construct( $context, $config ); + + $this->wikipage = $wikipage; + $this->user = $user; + $this->content = $content; + $this->summary = $summary; + $this->isMinor = $isMinor; + $this->section = $section; + $this->flags = $flags; + $this->revision = $revision; + $this->status = $status; + $this->baseRevId = $baseRevId; + } +} \ No newline at end of file diff --git a/src/Hooks/ParserFirstCallInit.php b/src/Hooks/ParserFirstCallInit.php new file mode 100644 index 0000000..5c7ebd7 --- /dev/null +++ b/src/Hooks/ParserFirstCallInit.php @@ -0,0 +1,39 @@ +<?php + +namespace BlueSpice\Hooks; + +abstract class ParserFirstCallInit extends Hook { + + /** + * + * @var \Parser + */ + protected $parser = null; + + /** + * + * @param \Parser $parser + * @return boolean + */ + public static function callback( $parser ) { + $className = static::class; + $hookHandler = new $className( + null, + null, + $parser + ); + return $hookHandler->process(); + } + + /** + * + * @param \IContextSource $context + * @param \Config $config + * @param \Parser $parser + */ + public function __construct( $context, $config, $parser ) { + parent::__construct( $context, $config ); + + $this->parser = $parser; + } +} \ No newline at end of file diff --git a/src/Hooks/SkinTemplateNavigation.php b/src/Hooks/SkinTemplateNavigation.php new file mode 100644 index 0000000..b14cf0f --- /dev/null +++ b/src/Hooks/SkinTemplateNavigation.php @@ -0,0 +1,49 @@ +<?php + +namespace BlueSpice\Hooks; + +class SkinTemplateNavigation extends Hook { + + /** + * + * @var \SkinTemplate + */ + protected $sktemplate = null; + + /** + * + * @var array + */ + protected $links = []; + + /** + * + * @param \SkinTemplate $sktemplate + * @param array $links + * @return boolean + */ + public static function callback( &$sktemplate, &$links ) { + $className = static::class; + $hookHandler = new $className( + null, + null, + $sktemplate, + $links + ); + return $hookHandler->process(); + } + + /** + * + * @param \IContextSource $context + * @param \Config $config + * @param \SkinTemplate $sktemplate + * @param array $links + */ + public function __construct( $context, $config, &$sktemplate, &$links ) { + parent::__construct( $context, $config ); + + $this->sktemplate = $sktemplate; + $this->links = &$links; + } +} \ No newline at end of file diff --git a/src/Hooks/SoftwareInfo.php b/src/Hooks/SoftwareInfo.php new file mode 100644 index 0000000..5339e40 --- /dev/null +++ b/src/Hooks/SoftwareInfo.php @@ -0,0 +1,34 @@ +<?php + +namespace BlueSpice\Hooks; + +abstract class SoftwareInfo extends Hook { + + protected $softwareInfo = []; + + /** + * Called by Special:Version for returning information about the software + * @param array $software + * @return boolean + */ + public static function callback( &$software ) { + $className = static::class; + $hookHandler = new $className( + null, + null, + $software + ); + return $hookHandler->process(); + } + + /** + * @param \IContextSource $context + * @param \Config $config + * @param array $software + */ + public function __construct( $context, $config, &$software ) { + parent::__construct( $context, $config ); + + $this->softwareInfo =& $software; + } +} \ No newline at end of file diff --git a/src/Hooks/SoftwareInfo/AddBlueSpice.php b/src/Hooks/SoftwareInfo/AddBlueSpice.php new file mode 100644 index 0000000..de9208d --- /dev/null +++ b/src/Hooks/SoftwareInfo/AddBlueSpice.php @@ -0,0 +1,16 @@ +<?php + +namespace BlueSpice\Hooks\SoftwareInfo; + +class AddBlueSpice extends \BlueSpice\Hooks\SoftwareInfo { + + protected static $configName = 'bsg'; + + protected function doProcess() { + $extInfo = $this->getConfig()->get( 'BlueSpiceExtInfo' ); + + $this->softwareInfo['[http://bluespice.com/ ' . $extInfo['name'] . '] ([' . \SpecialPage::getTitleFor( 'SpecialCredits' )->getFullURL() . ' Credits])'] = $extInfo['version']; + return true; + } +} + diff --git a/src/Hooks/UserCan.php b/src/Hooks/UserCan.php new file mode 100644 index 0000000..14b1d53 --- /dev/null +++ b/src/Hooks/UserCan.php @@ -0,0 +1,60 @@ +<?php + +namespace BlueSpice\Hooks; + +abstract class UserCan extends Hook { + + /** + * + * @var \Title + */ + protected $title = null; + + /** + * + * @var \User + */ + protected $user = null; + + /** + * + * @var string + */ + protected $action = ''; + + /** + * + * @var boolean + */ + protected $result = false; + + /** + * + * @param \Title $title + * @param \User $user + * @param string $action + * @param boolean $result + * @return boolean + */ + public static function callback( &$title, &$user, $action, &$result ) { + $className = static::class; + $hookHandler = new $className( + null, + null, + $title, + $user, + $action, + $result + ); + return $hookHandler->process(); + } + + public function __construct( $context, $config, &$title, &$user, $action, &$result ) { + parent::__construct( $context, $config ); + + $this->title = $title; + $this->user = $user; + $this->action = $action; + $this->result =& $result; + } +} \ No newline at end of file diff --git a/src/Hooks/UserGetRights.php b/src/Hooks/UserGetRights.php new file mode 100644 index 0000000..b7e22e1 --- /dev/null +++ b/src/Hooks/UserGetRights.php @@ -0,0 +1,49 @@ +<?php + +namespace BlueSpice\Hooks; + +abstract class UserGetRights extends Hook { + + /** + * + * @var \User + */ + protected $user = null; + + /** + * + * @var array + */ + protected $rights = []; + + /** + * + * @param \User $user + * @param array $rights + * @return type + */ + public static function callback( $user, &$rights ) { + $className = static::class; + $hookHandler = new $className( + null, + null, + $user, + $rights + ); + return $hookHandler->process(); + } + + /** + * + * @param \IContextSource $context + * @param \Config $config + * @param \User $user + * @param array $rights + */ + public function __construct( $context, $config, $user, &$rights ) { + parent::__construct( $context, $config ); + + $this->user = $user; + $this->rights =& $rights; + } +} \ No newline at end of file diff --git a/tests/phpunit/Hooks/LinkEnd/AddDataTitleTest.php b/tests/phpunit/Hooks/LinkEnd/AddDataTitleTest.php new file mode 100644 index 0000000..db13497 --- /dev/null +++ b/tests/phpunit/Hooks/LinkEnd/AddDataTitleTest.php @@ -0,0 +1,71 @@ +<?php + +namespace BlueSpice\Tests\LinkEnd; + +class AddDataTitleTest extends \PHPUnit_Framework_TestCase { + + public function testCanConstruct() { + + $context = $this->getMockBuilder( '\RequestContext' ) + ->disableOriginalConstructor() + ->getMock(); + + $config = $this->getMockBuilder( '\HashConfig' ) + ->disableOriginalConstructor() + ->getMock(); + + $dummy = new \DummyLinker(); + $title = \Title::newMainPage(); + $options = []; + $html = ''; + $attribs = []; + $ret = ''; + + $this->assertInstanceOf( + '\BlueSpice\Hooks\LinkEnd\AddDataTitle', + new \BlueSpice\Hooks\LinkEnd\AddDataTitle( + $context, + $config, + $dummy, + $title, + $options, + $html, + $attribs, + $ret + ) + ); + } + + public function testProcess() { + + $context = $this->getMockBuilder( '\RequestContext' ) + ->disableOriginalConstructor() + ->getMock(); + + $config = $this->getMockBuilder( '\HashConfig' ) + ->disableOriginalConstructor() + ->getMock(); + + $dummy = new \DummyLinker(); + $title = \Title::newMainPage(); + $options = []; + $html = ''; + $attribs = []; + $ret = ''; + + $instance = new \BlueSpice\Hooks\LinkEnd\AddDataTitle( + $context, + $config, + $dummy, + $title, + $options, + $html, + $attribs, + $ret + ); + $instance->process(); + + $this->assertArrayHasKey( 'data-bs-title', $attribs ); + $this->assertEquals( $title->getPrefixedDBkey(), $attribs['data-bs-title'] ); + } +} \ No newline at end of file diff --git a/tests/phpunit/Hooks/LinkEnd/AddDataUserNameTest.php b/tests/phpunit/Hooks/LinkEnd/AddDataUserNameTest.php new file mode 100644 index 0000000..6d04197 --- /dev/null +++ b/tests/phpunit/Hooks/LinkEnd/AddDataUserNameTest.php @@ -0,0 +1,147 @@ +<?php + +namespace BlueSpice\Tests\LinkEnd; + +class AddDataUserNameTest extends \MediaWikiTestCase { + protected $testUserName = 'wiki Sysöp'; + + public function testCanConstruct() { + + $context = $this->getMockBuilder( '\RequestContext' ) + ->disableOriginalConstructor() + ->getMock(); + + $config = $this->getMockBuilder( '\HashConfig' ) + ->disableOriginalConstructor() + ->getMock(); + + $dummy = new \DummyLinker(); + $title = \Title::newMainPage(); + $options = []; + $html = ''; + $attribs = []; + $ret = ''; + + $this->assertInstanceOf( + '\BlueSpice\Hooks\LinkEnd\AddDataUserName', + new \BlueSpice\Hooks\LinkEnd\AddDataUserName( + $context, + $config, + $dummy, + $title, + $options, + $html, + $attribs, + $ret + ) + ); + } + + public function testProcessUserPageWithRename() { + $testuser = \User::newFromName( $this->testUserName ); + $testuser->addToDatabase(); + $testuser->setRealName( 'Sysöp, W. Iki' ); + $testuser->saveSettings(); + + $context = $this->getMockBuilder( '\RequestContext' ) + ->disableOriginalConstructor() + ->getMock(); + + $config = $this->getMockBuilder( '\HashConfig' ) + ->disableOriginalConstructor() + ->getMock(); + + $dummy = new \DummyLinker(); + $title = \Title::makeTitle( NS_USER, 'Wiki Sysöp' ); + $options = []; + $html = $title->getText(); + $attribs = []; + $ret = ''; + + $instance = new \BlueSpice\Hooks\LinkEnd\AddDataUserName( + $context, + $config, + $dummy, + $title, + $options, + $html, + $attribs, + $ret + ); + $instance->process(); + + $this->assertArrayHasKey( 'data-bs-username', $attribs ); + $this->assertEquals( $testuser->getName(), $attribs['data-bs-username'] ); + $this->assertEquals( $testuser->getRealName(), $html ); + } + + public function testProcessUserPageWithOutRename() { + $testuser = \User::newFromName( $this->testUserName ); + $testuser->addToDatabase(); + $testuser->setRealName( 'Sysöp, W. Iki' ); + $testuser->saveSettings(); + + $context = $this->getMockBuilder( '\RequestContext' ) + ->disableOriginalConstructor() + ->getMock(); + + $config = $this->getMockBuilder( '\HashConfig' ) + ->disableOriginalConstructor() + ->getMock(); + + $dummy = new \DummyLinker(); + $title = \Title::makeTitle( NS_USER, 'Wiki Sysöp' ); + $options = []; + $html = 'Some link text'; + $attribs = []; + $ret = ''; + + $instance = new \BlueSpice\Hooks\LinkEnd\AddDataUserName( + $context, + $config, + $dummy, + $title, + $options, + $html, + $attribs, + $ret + ); + $instance->process(); + + $this->assertArrayHasKey( 'data-bs-username', $attribs ); + $this->assertEquals( $testuser->getName(), $attribs['data-bs-username'] ); + $this->assertEquals( $html, $html ); + } + + public function testProcessNoProcess() { + $context = $this->getMockBuilder( '\RequestContext' ) + ->disableOriginalConstructor() + ->getMock(); + + $config = $this->getMockBuilder( '\HashConfig' ) + ->disableOriginalConstructor() + ->getMock(); + + $dummy = new \DummyLinker(); + $title = \Title::makeTitle( NS_MAIN, 'Not a user page' ); + $options = []; + $html = 'Some link text'; + $attribs = []; + $ret = ''; + + $instance = new \BlueSpice\Hooks\LinkEnd\AddDataUserName( + $context, + $config, + $dummy, + $title, + $options, + $html, + $attribs, + $ret + ); + $instance->process(); + + $this->assertArrayNotHasKey( 'data-bs-username', $attribs ); + $this->assertEquals( $html, $html ); + } +} \ No newline at end of file diff --git a/tests/phpunit/Hooks/SoftwareInfo/AddBlueSpiceTest.php b/tests/phpunit/Hooks/SoftwareInfo/AddBlueSpiceTest.php new file mode 100644 index 0000000..4b02a90 --- /dev/null +++ b/tests/phpunit/Hooks/SoftwareInfo/AddBlueSpiceTest.php @@ -0,0 +1,54 @@ +<?php + +namespace BlueSpice\Tests\SoftwareInfo; + +class AddBlueSpiceTest extends \PHPUnit_Framework_TestCase { + + public function testCanConstruct() { + + $context = $this->getMockBuilder( '\RequestContext' ) + ->disableOriginalConstructor() + ->getMock(); + + $config = $this->getMockBuilder( '\HashConfig' ) + ->disableOriginalConstructor() + ->getMock(); + + $software = []; + + + $this->assertInstanceOf( + '\BlueSpice\Hooks\SoftwareInfo\AddBlueSpice', + new \BlueSpice\Hooks\SoftwareInfo\AddBlueSpice( + $context, + $config, + $software + ) + ); + } + + public function testProcess() { + + $context = $this->getMockBuilder( '\RequestContext' ) + ->disableOriginalConstructor() + ->getMock(); + + $config = new \HashConfig( [ + 'BlueSpiceExtInfo' => [ + 'name' => 'BlueSpice SUPER', + 'version' => '5.9.1' + ] + ] ); + + $software = []; + + $instance = new \BlueSpice\Hooks\SoftwareInfo\AddBlueSpice( + $context, + $config, + $software + ); + $instance->process(); + + $this->assertArrayHasKey( '5.9.1', array_flip( $software ) ); + } +} \ No newline at end of file -- To view, visit https://gerrit.wikimedia.org/r/349924 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I6b75430ee4bdd5aa9b225dafa7dd46bedef61f40 Gerrit-PatchSet: 13 Gerrit-Project: mediawiki/extensions/BlueSpiceFoundation Gerrit-Branch: master Gerrit-Owner: Robert Vogel <vo...@hallowelt.biz> Gerrit-Reviewer: Legoktm <lego...@member.fsf.org> Gerrit-Reviewer: Ljonka <l.verhovs...@gmail.com> Gerrit-Reviewer: Mglaser <gla...@hallowelt.biz> Gerrit-Reviewer: Pwirth <wi...@hallowelt.biz> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits