2019-11-08 14:46:52 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Cite\Tests\Unit;
|
|
|
|
|
2019-11-19 14:12:11 +00:00
|
|
|
use Cite\Cite;
|
2019-11-08 14:46:52 +00:00
|
|
|
use Wikimedia\TestingAccessWrapper;
|
|
|
|
|
|
|
|
/**
|
2019-11-19 14:12:11 +00:00
|
|
|
* @coversDefaultClass \Cite\Cite
|
2019-11-19 10:31:08 +00:00
|
|
|
*
|
|
|
|
* @license GPL-2.0-or-later
|
2019-11-08 14:46:52 +00:00
|
|
|
*/
|
2019-11-27 10:15:39 +00:00
|
|
|
class CiteUnitTest extends \MediaWikiUnitTestCase {
|
2019-11-08 14:46:52 +00:00
|
|
|
|
|
|
|
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 [
|
2019-11-22 08:49:27 +00:00
|
|
|
[ [], [ null, null, null, null, null ] ],
|
2019-11-08 14:46:52 +00:00
|
|
|
|
|
|
|
// One attribute only
|
2019-11-26 11:18:55 +00:00
|
|
|
[ [ 'dir' => 'invalid' ], [ 'invalid', null, null, null, null ] ],
|
|
|
|
[ [ 'dir' => ' rtl ' ], [ 'rtl', null, null, null, null ] ],
|
2019-11-08 14:46:52 +00:00
|
|
|
[ [ 'follow' => ' f ' ], [ null, null, 'f', null, null ] ],
|
|
|
|
// FIXME: Unlike all other attributes, group isn't trimmed. Why?
|
2019-11-26 11:18:55 +00:00
|
|
|
[ [ 'group' => ' g ' ], [ null, null, null, ' g ', null ] ],
|
2019-11-21 13:25:33 +00:00
|
|
|
[ [ 'invalid' => 'i' ], [ false, false, false, false, false ] ],
|
|
|
|
[ [ 'invalid' => null ], [ false, false, false, false, false ] ],
|
2019-11-26 11:18:55 +00:00
|
|
|
[ [ 'name' => ' n ' ], [ null, null, null, null, 'n' ] ],
|
2019-11-21 13:25:33 +00:00
|
|
|
[ [ 'name' => null ], [ false, false, false, false, false ] ],
|
2019-11-26 11:18:55 +00:00
|
|
|
[ [ 'extends' => ' e ' ], [ null, 'e', null, null, null ] ],
|
2019-11-08 14:46:52 +00:00
|
|
|
|
|
|
|
// Pairs
|
2019-11-26 11:18:55 +00:00
|
|
|
[ [ 'follow' => 'f', 'name' => 'n' ], [ null, null, 'f', null, 'n' ] ],
|
2019-11-21 13:25:33 +00:00
|
|
|
[ [ 'follow' => null, 'name' => null ], [ false, false, false, false, false ] ],
|
2019-11-26 11:18:55 +00:00
|
|
|
[ [ 'follow' => 'f', 'extends' => 'e' ], [ null, 'e', 'f', null, null ] ],
|
|
|
|
[ [ 'group' => 'g', 'name' => 'n' ], [ null, null, null, 'g', 'n' ] ],
|
2019-11-08 14:46:52 +00:00
|
|
|
|
|
|
|
// Combinations of 3 or more attributes
|
|
|
|
[
|
|
|
|
[ 'group' => 'g', 'name' => 'n', 'extends' => 'e', 'dir' => 'rtl' ],
|
2019-11-26 11:18:55 +00:00
|
|
|
[ 'rtl', 'e', null, 'g', 'n' ]
|
2019-11-08 14:46:52 +00:00
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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' ],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|