Jeroen De Dauw has submitted this change and it was merged.
Change subject: (Bug 56872) \SMW\BaseTemplateToolbox encode Title
......................................................................
(Bug 56872) \SMW\BaseTemplateToolbox encode Title
Change-Id: Ife1a4864ad568b25afa49c527f6047e0ba0f9b17
---
M includes/hooks/BaseTemplateToolbox.php
A tests/phpunit/integration/EncodingIntegrationTest.php
2 files changed, 104 insertions(+), 1 deletion(-)
Approvals:
Jeroen De Dauw: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/hooks/BaseTemplateToolbox.php
b/includes/hooks/BaseTemplateToolbox.php
index 666fa43..eae9cd2 100644
--- a/includes/hooks/BaseTemplateToolbox.php
+++ b/includes/hooks/BaseTemplateToolbox.php
@@ -2,6 +2,7 @@
namespace SMW;
+use SMWInfolink as Infolink;
use Title;
/**
@@ -67,11 +68,19 @@
$this->toolbox['smw-browse'] = array(
'text' =>
$this->skinTemplate->getSkin()->getContext()->msg( 'smw_browselink' )->text(),
- 'href' => \SpecialPage::getTitleFor( 'Browse',
$this->skinTemplate->getSkin()->getTitle() )->getLocalUrl(),
+ 'href' => \SpecialPage::getTitleFor( 'Browse',
$this->encodeTitle() )->getLocalUrl(),
'id' => 't-smwbrowselink',
'rel' => 'smw-browse'
);
return true;
}
+
+ /**
+ * @since 1.9
+ */
+ private function encodeTitle() {
+ return Infolink::encodeParameters( array(
$this->skinTemplate->getSkin()->getTitle()->getPrefixedDBkey() ), true );
+ }
+
}
diff --git a/tests/phpunit/integration/EncodingIntegrationTest.php
b/tests/phpunit/integration/EncodingIntegrationTest.php
new file mode 100644
index 0000000..69e40a6
--- /dev/null
+++ b/tests/phpunit/integration/EncodingIntegrationTest.php
@@ -0,0 +1,94 @@
+<?php
+
+namespace SMW\Test;
+
+use SMW\BaseTemplateToolbox;
+use SMW\ExtensionContext;
+
+/**
+ * @covers \SMW\BaseTemplateToolbox
+ * @covers \SMWInfolink
+ *
+ * @ingroup Test
+ *
+ * @group SMW
+ * @group SMWExtension
+ *
+ * @licence GNU GPL v2+
+ * @since 1.9
+ *
+ * @author mwjames
+ */
+class EncodingIntegrationTest extends SemanticMediaWikiTestCase {
+
+ /**
+ * @return string|false
+ */
+ public function getClass() {
+ return false;
+ }
+
+ /**
+ * @dataProvider baseTemplateToolboxDataProvider
+ *
+ * @since 1.9
+ */
+ public function testBaseTemplateToolboxURLEncoding( $setup, $expected )
{
+
+ $toolbox = '';
+
+ $context = new ExtensionContext();
+
$context->getDependencyBuilder()->getContainer()->registerObject( 'Settings',
$this->newSettings( $setup['settings'] ) );
+
+ $instance = new BaseTemplateToolbox( $setup['skinTemplate'],
$toolbox );
+ $instance->invokeContext( $context );
+
+ $instance->process();
+
+ $this->assertContains(
+ $expected,
+ $toolbox['smw-browse']['href'],
+ 'Asserts that process() returns an encoded URL'
+ );
+
+ }
+
+ /**
+ * @return array
+ */
+ public function baseTemplateToolboxDataProvider() {
+
+ $provider = array();
+
+ $provider[] = array( $this->newBaseTemplateToolboxSetup(
'2013/11/05' ), 'Special:Browse/2013-2F11-2F05' );
+ $provider[] = array( $this->newBaseTemplateToolboxSetup(
'2013-06-30' ), 'Special:Browse/2013-2D06-2D30' );
+ $provider[] = array( $this->newBaseTemplateToolboxSetup(
'2013$06&30' ), 'Special:Browse/2013-2406-2630' );
+
+ return $provider;
+ }
+
+ /**
+ * @return array
+ */
+ private function newBaseTemplateToolboxSetup( $text ) {
+
+ $settings = array(
+ 'smwgNamespacesWithSemanticLinks' => array( NS_MAIN =>
true ),
+ 'smwgToolboxBrowseLink' => true
+ );
+
+ $mockSkin = $this->newMockBuilder()->newObject( 'Skin', array(
+ 'getTitle' => $this->newTitle( NS_MAIN, $text ),
+ 'getContext' => $this->newContext()
+ ) );
+
+ $mockSkinTemplate = $this->newMockBuilder()->newObject(
'SkinTemplate', array(
+ 'getSkin' => $mockSkin,
+ ) );
+
+ $mockSkinTemplate->data['isarticle'] = true;
+
+ return array( 'settings' => $settings, 'skinTemplate' =>
$mockSkinTemplate );
+ }
+
+}
--
To view, visit https://gerrit.wikimedia.org/r/94629
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ife1a4864ad568b25afa49c527f6047e0ba0f9b17
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SemanticMediaWiki
Gerrit-Branch: master
Gerrit-Owner: Mwjames <[email protected]>
Gerrit-Reviewer: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits