http://www.mediawiki.org/wiki/Special:Code/MediaWiki/99285

Revision: 99285
Author:   jeroendedauw
Date:     2011-10-08 00:04:58 +0000 (Sat, 08 Oct 2011)
Log Message:
-----------
added test

Modified Paths:
--------------
    trunk/extensions/Contest/Contest.hooks.php
    trunk/extensions/Contest/specials/SpecialContestSubmission.php
    trunk/extensions/Contest/specials/SpecialContestant.php

Added Paths:
-----------
    trunk/extensions/Contest/test/ContestValidationTests.php

Modified: trunk/extensions/Contest/Contest.hooks.php
===================================================================
--- trunk/extensions/Contest/Contest.hooks.php  2011-10-08 00:04:52 UTC (rev 
99284)
+++ trunk/extensions/Contest/Contest.hooks.php  2011-10-08 00:04:58 UTC (rev 
99285)
@@ -163,7 +163,7 @@
        public static function registerUnitTests( array &$files ) {
                $testDir = dirname( __FILE__ ) . '/test/';
                
-               //$files[] = $testDir . 'SurveyQuestionTest.php';
+               $files[] = $testDir . 'ContestValidationTests.php';
                
                return true;
        }

Modified: trunk/extensions/Contest/specials/SpecialContestSubmission.php
===================================================================
--- trunk/extensions/Contest/specials/SpecialContestSubmission.php      
2011-10-08 00:04:52 UTC (rev 99284)
+++ trunk/extensions/Contest/specials/SpecialContestSubmission.php      
2011-10-08 00:04:58 UTC (rev 99285)
@@ -285,7 +285,7 @@
         * 
         * @return true|string
         */
-       public function validateSubmissionField( $value, $alldata = null  ) {
+       public static function validateSubmissionField( $value, $alldata = null 
 ) {
                $allowedPatterns = array(
                        // GitHub URLs such as 
https://github.com/JeroenDeDauw/smwcon/tree/f9b26ec4ba1101b1f5d4ef76b7ae6ad3dabfb53b
                        
'@^https://github\.com/[a-zA-Z0-9-]+/[a-zA-Z0-9_-]+/tree/[a-zA-Z0-9]{40}$@i'

Modified: trunk/extensions/Contest/specials/SpecialContestant.php
===================================================================
--- trunk/extensions/Contest/specials/SpecialContestant.php     2011-10-08 
00:04:52 UTC (rev 99284)
+++ trunk/extensions/Contest/specials/SpecialContestant.php     2011-10-08 
00:04:58 UTC (rev 99285)
@@ -53,6 +53,8 @@
                        $this->displayNavigation();
                        
                        $this->showGeneralInfo( $contestant );
+                       $this->showRating();
+                       $this->showComments();
                }
        }
        
@@ -139,4 +141,27 @@
        
        // TODO: show rating and commenting controls
        
+       /**
+        * Display the current rating the judge gave if any and a control to
+        * (re)-rate.
+        * 
+        * @since 0.1
+        * 
+        * @param ContestContestant $contestant
+        */
+       protected function showRating( ContestContestant $contestant ) {
+               
+       }
+
+       /**
+        * Show the comments and a control to add additional ones.
+        * 
+        * @since 0.1
+        * 
+        * @param ContestContestant $contestant
+        */
+       protected function showComments( ContestContestant $contestant ) {
+               
+       }
+       
 }

Added: trunk/extensions/Contest/test/ContestValidationTests.php
===================================================================
--- trunk/extensions/Contest/test/ContestValidationTests.php                    
        (rev 0)
+++ trunk/extensions/Contest/test/ContestValidationTests.php    2011-10-08 
00:04:58 UTC (rev 99285)
@@ -0,0 +1,38 @@
+<?php
+
+/**
+ * Contest form field validation tests cases.
+ *
+ * @ingroup Contest
+ * @since 0.1
+ *
+ * @licence GNU GPL v3
+ * @author Jeroen De Dauw < jeroended...@gmail.com >
+ */
+class ContestValidationTests extends MediaWikiTestCase {
+
+       /**
+        * Tests 
+        */
+       public function testURLValidation() {
+               $tests = array(
+                       
'https://github.com/JeroenDeDauw/smwcon/tree/f9b26ec4ba1101b1f5d4ef76b7ae6ad3dabfb53b'
 => true,
+                       
'https://github.com/Jeroen-De-Dauw42/smwcon_-42/tree/f9b26ec4ba1101b1f5d4ef76b7ae6ad3dabfb53b'
 => true,
+                       
'https://github.com/JeroenDeDauw$/smwcon/tree/f9b26ec4ba1101b1f5d4ef76b7ae6ad3dabfb53b'
 => false,
+                       
'https://github.com/JeroenDeDauw/smwcon/tree3/f9b26ec4ba1101b1f5d4ef76b7ae6ad3dabfb53b'
 => false,
+                       
'https://github.com/JeroenDeDauw/smwcon/tree/f9b26ec4ba1101b1f5d4ef76b7ae6ad3dabfb53'
 => false,
+                       
'https://github.com/JeroenDeDauw/smwcon/tree/f9b26ec4ba1101b1f5d4ef76b7ae6ad3dabfb53ba'
 => false,
+                       
'https://github.com/JeroenDeDauw/smwc*/tree/f9b26ec4ba1101b1f5d4ef76b7ae6ad3dabfb53b'
 => false,
+               );
+               
+               foreach ( $tests as $test => $isValdid ) {
+                       if ( $isValdid ) {
+                               $this->assertEquals( true, 
SpecialContestSubmission::validateSubmissionField( $test ) );
+                       }
+                       else {
+                               $this->assertFalse( 
SpecialContestSubmission::validateSubmissionField( $test ) === true );
+                       }
+               }
+       }
+
+}


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

Reply via email to