summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/MediaWiki/Specials/Ask/ParametersWidgetTest.php
blob: ffb6fb48d76972172888413b69994310b37a41a6 (plain)
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
<?php

namespace SMW\Tests\MediaWiki\Specials\Ask;

use SMW\MediaWiki\Specials\Ask\ParametersWidget;
use SMW\Tests\TestEnvironment;

/**
 * @covers \SMW\MediaWiki\Specials\Ask\ParametersWidget
 * @group semantic-mediawiki
 *
 * @license GNU GPL v2+
 * @since 2.5
 *
 * @author mwjames
 */
class ParametersWidgetTest extends \PHPUnit_Framework_TestCase {

	private $stringValidator;

	protected function setUp() {
		$testEnvironment = new TestEnvironment();

		$this->stringValidator = $testEnvironment->getUtilityFactory()->newValidatorFactory()->newStringValidator();
	}

	public function testFieldset() {

		$parameters = [];

		$this->stringValidator->assertThatStringContains(
			[
				'<fieldset><legend>.*</legend><span class="smw-ask-format-list">',
				'<input type="checkbox" id="options-toggle"/><div id="options-list" class="options-list"><div class="options-parameter-list">'
			],
			ParametersWidget::fieldset( \Title::newFromText( 'Foo' ), $parameters )
		);
	}

	/**
	 * @dataProvider parametersProvider
	 */
	public function testCreateParametersForm( $format, $parameters, $expected ) {

		$parameters['format'] = $format;

		$this->stringValidator->assertThatStringContains(
			$expected,
			ParametersWidget::parameterList( $parameters )
		);
	}

	public function parametersProvider() {

		$provider[] = [
			'',
			[],
			'<div class="smw-table smw-ask-options-list" width="100%"><div class="smw-table-row smw-ask-options-row-odd"></div></div>'
		];

		$provider[] = [
			'table',
			[],
			[
				'<div class="smw-table smw-ask-options-list" width="100%"',
				'<input class="parameter-number-input" size="6" style="width: 95%;" value="50" name="p[limit]"',
				'<input class="parameter-number-input" size="6" style="width: 95%;" value="0" name="p[offset]"'
			]
		];

		$provider[] = [
			'table',
			[
				'limit'  => 9999,
				'offset' => 42
			],
			[
				'<input class="parameter-number-input" size="6" style="width: 95%;" value="9999" name="p[limit]"',
				'<input class="parameter-number-input" size="6" style="width: 95%;" value="42" name="p[offset]"'
			]
		];

		return $provider;
	}

}