Thiemo Mättig (WMDE) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/244175

Change subject: Add basic PHPUnit tests
......................................................................

Add basic PHPUnit tests

This adds a few very basic tests to this component. I started doing this
while working on T112865 but later realized I do not need to touch this
extension. However, I started setting up tests and wanted to submit them.

Bug: T112865
Change-Id: I9d00b2baed8da97ffb6af94a6e3b8b63621b876a
---
A tests/phpunit/ApiQueryPageImagesTest.php
A tests/phpunit/PageImagesTest.php
2 files changed, 127 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PageImages 
refs/changes/75/244175/1

diff --git a/tests/phpunit/ApiQueryPageImagesTest.php 
b/tests/phpunit/ApiQueryPageImagesTest.php
new file mode 100644
index 0000000..5bf49d5
--- /dev/null
+++ b/tests/phpunit/ApiQueryPageImagesTest.php
@@ -0,0 +1,72 @@
+<?php
+
+namespace PageImages\Tests;
+
+use ApiQueryPageImages;
+use PHPUnit_Framework_TestCase;
+
+/**
+ * @covers ApiQueryPageImages
+ *
+ * @group PageImages
+ *
+ * @licence GNU GPL v2+
+ * @author Thiemo Mättig
+ */
+class ApiQueryPageImagesTest extends PHPUnit_Framework_TestCase {
+
+       private function getApi() {
+               $context = $this->getMockBuilder( 'IContextSource' )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+
+               $main = $this->getMockBuilder( 'ApiMain' )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+               $main->expects( $this->once() )
+                       ->method( 'getContext' )
+                       ->will( $this->returnValue( $context ) );
+
+               $query = $this->getMockBuilder( 'ApiQuery' )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+               $query->expects( $this->once() )
+                       ->method( 'getMain' )
+                       ->will( $this->returnValue( $main ) );
+
+               return new ApiQueryPageImages( $query, '' );
+       }
+
+       public function testConstructor() {
+               $api = $this->getApi();
+               $this->assertInstanceOf( 'ApiQueryPageImages', $api );
+       }
+
+       public function testGetDescription() {
+               $api = $this->getApi();
+               $description = $api->getDescription();
+               $this->assertInternalType( 'string', $description );
+               $this->assertNotEmpty( $description );
+       }
+
+       public function testGetCacheMode() {
+               $api = $this->getApi();
+               $this->assertSame( 'public', $api->getCacheMode( array() ) );
+       }
+
+       public function testGetAllowedParams() {
+               $api = $this->getApi();
+               $params = $api->getAllowedParams();
+               $this->assertInternalType( 'array', $params );
+               $this->assertNotEmpty( $params );
+               $this->assertContainsOnly( 'array', $params );
+       }
+
+       public function testGetParamDescription() {
+               $api = $this->getApi();
+               $descriptions = $api->getParamDescription();
+               $this->assertInternalType( 'array', $descriptions );
+               $this->assertNotEmpty( $descriptions );
+       }
+
+}
diff --git a/tests/phpunit/PageImagesTest.php b/tests/phpunit/PageImagesTest.php
new file mode 100644
index 0000000..043a93f
--- /dev/null
+++ b/tests/phpunit/PageImagesTest.php
@@ -0,0 +1,55 @@
+<?php
+
+namespace PageImages\Tests;
+
+use PageImages;
+use PHPUnit_Framework_TestCase;
+use stdClass;
+use Title;
+
+/**
+ * @covers PageImages
+ *
+ * @group PageImages
+ *
+ * @licence GNU GPL v2+
+ * @author Thiemo Mättig
+ */
+class PageImagesTest extends PHPUnit_Framework_TestCase {
+
+       public function testPagePropertyName() {
+               $this->assertSame( 'page_image', PageImages::PROP_NAME );
+       }
+
+       public function testConstructor() {
+               $pageImages = new PageImages();
+               $this->assertInstanceOf( 'PageImages', $pageImages );
+       }
+
+       public function testGivenNonExistingPage_getPageImageReturnsFalse() {
+               $title = Title::newFromText( 'Title' );
+               $title->resetArticleID( 0 );
+
+               $pageImages = new PageImages();
+               $this->assertFalse( $pageImages->getPageImage( $title ) );
+       }
+
+       public function testOnLinksUpdate() {
+               $parserOutput = new stdClass();
+               $parserOutput->pageImages = array(
+                       array( 'filename' => 'A.jpg', 'fullwidth' => 100, 
'fullheight' => 50 ),
+               );
+
+               $linksUpdate = $this->getMockBuilder( 'LinksUpdate' )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+               $linksUpdate->expects( $this->any() )
+                       ->method( 'getParserOutput' )
+                       ->will( $this->returnValue( $parserOutput ) );
+
+               $pageImages = new PageImages();
+               $this->assertTrue( $pageImages->onLinksUpdate( $linksUpdate ) );
+               $this->assertSame( 'A.jpg', 
$linksUpdate->mProperties[PageImages::PROP_NAME] );
+       }
+
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9d00b2baed8da97ffb6af94a6e3b8b63621b876a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/PageImages
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>

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

Reply via email to