1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
<?php
namespace SMW\Tests\MediaWiki\Search\Form;
use SMW\MediaWiki\Search\Form\Field;
/**
* @covers \SMW\MediaWiki\Search\Form\Field
* @group semantic-mediawiki
*
* @license GNU GPL v2+
* @since 3.0
*
* @author mwjames
*/
class FieldTest extends \PHPUnit_Framework_TestCase {
public function testTooltip() {
$instance = new Field();
$this->assertContains(
'Foo ... bar',
$instance->tooltip( [ 'tooltip' => 'Foo ... bar' ] )
);
}
public function testCreate() {
$instance = new Field();
$this->assertContains(
'smw-input-field',
$instance->create( 'input', [] )
);
$this->assertContains(
'smw-select',
$instance->create( 'select', [] )
);
}
public function testSelect() {
$instance = new Field();
$attr = [
'list' => [
'A' => 'Foo',
'B' => [ 42, 'disabled' ]
],
'name' => 'Foobar'
];
$html = $instance->select( $attr );
$this->assertContains(
'<select name="Foobar">',
$html
);
$this->assertContains(
"<option value='A'>Foo</option>",
$html
);
$this->assertContains(
"<option value='B' disabled>42</option>",
$html
);
}
/**
* @dataProvider inputAttributeProvider
*/
public function testInput( $attr, $expected ) {
$instance = new Field();
$this->assertContains(
$expected,
$instance->input( $attr )
);
}
public function inputAttributeProvider() {
yield [
[ 'name' => 'Foobar' ],
'<div class="smw-input-field"><input name="Foobar" placeholder=""/></div>'
];
yield [
[ 'name' => 'Foobar', 'multifield' => true ],
'<div class="smw-input-field"><input name="Foobar[]" placeholder=""/></div>'
];
}
}
|