Completed
Push — master ( 35bd4c...c8e02c )
by
unknown
10:31 queued 10s
created

OutputPageParserOutputTest::testCanConstruct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 0
loc 20
rs 9.4285
c 1
b 1
f 0
cc 1
eloc 14
nc 1
nop 0
1
<?php
2
3
namespace BootstrapComponents\Tests\Unit\Hooks;
4
5
use BootstrapComponents\Hooks\OutputPageParserOutput;
6
use BootstrapComponents\ParserOutputHelper;
7
use \ParserOutput;
8
use \PHPUnit_Framework_TestCase;
9
10
/**
11
 * @covers  \BootstrapComponents\Hooks\OutputPageParserOutput
12
 *
13
 * @ingroup Test
14
 *
15
 * @group   extension-bootstrap-components
16
 * @group   mediawiki-databaseless
17
 *
18
 * @license GNU GPL v3+
19
 *
20
 * @since   1.2
21
 * @author  Tobias Oetterer
22
 */
23
class OutputPageParserOutputTest extends PHPUnit_Framework_TestCase {
24
25
	public function testCanConstruct() {
26
27
		$outputPage = $this->getMockBuilder( 'OutputPage' )
28
			->disableOriginalConstructor()
29
			->getMock();
30
		$parserOutput = $this->getMockBuilder( 'ParserOutput' )
31
			->disableOriginalConstructor()
32
			->getMock();
33
		$parserOutputHelper = $this->getMockBuilder( 'BootstrapComponents\ParserOutputHelper' )
34
			->disableOriginalConstructor()
35
			->getMock();
36
37
		/** @noinspection PhpParamsInspection */
38
		$instance = new OutputPageParserOutput( $outputPage, $parserOutput, $parserOutputHelper );
39
40
		$this->assertInstanceOf(
41
			'BootstrapComponents\\Hooks\\OutputPageParserOutput',
42
			$instance
43
		);
44
	}
45
46
	public function testHookOutputPageParserOutput() {
47
		$content = 'CONTENT';
48
		$parser = $this->getMockBuilder( 'Parser' )
49
			->disableOriginalConstructor()
50
			->getMock();
51
		$outputPage = $this->getMockBuilder( 'OutputPage' )
52
			->disableOriginalConstructor()
53
			->getMock();
54
55
		$observerParserOutput = $this->getMockBuilder(ParserOutput::class )
56
			->disableOriginalConstructor()
57
#			->setMethods( [ 'getText', 'setText', 'getExtensionData' ] )
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
58
			->getMock();
59
		$observerParserOutput->expects( $this->exactly( 1 ) )
60
			->method( 'getText' )
61
			->will( $this->returnCallback( function() use ( &$content ) {
62
				return $content;
63
			} ) );
64
		$observerParserOutput->expects( $this->exactly( 1 ) )
65
			->method( 'setText' )
66
			->will( $this->returnCallback( function( $injection ) use ( &$content ) {
67
				$content = $injection;
68
			} ) );
69
		$observerParserOutput->expects( $this->exactly( 1 ) )
70
			->method( 'getExtensionData' )
71
			->with(
72
				$this->stringContains( 'bsc_deferredContent' )
73
			)
74
			->willReturn( [ 'test' ] );
75
76
		/** @noinspection PhpParamsInspection */
77
		$parserOutputHelper = new ParserOutputHelper( $parser );
78
79
		/** @noinspection PhpParamsInspection */
80
		$instance = new OutputPageParserOutput( $outputPage, $observerParserOutput, $parserOutputHelper );
81
82
		$this->assertTrue(
83
			$instance->process()
84
		);
85
		$this->assertEquals(
86
			'CONTENT<!-- injected by Extension:BootstrapComponents -->test<!-- /injected by Extension:BootstrapComponents -->',
87
			$content
88
		);
89
	}
90
}
91