Completed
Push — master ( 777c00...f61c3d )
by GIT
05:00
created

GalleryTest::testGetName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace SRF\Tests\Unit\Formats;
4
5
use SRF\Gallery;
6
use TraditionalImageGallery;
7
use Title;
8
use SMW\Test\QueryPrinterRegistryTestCase;
9
10
/**
11
 * Tests for the SRF\Gallery class.
12
 *
13
 * @file
14
 * @since 1.8
15
 *
16
 * @ingroup SemanticResultFormats
17
 * @ingroup Test
18
 *
19
 * @group SRF
20
 * @group SMWExtension
21
 * @group ResultPrinters
22
 *
23
 * @licence GNU GPL v2+
24
 * @author Jeroen De Dauw < [email protected] >
25
 */
26
class GalleryTest extends QueryPrinterRegistryTestCase {
27
28
	private $queryResult;
29
	private $title;
30
31
	protected function setUp(): void {
32
		parent::setUp();
33
34
		$this->queryResult = $this->getMockBuilder( '\SMWQueryResult' )
35
			->disableOriginalConstructor()
36
			->getMock();
37
38
		$this->title = $this->getMockBuilder( '\Title' )
39
			->disableOriginalConstructor()
40
			->getMock();
41
42
		$this->title->expects( $this->any() )
43
			->method( 'getNamespace' )
44
			->will( $this->returnValue( NS_MAIN ) );
45
	}
46
47
	/**
48
	 * @see QueryPrinterRegistryTestCase::getFormats
49
	 *
50
	 * @since 1.8
51
	 *
52
	 * @return array
53
	 */
54
	public function getFormats() {
55
		return [ 'gallery' ];
56
	}
57
58
	/**
59
	 * @see QueryPrinterRegistryTestCase::getClass
60
	 *
61
	 * @since 1.8
62
	 *
63
	 * @return string
64
	 */
65
	public function getClass() {
66
		return 'SRF\Gallery';
67
	}
68
69
	public function testGetName() {
70
71
		$instance = new Gallery(
72
			'gallery'
73
		);
74
75
		$this->assertInternalType('string', $instance->getName());
0 ignored issues
show
Bug introduced by
Consider using $instance->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
76
77
	}
78
79
	public function testBuildResult(){
80
81
		$instance = new Gallery(
82
			'gallery'
83
		);
84
85
		$widget = $this->getMockBuilder( '\stdClass' )
86
			->disableOriginalConstructor()
87
			->setMethods( [ 'getName', 'getValue' ] )
88
			->getMock();
89
90
		$widget->expects( $this->any() )
91
			->method( 'getName' )
92
			->will( $this->returnValue( 'widget' ) );
93
94
		$widget->expects( $this->any() )
95
			->method( 'getValue' )
96
			->will( $this->returnValue( 'carousel' ) );
97
98
99
		$intro = $this->getMockBuilder( '\stdClass' )
100
			->disableOriginalConstructor()
101
			->setMethods( [ 'getName', 'getValue' ] )
102
			->getMock();
103
104
		$intro->expects( $this->any() )
105
			->method( 'getName' )
106
			->will( $this->returnValue( 'intro' ) );
107
108
		$intro->expects( $this->any() )
109
			->method( 'getValue' )
110
			->will( $this->returnValue( '<div class="gallery-intro">' ) );
111
112
113
		$outro = $this->getMockBuilder( '\stdClass' )
114
			->disableOriginalConstructor()
115
			->setMethods( [ 'getName', 'getValue' ] )
116
			->getMock();
117
118
		$outro->expects( $this->any() )
119
			->method( 'getName' )
120
			->will( $this->returnValue( 'outro' ) );
121
122
		$outro->expects( $this->any() )
123
			->method( 'getValue' )
124
			->will( $this->returnValue( '</div>' ) );
125
126
		$parameters = [
127
			$widget,
128
			$intro,
129
			$outro
130
		];
131
132
		$this->assertContains(
133
			'',
134
			$instance->getResult( $this->queryResult, $parameters, SMW_OUTPUT_HTML )
135
		);
136
	}
137
138
}
139