mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-23 22:45:20 +00:00
Merge "Make most existing Cite tests pure unit tests"
This commit is contained in:
commit
0782f24d31
|
@ -305,7 +305,7 @@ class CiteHooks {
|
|||
* @param ApiQuerySiteinfo $api
|
||||
* @param array &$data
|
||||
*/
|
||||
public static function onAPIQuerySiteInfoGeneralInfo( ApiQuerySiteinfo $api, array &$data ) {
|
||||
public static function onAPIQuerySiteInfoGeneralInfo( $api, array &$data ) {
|
||||
$config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'cite' );
|
||||
$data['citeresponsivereferences'] = $config->get( 'CiteResponsiveReferences' );
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ use Cite;
|
|||
use Parser;
|
||||
use ParserOutput;
|
||||
use StripState;
|
||||
use Wikimedia\TestingAccessWrapper;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Cite
|
||||
|
@ -18,75 +17,13 @@ class CiteTest extends \MediaWikiIntegrationTestCase {
|
|||
|
||||
$this->setMwGlobals( [
|
||||
'wgCiteBookReferencing' => true,
|
||||
'wgFragmentMode' => [ 'html5' ],
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::refArg
|
||||
* @dataProvider provideRefAttributes
|
||||
*/
|
||||
public function testRefArg( array $attributes, array $expected ) {
|
||||
/** @var Cite $cite */
|
||||
$cite = TestingAccessWrapper::newFromObject( new Cite() );
|
||||
$this->assertSame( $expected, $cite->refArg( $attributes ) );
|
||||
}
|
||||
|
||||
public function provideRefAttributes() {
|
||||
return [
|
||||
[ [], [ null, null, false, null, null ] ],
|
||||
|
||||
// One attribute only
|
||||
[ [ 'dir' => 'invalid' ], [ null, null, false, '', null ] ],
|
||||
[ [ 'dir' => 'rtl' ], [ null, null, false, ' class="mw-cite-dir-rtl"', null ] ],
|
||||
[ [ 'follow' => 'f' ], [ null, null, 'f', null, null ] ],
|
||||
[ [ 'group' => 'g' ], [ null, 'g', null, null, null ] ],
|
||||
[ [ 'invalid' => 'i' ], [ false, false, false, false, false ] ],
|
||||
[ [ 'name' => 'n' ], [ 'n', null, null, null, null ] ],
|
||||
[ [ 'name' => null ], [ false, false, false, false, false ] ],
|
||||
[ [ 'extends' => 'e' ], [ null, null, null, null, 'e' ] ],
|
||||
|
||||
// Pairs
|
||||
[ [ 'follow' => 'f', 'name' => 'n' ], [ false, false, false, false, false ] ],
|
||||
[ [ 'follow' => null, 'name' => null ], [ false, false, false, false, false ] ],
|
||||
[ [ 'follow' => 'f', 'extends' => 'e' ], [ false, false, false, false, false ] ],
|
||||
[ [ 'group' => 'g', 'name' => 'n' ], [ 'n', 'g', null, null, null ] ],
|
||||
|
||||
// Combinations of 3 or more attributes
|
||||
[
|
||||
[ 'group' => 'g', 'name' => 'n', 'extends' => 'e', 'dir' => 'rtl' ],
|
||||
[ 'n', 'g', null, ' class="mw-cite-dir-rtl"', 'e' ]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::normalizeKey
|
||||
* @dataProvider provideKeyNormalizations
|
||||
*/
|
||||
public function testNormalizeKey( $key, $expected ) {
|
||||
/** @var Cite $cite */
|
||||
$cite = TestingAccessWrapper::newFromObject( new Cite() );
|
||||
$this->assertSame( $expected, $cite->normalizeKey( $key ) );
|
||||
}
|
||||
|
||||
public function provideKeyNormalizations() {
|
||||
return [
|
||||
[ 'a b', 'a_b' ],
|
||||
[ 'a __ b', 'a_b' ],
|
||||
[ ':', ':' ],
|
||||
[ "\t\n", '	 ' ],
|
||||
[ "'", ''' ],
|
||||
[ "''", '''' ],
|
||||
[ '"%&/<>?[]{|}', '"%&/<>?[]{|}' ],
|
||||
[ 'ISBN', 'ISBN' ],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::guardedRef
|
||||
*/
|
||||
public function testRef_pageProperty() {
|
||||
public function testBookExtendsPageProperty() {
|
||||
$mockOutput = $this->createMock( ParserOutput::class );
|
||||
$mockOutput->expects( $this->once() )
|
||||
->method( 'setProperty' )
|
||||
|
|
84
tests/phpunit/unit/CiteTest.php
Normal file
84
tests/phpunit/unit/CiteTest.php
Normal file
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
|
||||
namespace Cite\Tests\Unit;
|
||||
|
||||
use Cite;
|
||||
use Wikimedia\TestingAccessWrapper;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Cite
|
||||
*/
|
||||
class CiteTest extends \MediaWikiUnitTestCase {
|
||||
|
||||
protected function setUp() : void {
|
||||
global $wgCiteBookReferencing, $wgFragmentMode;
|
||||
|
||||
parent::setUp();
|
||||
$wgCiteBookReferencing = true;
|
||||
$wgFragmentMode = [ 'html5' ];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::refArg
|
||||
* @dataProvider provideRefAttributes
|
||||
*/
|
||||
public function testRefArg( array $attributes, array $expected ) {
|
||||
/** @var Cite $cite */
|
||||
$cite = TestingAccessWrapper::newFromObject( new Cite() );
|
||||
$this->assertSame( $expected, $cite->refArg( $attributes ) );
|
||||
}
|
||||
|
||||
public function provideRefAttributes() {
|
||||
return [
|
||||
[ [], [ null, null, false, null, null ] ],
|
||||
|
||||
// One attribute only
|
||||
[ [ 'dir' => 'invalid' ], [ null, null, false, '', null ] ],
|
||||
[ [ 'dir' => 'rtl' ], [ null, null, false, ' class="mw-cite-dir-rtl"', null ] ],
|
||||
[ [ 'follow' => ' f ' ], [ null, null, 'f', null, null ] ],
|
||||
// FIXME: Unlike all other attributes, group isn't trimmed. Why?
|
||||
[ [ 'group' => ' g ' ], [ null, ' g ', null, null, null ] ],
|
||||
[ [ 'invalid' => 'i' ], [ false, false, false, false, false ] ],
|
||||
[ [ 'invalid' => null ], [ false, false, false, false, false ] ],
|
||||
[ [ 'name' => ' n ' ], [ 'n', null, null, null, null ] ],
|
||||
[ [ 'name' => null ], [ false, false, false, false, false ] ],
|
||||
[ [ 'extends' => ' e ' ], [ null, null, null, null, 'e' ] ],
|
||||
|
||||
// Pairs
|
||||
[ [ 'follow' => 'f', 'name' => 'n' ], [ false, false, false, false, false ] ],
|
||||
[ [ 'follow' => null, 'name' => null ], [ false, false, false, false, false ] ],
|
||||
[ [ 'follow' => 'f', 'extends' => 'e' ], [ false, false, false, false, false ] ],
|
||||
[ [ 'group' => 'g', 'name' => 'n' ], [ 'n', 'g', null, null, null ] ],
|
||||
|
||||
// Combinations of 3 or more attributes
|
||||
[
|
||||
[ 'group' => 'g', 'name' => 'n', 'extends' => 'e', 'dir' => 'rtl' ],
|
||||
[ 'n', 'g', null, ' class="mw-cite-dir-rtl"', 'e' ]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::normalizeKey
|
||||
* @dataProvider provideKeyNormalizations
|
||||
*/
|
||||
public function testNormalizeKey( $key, $expected ) {
|
||||
/** @var Cite $cite */
|
||||
$cite = TestingAccessWrapper::newFromObject( new Cite() );
|
||||
$this->assertSame( $expected, $cite->normalizeKey( $key ) );
|
||||
}
|
||||
|
||||
public function provideKeyNormalizations() {
|
||||
return [
|
||||
[ 'a b', 'a_b' ],
|
||||
[ 'a __ b', 'a_b' ],
|
||||
[ ':', ':' ],
|
||||
[ "\t\n", '	 ' ],
|
||||
[ "'", ''' ],
|
||||
[ "''", '''' ],
|
||||
[ '"%&/<>?[]{|}', '"%&/<>?[]{|}' ],
|
||||
[ 'ISBN', 'ISBN' ],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue