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

PopoverTest::placeMeArgumentsProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 9.488
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\Popover;
6
use BootstrapComponents\Tests\Unit\ComponentsTestBase;
7
use \MWException;
8
9
/**
10
 * @covers  \BootstrapComponents\Components\Popover
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 PopoverTest extends ComponentsTestBase {
23
24
	private $input = 'Popover test text';
25
26
	/**
27
	 * @throws \MWException
28
	 */
29
	public function testCanConstruct() {
30
31
		$this->assertInstanceOf(
32
			'\\BootstrapComponents\\Components\\Popover',
33
			new Popover(
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 Popover(
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
		$this->assertEquals( $expectedOutput, $generatedOutput );
62
	}
63
64
	/**
65
	 * @return array
66
	 */
67
	public function placeMeArgumentsProvider() {
68
		return [
69
			'simple'          => [
70
				$this->input,
71
				[ 'heading' => 'heading', 'text' => 'BUTTON' ],
72
				'<button class="btn btn-info" id="bsc_popover_NULL" data-toggle="popover" title="heading" data-content="' . $this->input . '" type="submit">BUTTON</button>',
73
			],
74
			'heading empty' => [
75
				$this->input,
76
				[ 'heading' => '', 'text' => 'BUTTON' ],
77
				'bootstrap-components-popover-heading-missing',
78
			],
79
			'text missing'    => [
80
				$this->input,
81
				[ 'heading' => 'heading', 'text' => '' ],
82
				'bootstrap-components-popover-text-missing',
83
			],
84
			'all attributes'  => [
85
				$this->input,
86
				[
87
					'heading'   => 'heading', 'text' => 'BUTTON', 'class' => 'dummy nice', 'style' => 'float:right;background-color:green',
88
					'placement' => 'right', 'trigger' => 'hover', 'id' => 'cudgel', 'size' => 'sm'
89
				],
90
				'<button class="btn btn-info btn-sm dummy nice" style="float:right;background-color:green" id="cudgel" data-toggle="popover" title="heading" data-content="' . $this->input . '" data-placement="right" data-trigger="hover" type="submit">BUTTON</button>',
91
			],
92
		];
93
	}
94
}
95