mediawiki-extensions-Cite/tests/phpunit/unit/CiteKeyFormatterTest.php
Thiemo Kreuz 22627f074d Make the normalizeKey() method private
There was a call in the API that was *not* using normalizeKey(). Now
that the API is gone, we can inline this.

This patch also contains a bunch of cleanups that might already been
resolved in the previous patches.

Change-Id: Id3767b5830268c8cfe9c10efabfa4a31e9dafeb8
2019-11-29 19:02:48 +01:00

47 lines
1 KiB
PHP

<?php
namespace Cite\Tests\Unit;
use Cite\CiteKeyFormatter;
use MediaWikiUnitTestCase;
use Wikimedia\TestingAccessWrapper;
/**
* @coversDefaultClass \Cite\CiteKeyFormatter
*
* @license GPL-2.0-or-later
*/
class CiteKeyFormatterTest extends MediaWikiUnitTestCase {
public function setUp() : void {
parent::setUp();
global $wgFragmentMode;
$wgFragmentMode = [ 'html5' ];
}
/**
* @covers ::normalizeKey
* @dataProvider provideKeyNormalizations
*/
public function testNormalizeKey( $key, $expected ) {
/** @var CiteKeyFormatter $formatter */
$formatter = TestingAccessWrapper::newFromObject( new CiteKeyFormatter() );
$this->assertSame( $expected, $formatter->normalizeKey( $key ) );
}
public function provideKeyNormalizations() {
return [
[ 'a b', 'a_b' ],
[ 'a __ b', 'a_b' ],
[ ':', ':' ],
[ "\t\n", '&#9;&#10;' ],
[ "'", '&#039;' ],
[ "''", '&#039;&#039;' ],
[ '"%&/<>?[]{|}', '&quot;%&amp;/&lt;&gt;?&#91;&#93;&#123;&#124;&#125;' ],
[ 'ISBN', '&#73;SBN' ],
];
}
}