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
100
101
102
103
104
105
106
|
<?php
namespace SMW\Tests\MediaWiki\Specials\Ask;
use SMW\MediaWiki\Specials\Ask\ParameterInput;
use SMW\Tests\TestEnvironment;
/**
* @covers \SMW\MediaWiki\Specials\Ask\ParameterInput
* @group semantic-mediawiki
*
* @license GNU GPL v2+
* @since 3.0
*
* @author mwjames
*/
class ParameterInputTest extends \PHPUnit_Framework_TestCase {
public function testCanConstruct() {
$paramDefinition = $this->getMockBuilder( '\ParamProcessor\ParamDefinition' )
->disableOriginalConstructor()
->getMock();
$this->assertInstanceOf(
ParameterInput::class,
new ParameterInput( $paramDefinition, '' )
);
}
/**
* @dataProvider listValueProvider
*/
public function testGetHtmlOnCheckboxList( $currentValue, $allowedValues, $expected ) {
$stringValidator = TestEnvironment::newValidatorFactory()->newStringValidator();
$paramDefinition = $this->getMockBuilder( '\ParamProcessor\ParamDefinition' )
->disableOriginalConstructor()
->getMock();
$paramDefinition->expects( $this->atLeastOnce() )
->method( 'getAllowedValues' )
->will( $this->returnValue( $allowedValues ) );
$paramDefinition->expects( $this->any() )
->method( 'isList' )
->will( $this->returnValue( true ) );
$instance = new ParameterInput(
$paramDefinition,
$currentValue
);
$stringValidator->assertThatStringContains(
$expected,
$instance->getHtml()
);
}
public function listValueProvider() {
$provider[] = [
'Foo',
[ 'Foo', 'Bar' ],
[
'<span class="parameter-checkbox-input" style="white-space: nowrap; padding-right: 5px;"><input type="checkbox" name="[]" value="Foo" checked="".*><tt>Foo</tt></span>',
'<span class="parameter-checkbox-input" style="white-space: nowrap; padding-right: 5px;"><input type="checkbox" name="[]" value="Bar".*><tt>Bar</tt></span>'
],
];
$provider[] = [
[ 'Foo' ],
[ 'Foo', 'Bar' ],
[
'<span class="parameter-checkbox-input" style="white-space: nowrap; padding-right: 5px;"><input type="checkbox" name="[]" value="Foo" checked="".*><tt>Foo</tt></span>',
'<span class="parameter-checkbox-input" style="white-space: nowrap; padding-right: 5px;"><input type="checkbox" name="[]" value="Bar".*><tt>Bar</tt></span>'
],
];
$provider[] = [
[ 'Foo, Bar' ],
[ 'Foo', 'Bar' ],
[
'<span class="parameter-checkbox-input" style="white-space: nowrap; padding-right: 5px;"><input type="checkbox" name="[]" value="Foo" checked="".*><tt>Foo</tt></span>',
'<span class="parameter-checkbox-input" style="white-space: nowrap; padding-right: 5px;"><input type="checkbox" name="[]" value="Bar" checked="".*><tt>Bar</tt></span>'
],
];
$provider[] = [
[ 'Foo,foo bar' ],
[ 'Foo', 'foo bar' ],
[
'<span class="parameter-checkbox-input" style="white-space: nowrap; padding-right: 5px;"><input type="checkbox" name="[]" value="Foo" checked="".*><tt>Foo</tt></span>',
'<span class="parameter-checkbox-input" style="white-space: nowrap; padding-right: 5px;"><input type="checkbox" name="[]" value="foo bar" checked="".*><tt>foo bar</tt></span>'
],
];
return $provider;
}
}
|