Addshore has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/95773


Change subject: Split HTMLCheckMatrixTest into 2 files
......................................................................

Split HTMLCheckMatrixTest into 2 files

Change-Id: I166464da3373b45564dd770feecacafacb301604
---
M tests/phpunit/includes/HTMLCheckMatrixTest.php
A tests/phpunit/includes/HTMLFormFieldTest.php
2 files changed, 106 insertions(+), 93 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/73/95773/1

diff --git a/tests/phpunit/includes/HTMLCheckMatrixTest.php 
b/tests/phpunit/includes/HTMLCheckMatrixTest.php
index 39c3959..f8f69ce 100644
--- a/tests/phpunit/includes/HTMLCheckMatrixTest.php
+++ b/tests/phpunit/includes/HTMLCheckMatrixTest.php
@@ -1,8 +1,7 @@
 <?php
 
 /**
- * Unit tests for the HTMLCheckMatrix + HTMLFormField
- * @todo the tests for the two classes could be split up
+ * Unit tests for the HTMLCheckMatrix
  */
 class HtmlCheckMatrixTest extends MediaWikiTestCase {
        static private $defaultOptions = array(
@@ -16,7 +15,7 @@
         */
        public function testPlainInstantiation() {
                try {
-                       $form = new HTMLCheckMatrix( array() );
+                       new HTMLCheckMatrix( array() );
                } catch ( MWException $e ) {
                        $this->assertInstanceOf( 
'HTMLFormFieldRequiredOptionsException', $e );
                        return;
@@ -29,97 +28,8 @@
         * @covers HTMLCheckMatrix::__construct
         */
        public function testInstantiationWithMinimumRequiredParameters() {
-               $form = new HTMLCheckMatrix( self::$defaultOptions );
+               new HTMLCheckMatrix( self::$defaultOptions );
                $this->assertTrue( true ); // form instantiation must throw 
exception on failure
        }
 
-       /**
-        * @covers HTMLFormField::validate
-        */
-       public function testValidateCallsUserDefinedValidationCallback() {
-               $called = false;
-               $field = new HTMLCheckMatrix( self::$defaultOptions + array(
-                       'validation-callback' => function() use ( &$called ) {
-                               $called = true;
-                               return false;
-                       },
-               ) );
-               $this->assertEquals( false, $this->validate( $field, array() ) 
);
-               $this->assertTrue( $called );
-       }
-
-       /**
-        * @covers HTMLFormField::validate
-        */
-       public function testValidateRequiresArrayInput() {
-               $field = new HTMLCheckMatrix( self::$defaultOptions );
-               $this->assertEquals( false, $this->validate( $field, null ) );
-               $this->assertEquals( false, $this->validate( $field, true ) );
-               $this->assertEquals( false, $this->validate( $field, 'abc' ) );
-               $this->assertEquals( false, $this->validate( $field, new 
stdClass ) );
-               $this->assertEquals( true, $this->validate( $field, array() ) );
-       }
-
-       /**
-        * @covers HTMLFormField::validate
-        */
-       public function testValidateAllowsOnlyKnownTags() {
-               $field = new HTMLCheckMatrix( self::$defaultOptions );
-               $this->assertInternalType( 'string', $this->validate( $field, 
array( 'foo' ) ) );
-       }
-
-       /**
-        * @covers HTMLFormField::validate
-        */
-       public function testValidateAcceptsPartialTagList() {
-               $field = new HTMLCheckMatrix( self::$defaultOptions );
-               $this->assertTrue( $this->validate( $field, array() ) );
-               $this->assertTrue( $this->validate( $field, array( 'c1-r1' ) ) 
);
-               $this->assertTrue( $this->validate( $field, array( 'c1-r1', 
'c1-r2', 'c2-r1', 'c2-r2' ) ) );
-       }
-
-       /**
-        * This form object actually has no visibility into what happens later 
on, but essentially
-        * if the data submitted by the user passes validate the following is 
run:
-        * foreach ( $field->filterDataForSubmit( $data ) as $k => $v ) {
-        *     $user->setOption( $k, $v );
-        * }
-        * @covers HTMLFormField::filterDataForSubmit
-        */
-       public function testValuesForcedOnRemainOn() {
-               $field = new HTMLCheckMatrix( self::$defaultOptions + array(
-                       'force-options-on' => array( 'c2-r1' ),
-               ) );
-               $expected = array(
-                       'c1-r1' => false,
-                       'c1-r2' => false,
-                       'c2-r1' => true,
-                       'c2-r2' => false,
-               );
-               $this->assertEquals( $expected, $field->filterDataForSubmit( 
array() ) );
-       }
-
-       /**
-        * @covers HTMLFormField::filterDataForSubmit
-        */
-       public function testValuesForcedOffRemainOff() {
-               $field = new HTMLCheckMatrix( self::$defaultOptions + array(
-                       'force-options-off' => array( 'c1-r2', 'c2-r2' ),
-               ) );
-               $expected = array(
-                       'c1-r1' => true,
-                       'c1-r2' => false,
-                       'c2-r1' => true,
-                       'c2-r2' => false,
-               );
-               // array_keys on the result simulates submitting all fields 
checked
-               $this->assertEquals( $expected, $field->filterDataForSubmit( 
array_keys( $expected ) ) );
-       }
-
-       protected function validate( HTMLFormField $field, $submitted ) {
-               return $field->validate(
-                       $submitted,
-                       array( self::$defaultOptions['fieldname'] => $submitted 
)
-               );
-       }
 }
diff --git a/tests/phpunit/includes/HTMLFormFieldTest.php 
b/tests/phpunit/includes/HTMLFormFieldTest.php
new file mode 100644
index 0000000..f0c7965
--- /dev/null
+++ b/tests/phpunit/includes/HTMLFormFieldTest.php
@@ -0,0 +1,103 @@
+<?php
+
+/**
+ * Unit tests for the HTMLFormField
+ */
+class HTMLFormFieldTest extends MediaWikiTestCase {
+       static private $defaultOptions = array(
+               'rows' => array( 'r1', 'r2' ),
+               'columns' => array( 'c1', 'c2' ),
+               'fieldname' => 'test',
+       );
+
+       /**
+        * @covers HTMLFormField::validate
+        */
+       public function testValidateCallsUserDefinedValidationCallback() {
+               $called = false;
+               $field = new HTMLCheckMatrix( self::$defaultOptions + array(
+                               'validation-callback' => function() use ( 
&$called ) {
+                                               $called = true;
+                                               return false;
+                                       },
+                       ) );
+               $this->assertEquals( false, $this->validate( $field, array() ) 
);
+               $this->assertTrue( $called );
+       }
+
+       /**
+        * @covers HTMLFormField::validate
+        */
+       public function testValidateRequiresArrayInput() {
+               $field = new HTMLCheckMatrix( self::$defaultOptions );
+               $this->assertEquals( false, $this->validate( $field, null ) );
+               $this->assertEquals( false, $this->validate( $field, true ) );
+               $this->assertEquals( false, $this->validate( $field, 'abc' ) );
+               $this->assertEquals( false, $this->validate( $field, new 
stdClass ) );
+               $this->assertEquals( true, $this->validate( $field, array() ) );
+       }
+
+       /**
+        * @covers HTMLFormField::validate
+        */
+       public function testValidateAllowsOnlyKnownTags() {
+               $field = new HTMLCheckMatrix( self::$defaultOptions );
+               $this->assertInternalType( 'string', $this->validate( $field, 
array( 'foo' ) ) );
+       }
+
+       /**
+        * @covers HTMLFormField::validate
+        */
+       public function testValidateAcceptsPartialTagList() {
+               $field = new HTMLCheckMatrix( self::$defaultOptions );
+               $this->assertTrue( $this->validate( $field, array() ) );
+               $this->assertTrue( $this->validate( $field, array( 'c1-r1' ) ) 
);
+               $this->assertTrue( $this->validate( $field, array( 'c1-r1', 
'c1-r2', 'c2-r1', 'c2-r2' ) ) );
+       }
+
+       /**
+        * This form object actually has no visibility into what happens later 
on, but essentially
+        * if the data submitted by the user passes validate the following is 
run:
+        * foreach ( $field->filterDataForSubmit( $data ) as $k => $v ) {
+        *     $user->setOption( $k, $v );
+        * }
+        * @covers HTMLFormField::filterDataForSubmit
+        */
+       public function testValuesForcedOnRemainOn() {
+               $field = new HTMLCheckMatrix( self::$defaultOptions + array(
+                               'force-options-on' => array( 'c2-r1' ),
+                       ) );
+               $expected = array(
+                       'c1-r1' => false,
+                       'c1-r2' => false,
+                       'c2-r1' => true,
+                       'c2-r2' => false,
+               );
+               $this->assertEquals( $expected, $field->filterDataForSubmit( 
array() ) );
+       }
+
+       /**
+        * @covers HTMLFormField::filterDataForSubmit
+        */
+       public function testValuesForcedOffRemainOff() {
+               $field = new HTMLCheckMatrix( self::$defaultOptions + array(
+                               'force-options-off' => array( 'c1-r2', 'c2-r2' 
),
+                       ) );
+               $expected = array(
+                       'c1-r1' => true,
+                       'c1-r2' => false,
+                       'c2-r1' => true,
+                       'c2-r2' => false,
+               );
+               // array_keys on the result simulates submitting all fields 
checked
+               $this->assertEquals( $expected, $field->filterDataForSubmit( 
array_keys( $expected ) ) );
+       }
+
+       protected function validate( HTMLFormField $field, $submitted ) {
+               return $field->validate(
+                       $submitted,
+                       array( self::$defaultOptions['fieldname'] => $submitted 
)
+               );
+       }
+
+} 
\ No newline at end of file

-- 
To view, visit https://gerrit.wikimedia.org/r/95773
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I166464da3373b45564dd770feecacafacb301604
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Addshore <addshorew...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to