Completed
Push — master ( 552173...c8702c )
by Tobias
12:00 queued 43s
created

CarouselTest::testCanRender()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
cc 2
eloc 15
nc 2
nop 3
1
<?php
2
3
namespace BootstrapComponents\Tests\Unit\Components;
4
5
use BootstrapComponents\Components\Carousel;
6
use BootstrapComponents\Tests\Unit\ComponentsTestBase;
7
use \MWException;
8
9
/**
10
 * @covers  \BootstrapComponents\Components\Carousel
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 CarouselTest extends ComponentsTestBase {
23
24
	private $input = 'Botched input';
25
26
	/**
27
	 * @throws \MWException
28
	 */
29
	public function testCanConstruct() {
30
31
		$this->assertInstanceOf(
32
			'BootstrapComponents\\Components\\Carousel',
33
			new Carousel(
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 Carousel(
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
			$this->assertEquals(
63
				[ 0 => $expectedOutput, "isHTML" => true, "noparse" => true, ],
64
				$generatedOutput
65
			);
66
		} else {
67
			$this->assertEquals(
68
				$expectedOutput,
69
				$generatedOutput
70
			);
71
		}
72
	}
73
74
	/**
75
	 * @return array
76
	 */
77
	public function placeMeArgumentsProvider() {
78
		return [
79
			'simple'               => [
80
				'[[File:Mal.jpg|Malcolm Reynolds_0]]',
81
				[ '[[File:Mal.jpg|Malcolm Reynolds]]' => true, '[[File:Wash.jpg|link' => '|Hoban Washburne]]' ],
82
				'<div class="carousel slide" id="bsc_carousel_NULL" data-ride="carousel">
83
<ol class="carousel-indicators">
84
	<li data-target="#bsc_carousel_NULL" data-slide-to="0" class="active"></li>
85
	<li data-target="#bsc_carousel_NULL" data-slide-to="1"></li>
86
	<li data-target="#bsc_carousel_NULL" data-slide-to="2"></li>
87
</ol>
88
<div class="carousel-inner">
89
	<div class="item active">[[File:Mal.jpg|Malcolm Reynolds_0]]</div>
90
	<div class="item">[[File:Mal.jpg|Malcolm Reynolds]]</div>
91
	<div class="item">[[File:Wash.jpg|link=|Hoban Washburne]]</div>
92
</div><a class="left carousel-control" href="#bsc_carousel_NULL" data-slide="prev"><span class="glyphicon glyphicon-chevron-left"></span></a><a class="right carousel-control" href="#bsc_carousel_NULL" data-slide="next"><span class="glyphicon glyphicon-chevron-right"></span></a></div>',
93
			],
94
			'images missing'       => [
95
				$this->input,
96
				[ 'class' => 'no_images' ],
97
				'bootstrap-components-carousel-images-missing',
98
			],
99
			'id, style, and class' => [
100
				$this->input,
101
				[
102
					'[[File:Mal.jpg|Malcolm Reynolds]]' => true, '[[File:Wash.jpg|link' => '|Hoban Washburne]]', 'class' => 'crew',
103
					'style'                             => 'float:none;background-color:black',
104
				],
105
				'<div class="carousel slide crew" style="float:none;background-color:black" id="bsc_carousel_NULL" data-ride="carousel">
106
<ol class="carousel-indicators">
107
	<li data-target="#bsc_carousel_NULL" data-slide-to="0" class="active"></li>
108
	<li data-target="#bsc_carousel_NULL" data-slide-to="1"></li>
109
</ol>
110
<div class="carousel-inner">
111
	<div class="item active">[[File:Mal.jpg|Malcolm Reynolds]]</div>
112
	<div class="item">[[File:Wash.jpg|link=|Hoban Washburne]]</div>
113
</div><a class="left carousel-control" href="#bsc_carousel_NULL" data-slide="prev"><span class="glyphicon glyphicon-chevron-left"></span></a><a class="right carousel-control" href="#bsc_carousel_NULL" data-slide="next"><span class="glyphicon glyphicon-chevron-right"></span></a></div>',
114
			],
115
		];
116
	}
117
}
118