2019-11-28 14:35:23 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Cite\Tests\Unit;
|
|
|
|
|
|
|
|
use Cite\CiteKeyFormatter;
|
|
|
|
use MediaWikiUnitTestCase;
|
2019-11-29 14:00:39 +00:00
|
|
|
use Wikimedia\TestingAccessWrapper;
|
2019-11-28 14:35:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @coversDefaultClass \Cite\CiteKeyFormatter
|
2019-11-29 14:00:39 +00:00
|
|
|
*
|
|
|
|
* @license GPL-2.0-or-later
|
2019-11-28 14:35:23 +00:00
|
|
|
*/
|
|
|
|
class CiteKeyFormatterTest extends MediaWikiUnitTestCase {
|
|
|
|
|
|
|
|
public function setUp() : void {
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
global $wgFragmentMode;
|
|
|
|
$wgFragmentMode = [ 'html5' ];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::normalizeKey
|
|
|
|
* @dataProvider provideKeyNormalizations
|
|
|
|
*/
|
|
|
|
public function testNormalizeKey( $key, $expected ) {
|
2019-11-29 14:00:39 +00:00
|
|
|
/** @var CiteKeyFormatter $formatter */
|
|
|
|
$formatter = TestingAccessWrapper::newFromObject( new CiteKeyFormatter() );
|
|
|
|
$this->assertSame( $expected, $formatter->normalizeKey( $key ) );
|
2019-11-28 14:35:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function provideKeyNormalizations() {
|
|
|
|
return [
|
|
|
|
[ 'a b', 'a_b' ],
|
|
|
|
[ 'a __ b', 'a_b' ],
|
|
|
|
[ ':', ':' ],
|
|
|
|
[ "\t\n", '	 ' ],
|
|
|
|
[ "'", ''' ],
|
|
|
|
[ "''", '''' ],
|
|
|
|
[ '"%&/<>?[]{|}', '"%&/<>?[]{|}' ],
|
|
|
|
[ 'ISBN', 'ISBN' ],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|