MediaWiki  1.23.12
HTMLCheckMatrixTest.php
Go to the documentation of this file.
1 <?php
2 
8  static private $defaultOptions = array(
9  'rows' => array( 'r1', 'r2' ),
10  'columns' => array( 'c1', 'c2' ),
11  'fieldname' => 'test',
12  );
13 
14  public function testPlainInstantiation() {
15  try {
16  new HTMLCheckMatrix( array() );
17  } catch ( MWException $e ) {
18  $this->assertInstanceOf( 'HTMLFormFieldRequiredOptionsException', $e );
19  return;
20  }
21 
22  $this->fail( 'Expected MWException indicating missing parameters but none was thrown.' );
23  }
24 
27  $this->assertTrue( true ); // form instantiation must throw exception on failure
28  }
29 
31  $called = false;
33  'validation-callback' => function() use ( &$called ) {
34  $called = true;
35  return false;
36  },
37  ) );
38  $this->assertEquals( false, $this->validate( $field, array() ) );
39  $this->assertTrue( $called );
40  }
41 
42  public function testValidateRequiresArrayInput() {
43  $field = new HTMLCheckMatrix( self::$defaultOptions );
44  $this->assertEquals( false, $this->validate( $field, null ) );
45  $this->assertEquals( false, $this->validate( $field, true ) );
46  $this->assertEquals( false, $this->validate( $field, 'abc' ) );
47  $this->assertEquals( false, $this->validate( $field, new stdClass ) );
48  $this->assertEquals( true, $this->validate( $field, array() ) );
49  }
50 
51  public function testValidateAllowsOnlyKnownTags() {
52  $field = new HTMLCheckMatrix( self::$defaultOptions );
53  $this->assertInternalType( 'string', $this->validate( $field, array( 'foo' ) ) );
54  }
55 
57  $field = new HTMLCheckMatrix( self::$defaultOptions );
58  $this->assertTrue( $this->validate( $field, array() ) );
59  $this->assertTrue( $this->validate( $field, array( 'c1-r1' ) ) );
60  $this->assertTrue( $this->validate( $field, array( 'c1-r1', 'c1-r2', 'c2-r1', 'c2-r2' ) ) );
61  }
62 
70  public function testValuesForcedOnRemainOn() {
72  'force-options-on' => array( 'c2-r1' ),
73  ) );
74  $expected = array(
75  'c1-r1' => false,
76  'c1-r2' => false,
77  'c2-r1' => true,
78  'c2-r2' => false,
79  );
80  $this->assertEquals( $expected, $field->filterDataForSubmit( array() ) );
81  }
82 
83  public function testValuesForcedOffRemainOff() {
85  'force-options-off' => array( 'c1-r2', 'c2-r2' ),
86  ) );
87  $expected = array(
88  'c1-r1' => true,
89  'c1-r2' => false,
90  'c2-r1' => true,
91  'c2-r2' => false,
92  );
93  // array_keys on the result simulates submitting all fields checked
94  $this->assertEquals( $expected, $field->filterDataForSubmit( array_keys( $expected ) ) );
95  }
96 
97  protected function validate( HTMLFormField $field, $submitted ) {
98  return $field->validate(
99  $submitted,
100  array( self::$defaultOptions['fieldname'] => $submitted )
101  );
102  }
103 
104 }
HtmlCheckMatrixTest\testValuesForcedOffRemainOff
testValuesForcedOffRemainOff()
Definition: HTMLCheckMatrixTest.php:83
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
HtmlCheckMatrixTest\testPlainInstantiation
testPlainInstantiation()
Definition: HTMLCheckMatrixTest.php:14
HtmlCheckMatrixTest\testValidateAcceptsPartialTagList
testValidateAcceptsPartialTagList()
Definition: HTMLCheckMatrixTest.php:56
$defaultOptions
return false to override stock group addition can be modified try getUserPermissionsErrors userCan checks are continued by internal code can override on output return false to not delete it return false to override the default password checks this Boolean value will be checked to determine if the password was valid return false to implement your own hashing method this String will be used as the hash which may be added to this hook is run right before returning the options to the caller which means it s potentially called dozens or hundreds of times You may want to cache the results of non trivial operations in your hook function for this reason & $defaultOptions
Definition: hooks.txt:2702
HtmlCheckMatrixTest\testInstantiationWithMinimumRequiredParameters
testInstantiationWithMinimumRequiredParameters()
Definition: HTMLCheckMatrixTest.php:25
HTMLFormField\validate
validate( $value, $alldata)
Override this function to add specific validation checks on the field input.
Definition: HTMLFormField.php:73
fail
as a message key or array as accepted by ApiBase::dieUsageMsg after processing request parameters Return false to let the request fail
Definition: hooks.txt:375
MediaWikiTestCase\$called
$called
$called tracks whether the setUp and tearDown method has been called.
Definition: MediaWikiTestCase.php:20
MWException
MediaWiki exception.
Definition: MWException.php:26
MediaWikiTestCase
Definition: MediaWikiTestCase.php:6
HTMLFormField
The parent class to generate form fields.
Definition: HTMLFormField.php:7
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
HtmlCheckMatrixTest\testValidateAllowsOnlyKnownTags
testValidateAllowsOnlyKnownTags()
Definition: HTMLCheckMatrixTest.php:51
HtmlCheckMatrixTest\validate
validate(HTMLFormField $field, $submitted)
Definition: HTMLCheckMatrixTest.php:97
HtmlCheckMatrixTest\testValidateRequiresArrayInput
testValidateRequiresArrayInput()
Definition: HTMLCheckMatrixTest.php:42
HtmlCheckMatrixTest\$defaultOptions
static $defaultOptions
Definition: HTMLCheckMatrixTest.php:8
HtmlCheckMatrixTest\testValuesForcedOnRemainOn
testValuesForcedOnRemainOn()
This form object actually has no visibility into what happens later on, but essentially if the data s...
Definition: HTMLCheckMatrixTest.php:70
HtmlCheckMatrixTest\testValidateCallsUserDefinedValidationCallback
testValidateCallsUserDefinedValidationCallback()
Definition: HTMLCheckMatrixTest.php:30
HtmlCheckMatrixTest
Unit tests for the HTMLCheckMatrix @covers HTMLCheckMatrix.
Definition: HTMLCheckMatrixTest.php:7
HTMLCheckMatrix
A checkbox matrix Operates similarly to HTMLMultiSelectField, but instead of using an array of option...
Definition: HTMLCheckMatrix.php:24
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:1632