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() {
|
2019-10-05 01:41:15 +00:00
|
|
|
$context = $this->createMock( IContextSource::class );
|
2017-01-31 12:59:16 +00:00
|
|
|
$context->method( 'getTitle' )
|
|
|
|
->will( $this->returnValue( $this->newTitle() ) );
|
2019-10-29 11:22:52 +00:00
|
|
|
$fauxRequest = new \FauxRequest();
|
|
|
|
$config = new \HashConfig();
|
|
|
|
$context->method( 'getRequest' )
|
|
|
|
->willReturn( $fauxRequest );
|
|
|
|
$context->method( 'getConfig' )
|
|
|
|
->willReturn( $config );
|
2017-01-31 12:59:16 +00:00
|
|
|
|
2019-10-05 01:41:15 +00:00
|
|
|
$outputPage = $this->getMockBuilder( OutputPage::class )
|
|
|
|
->setMethods( [ 'addMeta' ] )
|
|
|
|
->setConstructorArgs( [ $context ] )
|
|
|
|
->getMock();
|
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
|
|
|
}
|