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;
|
2020-04-19 22:41:19 +00:00
|
|
|
use PageImages\PageImages;
|
2017-01-31 12:59:16 +00:00
|
|
|
use SkinTemplate;
|
2015-10-07 15:18:54 +00:00
|
|
|
use Title;
|
|
|
|
|
|
|
|
/**
|
2020-04-19 22:41:19 +00:00
|
|
|
* @covers \PageImages\PageImages
|
2015-10-07 15:18:54 +00:00
|
|
|
*
|
|
|
|
* @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();
|
2020-05-01 01:33:19 +00:00
|
|
|
$this->assertInstanceOf( PageImages::class, $pageImages );
|
2015-10-07 15:18:54 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2020-04-20 13:34:12 +00:00
|
|
|
public function testGetPropNames() {
|
|
|
|
$this->assertSame(
|
|
|
|
[ PageImages::PROP_NAME_FREE, PageImages::PROP_NAME ],
|
|
|
|
PageImages::getPropNames( PageImages::LICENSE_ANY )
|
|
|
|
);
|
|
|
|
$this->assertSame(
|
|
|
|
PageImages::PROP_NAME_FREE,
|
|
|
|
PageImages::getPropNames( PageImages::LICENSE_FREE )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
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' )
|
2021-03-20 05:22:04 +00:00
|
|
|
->willReturn( $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
|
|
|
}
|