Sumit has uploaded a new change for review. https://gerrit.wikimedia.org/r/220963
Change subject: WikidataPageBanner add getBannerUrl test ...................................................................... WikidataPageBanner add getBannerUrl test Adds a test for function getBannerUrl() which fetches image from local or foreign repo. Test uses files from wikimedia commons(foreign). Adjust the max_width in getBannerUrl() to 5000. Bug: T98832 Change-Id: I7bca4c7b14aa480d5d5b069ccf747aa71c1ac071 --- M includes/WikidataPageBanner.hooks.php A tests/phpunit/GetBannerUrlTest.php 2 files changed, 49 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikidataPageBanner refs/changes/63/220963/1 diff --git a/includes/WikidataPageBanner.hooks.php b/includes/WikidataPageBanner.hooks.php index 27b3c6c..8a5fde2 100644 --- a/includes/WikidataPageBanner.hooks.php +++ b/includes/WikidataPageBanner.hooks.php @@ -130,7 +130,7 @@ $title = Title::makeTitleSafe( NS_IMAGE, $filename ); $file = wfFindFile( $title ); $options = array( - 'options' => array( 'min_range' => 0, 'max_range' => 3000 ) + 'options' => array( 'min_range' => 0, 'max_range' => 5000 ) ); // if file not found, return null if ( $file == null ) { diff --git a/tests/phpunit/GetBannerUrlTest.php b/tests/phpunit/GetBannerUrlTest.php new file mode 100644 index 0000000..332346f --- /dev/null +++ b/tests/phpunit/GetBannerUrlTest.php @@ -0,0 +1,48 @@ +<?php +/** + * @group WikidataPageBanner + */ +class GetBannerUrlTest extends \MediaWikiTestCase { + protected function setUp() { + parent::setUp(); + $this->setMWGlobals( array( + 'wgUseInstantCommons' => 'true' + ) ); + } + + protected function tearDown() { + parent::tearDown(); + } + + /** + * testGetBannerUrl Tests getBannerUrl by using images from wikimedia commons + * Note: The mentioned images need to be present on commons for tests to succeed, if not, + * they should be replaced + * @covers getBannerUrl(...) + */ + public function testGetBannerUrl() { + $file = 'Manhattan4_amk.jpg'; + $url = WikidataPageBanner::getBannerUrl( $file ); + $this->assertStringStartsWith( 'http', $url, + 'On providing valid image, its url should be returned' ); + $url = WikidataPageBanner::getBannerUrl( $file, 800, + 'On providing valid image, its url should be returned' ); + $this->assertStringStartsWith( 'http', $url ); + $url = WikidataPageBanner::getBannerUrl( $file, 1600, + 'On providing valid image, its url should be returned' ); + $this->assertStringStartsWith( 'http', $url ); + + $file = 'Sainte-Enimie-Gorges_du_Tarn_France_banner.jpg'; + $url = WikidataPageBanner::getBannerUrl( $file ); + $this->assertStringStartsWith( 'http', $url, + 'On providing valid image, its url should be returned' ); + $url = WikidataPageBanner::getBannerUrl( $file, 4300 ); + $this->assertNull( $url, + 'On providing valid image with width greater than original width, null should be returned' ); + + $file = ''; + $url = WikidataPageBanner::getBannerUrl( $file, 1600 ); + $this->assertNull( $url, 'invalid image should return null' ); + } +} + -- To view, visit https://gerrit.wikimedia.org/r/220963 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I7bca4c7b14aa480d5d5b069ccf747aa71c1ac071 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikidataPageBanner Gerrit-Branch: master Gerrit-Owner: Sumit <asthana.sumi...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits