Completed
Push — master ( eadb3e...25e675 )
by
unknown
10:12
created

TooltipTest::placeMeArgumentsProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 9.536
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace BootstrapComponents\Tests\Unit\Components;
4
5
use BootstrapComponents\Components\Tooltip;
6
use BootstrapComponents\Tests\Unit\ComponentsTestBase;
7
use \MWException;
8
9
/**
10
 * @covers  \BootstrapComponents\Components\Tooltip
11
 *
12
 * @ingroup Test
13
 *
14
 * @group extension-bootstrap-components
15
 * @group mediawiki-databaseless
16
 *
17
 * @license GNU GPL v3+
18
 *
19
 * @since   1.0
20
 * @author  Tobias Oetterer
21
 */
22
class TooltipTest extends ComponentsTestBase {
23
24
	private $input = 'Tooltip test text';
25
26
	/**
27
	 * @throws \MWException
28
	 */
29
	public function testCanConstruct() {
30
31
		$this->assertInstanceOf(
32
			'\\BootstrapComponents\\Components\\Tooltip',
33
			new Tooltip(
34
				$this->getComponentLibrary(),
35
				$this->getParserOutputHelper(),
36
				$this->getNestingController()
37
			)
38
		);
39
	}
40
41
	/**
42
	 * @param string $input
43
	 * @param array  $arguments
44
	 * @param string $expectedOutput
45
	 *
46
	 * @dataProvider placeMeArgumentsProvider
47
	 * @throws MWException
48
	 */
49
	public function testCanRender( $input, $arguments, $expectedOutput ) {
50
		$instance = new Tooltip(
51
			$this->getComponentLibrary(),
52
			$this->getParserOutputHelper(),
53
			$this->getNestingController()
54
		);
55
56
		$parserRequest = $this->buildParserRequest( $input, $arguments );
57
58
		/** @noinspection PhpParamsInspection */
59
		$generatedOutput = $instance->parseComponent( $parserRequest );
60
61
		if ( is_array( $generatedOutput ) ) {
62
			$generatedOutput = $generatedOutput[0];
63
		}
64
65
		$this->assertEquals( $expectedOutput, $generatedOutput );
66
	}
67
68
	/**
69
	 * @return array
70
	 */
71
	public function placeMeArgumentsProvider() {
72
		return [
73
			'simple'              => [
74
				$this->input,
75
				[ 'text' => 'simple' ],
76
				'<span class="bootstrap-tooltip" id="bsc_tooltip_NULL" data-toggle="tooltip" title="simple">' . $this->input . '</span>',
77
			],
78
			'empty'               => [
79
				'',
80
				[],
81
				'bootstrap-components-tooltip-target-missing',
82
			],
83
			'text missing'        => [
84
				$this->input,
85
				[],
86
				'bootstrap-components-tooltip-content-missing',
87
			],
88
			'id, style and class' => [
89
				$this->input,
90
				[ 'text' => 'simple', 'class' => 'dummy nice', 'style' => 'float:right;background-color:#80266e', 'id' => 'vera' ],
91
				'<span class="bootstrap-tooltip dummy nice" style="float:right;background-color:#80266e" id="vera" data-toggle="tooltip" title="simple">' . $this->input . '</span>',
92
			],
93
		];
94
	}
95
}
96