Jonas Kress (WMDE) has submitted this change and it was merged. ( 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 Bug: T161789 Change-Id: Ie743670e99891d487e5d48eb0aef618ac0e14e33 --- A resources/templates.php A src/View/Template/LexemeTemplateFactory.php A tests/phpunit/mediawiki/View/Template/LexemeTemplateFactoryTest.php 3 files changed, 106 insertions(+), 0 deletions(-) Approvals: Daniel Kinzler: Looks good to me, approved Jonas Kress (WMDE): Verified 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..6ed9da5 --- /dev/null +++ b/src/View/Template/LexemeTemplateFactory.php @@ -0,0 +1,29 @@ +<?php + +namespace Wikibase\Lexeme\View\Template; + +use Wikibase\View\Template\TemplateFactory; +use Wikibase\View\Template\TemplateRegistry; + +/** + * @license GPL-2.0+ + * @author Amir Sarabadani <ladsgr...@gmail.com> + */ +class LexemeTemplateFactory extends TemplateFactory { + + /** + * @var self + */ + private static $instance; + + 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..aa988a0 --- /dev/null +++ b/tests/phpunit/mediawiki/View/Template/LexemeTemplateFactoryTest.php @@ -0,0 +1,59 @@ +<?php + +namespace Wikibase\Lexeme\Tests\Mediawiki\View\Template; + +use PHPUnit_Framework_TestCase; +use Wikibase\Lexeme\View\Template\LexemeTemplateFactory; +use Wikibase\View\Template\TemplateRegistry; + +/** + * @covers Wikibase\Lexeme\View\Template\LexemeTemplateFactory + * + * @group Wikibase + * @group WikibaseView + * @group WikibaseLexeme + * + * @license GPL-2.0+ + * @author Amir Sarabadani <ladsgr...@gmail.com> + */ +class TemplateFactoryTest extends PHPUnit_Framework_TestCase { + + private function newInstance() { + return new LexemeTemplateFactory( new TemplateRegistry( [ 'basic' => '$1' ] ) ); + } + + public function testGetDefaultInstance() { + $instance = LexemeTemplateFactory::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: merged Gerrit-Change-Id: Ie743670e99891d487e5d48eb0aef618ac0e14e33 Gerrit-PatchSet: 5 Gerrit-Project: mediawiki/extensions/WikibaseLexeme Gerrit-Branch: master Gerrit-Owner: Ladsgroup <ladsgr...@gmail.com> Gerrit-Reviewer: Aleksey Bekh-Ivanov (WMDE) <aleksey.bekh-iva...@wikimedia.de> Gerrit-Reviewer: Daniel Kinzler <daniel.kinz...@wikimedia.de> Gerrit-Reviewer: Jonas Kress (WMDE) <jonas.kr...@wikimedia.de> Gerrit-Reviewer: Ladsgroup <ladsgr...@gmail.com> Gerrit-Reviewer: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits