Add the first small PHPUnit test for Cite::normalizeKey()

Note this is intentionally testing a private method. As of now, the
code is so heavily entangled, it's not yet possible to test individual
aspects without calling private methods. The plan is to slowly increase
the overall test coverage, and the start restructuring the code as
necessary.

Change-Id: Ib3b01bddaffd0469fb66979c67c8114a5807df6d
This commit is contained in:
Thiemo Kreuz 2019-11-07 10:05:14 +01:00 committed by Thiemo Kreuz (WMDE)
parent 16b757b88d
commit 64c94662f0

View file

@ -0,0 +1,41 @@
<?php
use Wikimedia\TestingAccessWrapper;
/**
* @coversDefaultClass \Cite
*/
class CiteTest extends MediaWikiTestCase {
protected function setUp() : void {
parent::setUp();
$this->setMwGlobals( [
'wgFragmentMode' => [ 'html5' ],
] );
}
/**
* @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", '&#9;&#10;' ],
[ "'", '&#039;' ],
[ "''", '&#039;&#039;' ],
[ '"%&/<>?[]{|}', '&quot;%&amp;/&lt;&gt;?&#91;&#93;&#123;&#124;&#125;' ],
[ 'ISBN', '&#73;SBN' ],
];
}
}