mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-14 10:34:53 +00:00
5ac57def59
Incremental patch which extracts the refines attribute from the tag. Doing this now to allow the calling function to have responsibility for doing something with the attribute value. Bug: T237531 Change-Id: I59bb409bedd8e6ed06268e705e02e8ffb45b1f0e
81 lines
2.3 KiB
PHP
81 lines
2.3 KiB
PHP
<?php
|
|
|
|
use Wikimedia\TestingAccessWrapper;
|
|
|
|
/**
|
|
* @coversDefaultClass \Cite
|
|
*/
|
|
class CiteTest extends MediaWikiTestCase {
|
|
|
|
protected function setUp() : void {
|
|
parent::setUp();
|
|
|
|
$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 ] ],
|
|
[ [ 'refines' => 'r' ], [ null, null, null, null, 'r' ] ],
|
|
|
|
// Pairs
|
|
[ [ 'follow' => 'f', 'name' => 'n' ], [ false, false, false, false, false ] ],
|
|
[ [ 'follow' => null, 'name' => null ], [ false, false, false, false, false ] ],
|
|
[ [ 'follow' => 'f', 'refines' => 'r' ], [ null, null, 'f', null, 'r' ] ],
|
|
[ [ 'group' => 'g', 'name' => 'n' ], [ 'n', 'g', null, null, null ] ],
|
|
|
|
// Combinations of 3 or more attributes
|
|
[
|
|
[ 'group' => 'g', 'name' => 'n', 'refines' => 'r', 'dir' => 'rtl' ],
|
|
[ 'n', 'g', null, ' class="mw-cite-dir-rtl"', 'r' ]
|
|
],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @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' ],
|
|
];
|
|
}
|
|
|
|
}
|