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
107
108
109
110
|
<?php
namespace SMW\Tests\MediaWiki\Search\Form;
use SMW\MediaWiki\Search\Form\FormsBuilder;
use SMW\Tests\TestEnvironment;
/**
* @covers \SMW\MediaWiki\Search\Form\FormsBuilder
* @group semantic-mediawiki
*
* @license GNU GPL v2+
* @since 3.0
*
* @author mwjames
*/
class FormsBuilderTest extends \PHPUnit_Framework_TestCase {
private $webRequest;
private $formsFactory;
protected function setUp() {
$this->webRequest = $this->getMockBuilder( '\WebRequest' )
->disableOriginalConstructor()
->getMock();
$this->formsFactory = $this->getMockBuilder( '\SMW\MediaWiki\Search\Form\FormsFactory' )
->disableOriginalConstructor()
->getMock();
}
public function testCanConstruct() {
$this->assertInstanceOf(
FormsBuilder::class,
new FormsBuilder( $this->webRequest, $this->formsFactory )
);
}
public function testBuildForm() {
$title = $this->getMockBuilder( '\Title' )
->disableOriginalConstructor()
->getMock();
$openForm = $this->getMockBuilder( '\SMW\MediaWiki\Search\Form\OpenForm' )
->disableOriginalConstructor()
->getMock();
$customForm = $this->getMockBuilder( '\SMW\MediaWiki\Search\Form\CustomForm' )
->disableOriginalConstructor()
->getMock();
$customForm->expects( $this->any() )
->method( 'getParameters' )
->will( $this->returnValue( [] ) );
$this->formsFactory->expects( $this->any() )
->method( 'newOpenForm' )
->will( $this->returnValue( $openForm ) );
$this->formsFactory->expects( $this->any() )
->method( 'newCustomForm' )
->will( $this->returnValue( $customForm ) );
$instance = new FormsBuilder(
$this->webRequest,
$this->formsFactory
);
$data = [
'forms' => [
'Foo' => [
'Property one'
],
'Bar' => [
'Property two'
]
]
];
$expected = [
"<div class='divider' style='display:none;'></div>",
'<div id="smw-form-definitions" class="is-disabled">',
'<div id="smw-form-bar" class="smw-fields"></div>',
'<div id="smw-form-foo" class="smw-fields"></div></div>'
];
$this->assertContains(
implode( '', $expected ),
$instance->buildForm( $data )
);
$stringValidator = TestEnvironment::newValidatorFactory()->newStringValidator();
$expected = [
'<button type="button" id="smw-search-forms" class="smw-selectmenu-button is-disabled".*',
'name="smw-form" value="".*',
'data-list="[{"id":"bar","name":"Bar","desc":"Bar"},{"id":"foo","name":"Foo","desc":"Foo"}]" data-nslist="[]">Form</button><input type="hidden" name="smw-form"/>'
];
$stringValidator->assertThatStringContains(
$expected,
$instance->buildFormList( $title )
);
}
}
|