overrideConfigValue( 'FragmentMode', [ 'html5' ] ); } /** * @covers ::refKey * @covers ::backLink */ public function testRefKey() { $mockMessageLocalizer = $this->createMock( ReferenceMessageLocalizer::class ); $mockMessageLocalizer->method( 'msg' )->willReturnCallback( function ( ...$args ) { $msg = $this->createMock( Message::class ); $msg->method( 'plain' )->willReturn( '(' . implode( '|', $args ) . ')' ); return $msg; } ); $formatter = new AnchorFormatter( $mockMessageLocalizer ); $this->assertSame( '(cite_reference_link_prefix)key', $formatter->backLink( 'key', null ) ); $this->assertSame( '(cite_reference_link_prefix)key_2', $formatter->backLink( 'key', '2' ) ); } /** * @covers ::getReferencesKey * @covers ::jumpLink */ public function testGetReferencesKey() { $mockMessageLocalizer = $this->createMock( ReferenceMessageLocalizer::class ); $mockMessageLocalizer->method( 'msg' )->willReturnCallback( function ( ...$args ) { $msg = $this->createMock( Message::class ); $msg->method( 'plain' )->willReturn( '(' . implode( '|', $args ) . ')' ); return $msg; } ); $formatter = new AnchorFormatter( $mockMessageLocalizer ); $this->assertSame( '(cite_references_link_prefix)key', $formatter->jumpLink( 'key' ) ); } /** * @covers ::normalizeKey * @covers ::__construct * @dataProvider provideKeyNormalizations */ public function testNormalizeKey( $key, $expected ) { /** @var AnchorFormatter $formatter */ $formatter = TestingAccessWrapper::newFromObject( new AnchorFormatter( $this->createMock( ReferenceMessageLocalizer::class ) ) ); $normalized = $formatter->normalizeKey( $key ); $encoded = Sanitizer::safeEncodeAttribute( Sanitizer::escapeIdForLink( $normalized ) ); $this->assertSame( $expected, $encoded ); } public static function provideKeyNormalizations() { return [ [ 'a b', 'a_b' ], [ 'a __ b', 'a_b' ], [ ':', ':' ], [ "\t\n", '_' ], [ "'", ''' ], [ "''", '''' ], [ '"%&/<>?[]{|}', '"%&/<>?[]{|}' ], [ 'ISBN', 'ISBN' ], [ 'nature%20phylo', 'nature%2520phylo' ], [ 'Mininova%2E26%2E11%2E2009', 'Mininova%252E26%252E11%252E2009' ], [ '%c8%98tiri_2019', '%25c8%2598tiri_2019' ], [ 'play%21', 'play%2521' ], [ 'Terry+O%26rsquo%3BN…