Debian Codegraph @

extensions/Cite/tests/phpunit/unit/CiteParserTagHooksTest.php

raw symbols SCIP
1 <?php
2
3 namespace Cite\Tests\Unit;
4
5 use Cite\Cite;
6 use Cite\Hooks\CiteParserTagHooks;
7 use MediaWiki\Config\Config;
8 use MediaWiki\Parser\Parser;
9 use MediaWiki\Parser\ParserOutput;
10 use MediaWiki\Parser\PPFrame;
11
12 /**
13 * @covers \Cite\Hooks\CiteParserTagHooks
14 * @license GPL-2.0-or-later
15 */
16 class CiteParserTagHooksTest extends \MediaWikiUnitTestCase {
17
18 private function newCiteParserTagHooks() {
19 return new CiteParserTagHooks(
20 $this->createNoOpMock( Config::class )
21 );
22 }
23
24 public function testRegister() {
25 $parser = $this->createNoOpMock( Parser::class, [ 'setHook' ] );
26 $expectedTags = [ 'ref' => true, 'references' => true ];
27 $parser->expects( $this->exactly( 2 ) )
28 ->method( 'setHook' )
29 ->willReturnCallback( function ( $tag ) use ( &$expectedTags ) {
30 $this->assertArrayHasKey( $tag, $expectedTags );
31 unset( $expectedTags[$tag] );
32 } );
33
34 $citeParserTagHooks = $this->newCiteParserTagHooks();
35 $citeParserTagHooks->register( $parser );
36 }
37
38 public function testRef_fails() {
39 $cite = $this->createMock( Cite::class );
40 $cite->method( 'ref' )
41 ->willReturn( null );
42
43 $parser = $this->createNoOpMock( Parser::class );
44 $parser->extCite = $cite;
45
46 $frame = $this->createMock( PPFrame::class );
47
48 $citeParserTagHooks = $this->newCiteParserTagHooks();
49 $html = $citeParserTagHooks->ref( null, [], $parser, $frame );
50 $this->assertSame( '&lt;ref&gt;&lt;/ref&gt;', $html );
51 }
52
53 public function testRef() {
54 $cite = $this->createMock( Cite::class );
55 $cite->expects( $this->once() )
56 ->method( 'ref' )
57 ->willReturn( '<HTML>' );
58
59 $parserOutput = $this->createMock( ParserOutput::class );
60 $parserOutput->expects( $this->once() )
61 ->method( 'addModules' );
62 $parserOutput->expects( $this->once() )
63 ->method( 'addModuleStyles' );
64
65 $parser = $this->createNoOpMock( Parser::class, [ 'getOutput' ] );
66 $parser->method( 'getOutput' )
67 ->willReturn( $parserOutput );
68 $parser->extCite = $cite;
69
70 $frame = $this->createMock( PPFrame::class );
71
72 $citeParserTagHooks = $this->newCiteParserTagHooks();
73 $html = $citeParserTagHooks->ref( null, [], $parser, $frame );
74 $this->assertSame( '<HTML>', $html );
75 }
76
77 public function testReferences_fails() {
78 $cite = $this->createMock( Cite::class );
79 $cite->method( 'references' )
80 ->willReturn( null );
81
82 $parser = $this->createNoOpMock( Parser::class );
83 $parser->extCite = $cite;
84
85 $frame = $this->createMock( PPFrame::class );
86
87 $citeParserTagHooks = $this->newCiteParserTagHooks();
88 $html = $citeParserTagHooks->references( null, [], $parser, $frame );
89 $this->assertSame( '&lt;references/&gt;', $html );
90 }
91
92 public function testReferences() {
93 $cite = $this->createMock( Cite::class );
94 $cite->expects( $this->once() )
95 ->method( 'references' )
96 ->willReturn( '<HTML>' );
97
98 $parser = $this->createNoOpMock( Parser::class );
99 $parser->extCite = $cite;
100
101 $frame = $this->createMock( PPFrame::class );
102
103 $citeParserTagHooks = $this->newCiteParserTagHooks();
104 $html = $citeParserTagHooks->references( null, [], $parser, $frame );
105 $this->assertSame( '<HTML>', $html );
106 }
107
108 }