mediawiki-extensions-Cite/tests/phpunit/CiteTest.php
Thiemo Kreuz 64c94662f0 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
2019-11-07 09:23:13 +00:00

42 lines
857 B
PHP

<?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' ],
];
}
}