Mailing List Archive

[MediaWiki-commits] [Gerrit] mediawiki...ArticlePlaceholder[master]: Add more test cases to improve overall test coverage
Thiemo Kreuz (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/406054 )

Change subject: Add more test cases to improve overall test coverage
......................................................................

Add more test cases to improve overall test coverage

Change-Id: I28547aa378977d1c379e7e709357d9916c511e1f
---
M tests/phpunit/includes/HooksTest.php
A tests/phpunit/includes/Lua/Scribunto_LuaArticlePlaceholderLibraryTest.php
2 files changed, 99 insertions(+), 0 deletions(-)


git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ArticlePlaceholder refs/changes/54/406054/1

diff --git a/tests/phpunit/includes/HooksTest.php b/tests/phpunit/includes/HooksTest.php
index 1e9a960..e5c9e5a 100644
--- a/tests/phpunit/includes/HooksTest.php
+++ b/tests/phpunit/includes/HooksTest.php
@@ -15,6 +15,15 @@
*/
class HooksTest extends PHPUnit_Framework_TestCase {

+ public function testOnScribuntoExternalLibraries() {
+ $instance = new Hooks();
+ $extraLibraries = [];
+ $instance->onScribuntoExternalLibraries( 'lua', $extraLibraries );
+ $this->assertCount( 1, $extraLibraries );
+ $this->assertContainsOnly( 'array', $extraLibraries );
+ $this->assertArrayHasKey( 'class', reset( $extraLibraries ) );
+ }
+
public function testRegisterScribuntoExternalLibraryPaths() {
$instance = new Hooks();
$paths = [];
diff --git a/tests/phpunit/includes/Lua/Scribunto_LuaArticlePlaceholderLibraryTest.php b/tests/phpunit/includes/Lua/Scribunto_LuaArticlePlaceholderLibraryTest.php
new file mode 100644
index 0000000..ffaec0f
--- /dev/null
+++ b/tests/phpunit/includes/Lua/Scribunto_LuaArticlePlaceholderLibraryTest.php
@@ -0,0 +1,90 @@
+<?php
+
+namespace ArticlePlaceholder\Tests\Lua;
+
+use ArticlePlaceholder\Lua\Scribunto_LuaArticlePlaceholderLibrary;
+use MediaWikiTestCase;
+use RuntimeException;
+use Scribunto_LuaEngine;
+
+/**
+ * @covers \ArticlePlaceholder\Lua\Scribunto_LuaArticlePlaceholderLibrary
+ *
+ * @group ArticlePlaceholder
+ *
+ * @license GNU GPL v2+
+ * @author Thiemo Kreuz
+ */
+class Scribunto_LuaArticlePlaceholderLibraryTest extends MediaWikiTestCase {
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->setMwGlobals( [
+ 'wgArticlePlaceholderImageProperty' => 'P2001',
+ 'wgArticlePlaceholderReferencesBlacklist' => 'P2002',
+ ] );
+ }
+
+ public function testGetImageProperty() {
+ $instance = $this->newInstance();
+
+ $actual = $instance->getImageProperty();
+ $this->assertSame( [ 'P2001' ], $actual );
+ }
+
+ public function testGetImageProperty_throwsException() {
+ $this->setMwGlobals( 'wgArticlePlaceholderImageProperty', '' );
+ $instance = $this->newInstance();
+
+ $this->setExpectedException( RuntimeException::class );
+ $instance->getImageProperty();
+ }
+
+ public function testGetReferencesBlacklist() {
+ $instance = $this->newInstance();
+
+ $actual = $instance->getReferencesBlacklist();
+ $this->assertSame( [ 'P2002' ], $actual );
+ }
+
+ public function testGetReferencesBlacklist_returnsNull() {
+ $this->setMwGlobals( 'wgArticlePlaceholderReferencesBlacklist', '' );
+ $instance = $this->newInstance();
+
+ $actual = $instance->getReferencesBlacklist();
+ $this->assertNull( $actual );
+ }
+
+ public function testRegister() {
+ $engine = $this->getMockBuilder( Scribunto_LuaEngine::class )
+ ->disableOriginalConstructor()
+ ->getMock();
+ $engine->expects( $this->once() )
+ ->method( 'registerInterface' )
+ ->willReturnCallback( function (
+ $moduleFileName,
+ array $interfaceFuncs,
+ array $setupOptions
+ ) {
+ $this->assertFileExists( $moduleFileName );
+ $this->assertInternalType( 'callable', $interfaceFuncs['getImageProperty'] );
+ $this->assertInternalType( 'callable', $interfaceFuncs['getReferencesBlacklist'] );
+
+ return 'dummyReturnValue';
+ } );
+ $instance = new Scribunto_LuaArticlePlaceholderLibrary( $engine );
+
+ $actual = $instance->register();
+ $this->assertSame( 'dummyReturnValue', $actual );
+ }
+
+ private function newInstance() {
+ $engine = $this->getMockBuilder( Scribunto_LuaEngine::class )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ return new Scribunto_LuaArticlePlaceholderLibrary( $engine );
+ }
+
+}

--
To view, visit https://gerrit.wikimedia.org/r/406054
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I28547aa378977d1c379e7e709357d9916c511e1f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ArticlePlaceholder
Gerrit-Branch: master
Gerrit-Owner: Thiemo Kreuz (WMDE) <thiemo.kreuz@wikimedia.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits