2017-05-19 13:37:26 +00:00
|
|
|
<?php
|
|
|
|
namespace TextExtracts\Test;
|
|
|
|
|
2018-01-23 22:54:12 +00:00
|
|
|
use MediaWikiCoversValidator;
|
2017-05-19 13:37:26 +00:00
|
|
|
use TextExtracts\ApiQueryExtracts;
|
|
|
|
|
|
|
|
/**
|
2018-01-23 22:54:12 +00:00
|
|
|
* @covers \TextExtracts\ApiQueryExtracts
|
2017-05-19 13:37:26 +00:00
|
|
|
* @group TextExtracts
|
|
|
|
*/
|
2018-02-15 14:32:47 +00:00
|
|
|
class ApiQueryExtractsTest extends \PHPUnit\Framework\TestCase {
|
2018-01-23 22:54:12 +00:00
|
|
|
use MediaWikiCoversValidator;
|
|
|
|
|
2017-05-19 13:37:26 +00:00
|
|
|
private function newInstance() {
|
|
|
|
$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 ) );
|
|
|
|
|
|
|
|
$config = $this->getMockBuilder( 'Config' )
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
return new ApiQueryExtracts( $query, '', $config );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetAllowedParams() {
|
|
|
|
$instance = $this->newInstance();
|
|
|
|
$params = $instance->getAllowedParams();
|
|
|
|
$this->assertInternalType( 'array', $params );
|
2017-05-24 22:04:20 +00:00
|
|
|
$this->assertArrayHasKey( 'chars', $params );
|
|
|
|
$this->assertEquals( $params['chars'][\ApiBase::PARAM_MIN], 1 );
|
|
|
|
$this->assertEquals( $params['chars'][\ApiBase::PARAM_MAX], 1200 );
|
2017-05-19 13:37:26 +00:00
|
|
|
$this->assertArrayHasKey( 'limit', $params );
|
|
|
|
$this->assertEquals( $params['limit'][\ApiBase::PARAM_DFLT], 20 );
|
|
|
|
$this->assertEquals( $params['limit'][\ApiBase::PARAM_TYPE], 'limit' );
|
|
|
|
$this->assertEquals( $params['limit'][\ApiBase::PARAM_MIN], 1 );
|
|
|
|
$this->assertEquals( $params['limit'][\ApiBase::PARAM_MAX], 20 );
|
|
|
|
$this->assertEquals( $params['limit'][\ApiBase::PARAM_MAX2], 20 );
|
|
|
|
}
|
|
|
|
}
|