aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/htmlform/HTMLFormFieldTest.php
diff options
context:
space:
mode:
authorFunc <Funcer@outlook.com>2022-02-07 08:18:40 +0000
committerFunc <Funcer@outlook.com>2022-02-08 09:39:41 +0000
commit294b75c55958a5c3d1c74e06e9314416ec00d4bf (patch)
tree68fa5e4314df2565556ee0050897bf2fddd04ec8 /tests/phpunit/includes/htmlform/HTMLFormFieldTest.php
parentc6ca47570f4f0381f9beb0dede0eca0bc53667ab (diff)
downloadmediawikicore-294b75c55958a5c3d1c74e06e9314416ec00d4bf.tar.gz
mediawikicore-294b75c55958a5c3d1c74e06e9314416ec00d4bf.zip
HTMLFormFieldTest: Add more tests about field cloner
Change-Id: Ie8539ec2fdfc29b166737f9715ed05b7abf3316f
Diffstat (limited to 'tests/phpunit/includes/htmlform/HTMLFormFieldTest.php')
-rw-r--r--tests/phpunit/includes/htmlform/HTMLFormFieldTest.php72
1 files changed, 71 insertions, 1 deletions
diff --git a/tests/phpunit/includes/htmlform/HTMLFormFieldTest.php b/tests/phpunit/includes/htmlform/HTMLFormFieldTest.php
index fafc9af0fabd..c89884fbdb7f 100644
--- a/tests/phpunit/includes/htmlform/HTMLFormFieldTest.php
+++ b/tests/phpunit/includes/htmlform/HTMLFormFieldTest.php
@@ -36,12 +36,20 @@ class HTMLFormFieldTest extends PHPUnit\Framework\TestCase {
$this->expectException( $exception[0] );
$this->expectExceptionMessageMatches( $exception[1] );
}
- $form = $this->getNewForm( wfArrayPlus2d( $fieldInfo, [
+ $form = $this->getNewForm( array_merge_recursive( $fieldInfo, [
'check1' => [ 'type' => 'check' ],
'check2' => [ 'type' => 'check', 'invert' => true ],
'check3' => [ 'type' => 'check', 'name' => 'foo' ],
'select1' => [ 'type' => 'select', 'options' => [ 'a' => 'a', 'b' => 'b', 'c' => 'c' ], 'default' => 'b' ],
'text1' => [ 'type' => 'text' ],
+ 'cloner' => [
+ 'class' => HTMLFormFieldCloner::class,
+ 'fields' => [
+ 'check1' => [ 'type' => 'check' ],
+ 'check2' => [ 'type' => 'check', 'invert' => true ],
+ 'check3' => [ 'type' => 'check', 'name' => 'foo' ],
+ ]
+ ]
] ), $requestData );
$callback( $form, $form->mFieldData );
}
@@ -295,6 +303,68 @@ class HTMLFormFieldTest extends PHPUnit\Framework\TestCase {
'callback' => null,
'exception' => [ DomainException::class, '/no field named foo/' ],
];
+
+ yield 'Field disabled in cloner if "check" field is checked' => [
+ 'fieldInfo' => [
+ 'cloner' => [ 'fields' => [
+ 'check2' => [ 'disable-if' => [ '===', 'check1', '1' ] ],
+ ] ]
+ ],
+ 'requestData' => [
+ 'wpcloner' => [ 0 => [ 'check1' => '1' ] ],
+ ],
+ 'callback' => function ( $form, $fieldData ) {
+ $this->assertTrue( $this->getFieldInCloner( $form, 'cloner', 0, 'check2' )
+ ->isDisabled( $fieldData ) );
+ }
+ ];
+ yield 'Field disabled in cloner if "check" (invert) field is checked' => [
+ 'fieldInfo' => [
+ 'cloner' => [ 'fields' => [
+ 'check1' => [ 'disable-if' => [ '===', 'check2', '1' ] ],
+ ] ]
+ ],
+ 'requestData' => [
+ 'wpcloner' => [ 0 => [ 'check2' => '1' ] ],
+ ],
+ 'callback' => function ( $form, $fieldData ) {
+ $this->assertTrue( $this->getFieldInCloner( $form, 'cloner', 0, 'check1' )
+ ->isDisabled( $fieldData ) );
+ }
+ ];
+ yield 'Field disabled in cloner if "check" (named) field is checked' => [
+ 'fieldInfo' => [
+ 'cloner' => [ 'fields' => [
+ 'check1' => [ 'disable-if' => [ '===', 'check3', '1' ] ],
+ ] ]
+ ],
+ 'requestData' => [
+ 'wpcloner' => [ 0 => [ 'foo' => '1' ] ],
+ ],
+ 'callback' => function ( $form, $fieldData ) {
+ $this->assertTrue( $this->getFieldInCloner( $form, 'cloner', 0, 'check1' )
+ ->isDisabled( $fieldData ) );
+ }
+ ];
+ yield 'Field disabled in cloner if "select" (outside) field has value' => [
+ 'fieldInfo' => [
+ 'cloner' => [ 'fields' => [
+ 'check1' => [ 'disable-if' => [ '===', 'select1', 'a' ] ],
+ ] ]
+ ],
+ 'requestData' => [
+ 'wpselect1' => 'a',
+ ],
+ 'callback' => function ( $form, $fieldData ) {
+ $this->assertTrue( $this->getFieldInCloner( $form, 'cloner', 0, 'check1' )
+ ->isDisabled( $fieldData ) );
+ }
+ ];
+ }
+
+ private function getFieldInCloner( $form, $clonerName, $index, $fieldName ) {
+ $cloner = TestingAccessWrapper::newFromObject( $form->getField( $clonerName ) );
+ return $cloner->getFieldsForKey( $index )[$fieldName];
}
/**