2015-10-07 15:18:54 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace PageImages\Tests;
|
|
|
|
|
2017-01-31 12:59:16 +00:00
|
|
|
use IContextSource;
|
2015-10-07 15:18:54 +00:00
|
|
|
use MediaWikiTestCase;
|
2017-01-31 12:59:16 +00:00
|
|
|
use OutputPage;
|
2015-10-07 15:18:54 +00:00
|
|
|
use PageImages;
|
2017-01-31 12:59:16 +00:00
|
|
|
use SkinTemplate;
|
2015-10-07 15:18:54 +00:00
|
|
|
use Title;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers PageImages
|
|
|
|
*
|
|
|
|
* @group PageImages
|
|
|
|
* @group Database
|
|
|
|
*
|
2018-05-25 04:42:29 +00:00
|
|
|
* @license WTFPL
|
2017-11-24 07:33:49 +00:00
|
|
|
* @author Thiemo Kreuz
|
2015-10-07 15:18:54 +00:00
|
|
|
*/
|
|
|
|
class PageImagesTest extends MediaWikiTestCase {
|
|
|
|
|
2016-11-10 00:02:00 +00:00
|
|
|
public function testPagePropertyNames() {
|
2015-10-07 15:18:54 +00:00
|
|
|
$this->assertSame( 'page_image', PageImages::PROP_NAME );
|
2016-11-10 00:02:00 +00:00
|
|
|
$this->assertSame( 'page_image_free', PageImages::PROP_NAME_FREE );
|
2015-10-07 15:18:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testConstructor() {
|
|
|
|
$pageImages = new PageImages();
|
|
|
|
$this->assertInstanceOf( 'PageImages', $pageImages );
|
|
|
|
}
|
|
|
|
|
2017-12-06 22:11:25 +00:00
|
|
|
public function testGivenNonExistingPageGetPageImageReturnsFalse() {
|
2017-01-31 12:59:16 +00:00
|
|
|
$title = $this->newTitle();
|
2015-10-07 15:18:54 +00:00
|
|
|
$this->assertFalse( PageImages::getPageImage( $title ) );
|
|
|
|
}
|
|
|
|
|
2016-11-10 00:02:00 +00:00
|
|
|
public function testGetPropName() {
|
|
|
|
$this->assertSame( 'page_image', PageImages::getPropName( false ) );
|
|
|
|
$this->assertSame( 'page_image_free', PageImages::getPropName( true ) );
|
|
|
|
}
|
2017-01-31 12:59:16 +00:00
|
|
|
|
2017-12-06 22:11:25 +00:00
|
|
|
public function testGivenNonExistingPageOnBeforePageDisplayDoesNotAddMeta() {
|
2017-01-31 12:59:16 +00:00
|
|
|
$context = $this->getMock( IContextSource::class );
|
|
|
|
$context->method( 'getTitle' )
|
|
|
|
->will( $this->returnValue( $this->newTitle() ) );
|
|
|
|
|
2018-04-14 05:20:17 +00:00
|
|
|
$outputPage = $this->getMock(
|
|
|
|
OutputPage::class, [ 'addMeta' ], [ $context ] );
|
2017-01-31 12:59:16 +00:00
|
|
|
$outputPage->expects( $this->never() )
|
|
|
|
->method( 'addMeta' );
|
|
|
|
|
2018-02-26 16:49:10 +00:00
|
|
|
$skinTemplate = new SkinTemplate();
|
|
|
|
PageImages::onBeforePageDisplay( $outputPage, $skinTemplate );
|
2017-01-31 12:59:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Title
|
|
|
|
*/
|
|
|
|
private function newTitle() {
|
|
|
|
$title = Title::newFromText( 'New' );
|
|
|
|
$title->resetArticleID( 0 );
|
|
|
|
return $title;
|
|
|
|
}
|
|
|
|
|
2015-10-07 15:18:54 +00:00
|
|
|
}
|