Ladsgroup has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/345515 )
Change subject: Introduce LexemeTemplateFactory and templates.php file
......................................................................
Introduce LexemeTemplateFactory and templates.php file
It's very simple and doesn't have anything in it
Change-Id: Ie743670e99891d487e5d48eb0aef618ac0e14e33
Depends-On: I6379bdcca1a837aec457cc4e71da1b2bdde81a80
Bug: T161789
---
A resources/templates.php
A src/View/Template/LexemeTemplateFactory.php
A tests/phpunit/mediawiki/View/Template/LexemeTemplateFactoryTest.php
3 files changed, 102 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseLexeme
refs/changes/15/345515/1
diff --git a/resources/templates.php b/resources/templates.php
new file mode 100644
index 0000000..b99fad7
--- /dev/null
+++ b/resources/templates.php
@@ -0,0 +1,18 @@
+<?php
+
+namespace Wikibase\Lexeme;
+
+/**
+ * Contains templates of lexemes commonly used in server-side output
generation and client-side
+ * JavaScript processing.
+ *
+ * @license GPL-2.0+
+ *
+ * @return array
+ */
+
+return call_user_func( function() {
+ $templates = [];
+
+ return $templates;
+} );
diff --git a/src/View/Template/LexemeTemplateFactory.php
b/src/View/Template/LexemeTemplateFactory.php
new file mode 100644
index 0000000..99c8c1e
--- /dev/null
+++ b/src/View/Template/LexemeTemplateFactory.php
@@ -0,0 +1,24 @@
+<?php
+
+namespace Wikibase\Lexeme\View\Template;
+
+use Wikibase\View\Template\TemplateFactory;
+use Wikibase\View\Template\TemplateRegistry;
+
+/**
+ * @license GPL-2.0+
+ * @author Amir Sarabadani <[email protected]>
+ */
+class LexemeTemplateFactory extends TemplateFactory {
+
+ public static function getDefaultInstance() {
+ if ( self::$instance === null ) {
+ self::$instance = new self(
+ new TemplateRegistry( include __DIR__ .
'/../../../resources/templates.php' )
+ );
+ }
+
+ return self::$instance;
+ }
+
+}
diff --git
a/tests/phpunit/mediawiki/View/Template/LexemeTemplateFactoryTest.php
b/tests/phpunit/mediawiki/View/Template/LexemeTemplateFactoryTest.php
new file mode 100644
index 0000000..6d348d0
--- /dev/null
+++ b/tests/phpunit/mediawiki/View/Template/LexemeTemplateFactoryTest.php
@@ -0,0 +1,60 @@
+<?php
+
+namespace Wikibase\Lexeme\Tests\Mediawiki\View\Template;
+
+use PHPUnit_Framework_TestCase;
+use Wikibase\Lexeme\View\Template\LexemeTemplateFactory;
+use Wikibase\View\Template\TemplateFactory;
+use Wikibase\View\Template\TemplateRegistry;
+
+/**
+ * @covers Wikibase\Lexeme\View\Template\LexemeTemplateFactory
+ *
+ * @group Wikibase
+ * @group WikibaseView
+ * @group WikibaseLexeme
+ *
+ * @license GPL-2.0+
+ * @author Amir Sarabadani <[email protected]>
+ */
+class TemplateFactoryTest extends PHPUnit_Framework_TestCase {
+
+ private function newInstance() {
+ return new LexemeTemplateFactory( new TemplateRegistry( [
'basic' => '$1' ] ) );
+ }
+
+ public function testGetDefaultInstance() {
+ $instance = TemplateFactory::getDefaultInstance();
+ $this->assertInstanceOf( LexemeTemplateFactory::class,
$instance );
+ }
+
+ public function testGetTemplates() {
+ $templates = $this->newInstance()->getTemplates();
+ $this->assertSame( [ 'basic' => '$1' ], $templates );
+ }
+
+ public function testGet() {
+ $template = $this->newInstance()->get( 'basic', [ '<PARAM>' ] );
+ $this->assertSame( 'basic', $template->getKey() );
+ $this->assertSame( [ '<PARAM>' ], $template->getParams() );
+ $this->assertSame( '<PARAM>', $template->plain() );
+ }
+
+ /**
+ * @dataProvider renderParamsProvider
+ */
+ public function testRender( $params, $expected ) {
+ $rendered = $this->newInstance()->render( 'basic', $params );
+ $this->assertSame( $expected, $rendered );
+ }
+
+ public function renderParamsProvider() {
+ return [
+ [ '<PARAM>', '<PARAM>' ],
+ [ [], '$1' ],
+ [ [ '<PARAM>' ], '<PARAM>' ],
+ [ [ '<PARAM>', 'ignored' ], '<PARAM>' ],
+ ];
+ }
+
+}
--
To view, visit https://gerrit.wikimedia.org/r/345515
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie743670e99891d487e5d48eb0aef618ac0e14e33
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikibaseLexeme
Gerrit-Branch: master
Gerrit-Owner: Ladsgroup <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits