r83622 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83621‎ | r83622 | r83623 >
Date:01:30, 10 March 2011
Author:neilk
Status:deferred
Tags:
Comment:
somehow committed a file with conflicts, fixing
Modified paths:
  • /trunk/extensions/UploadWizard/test/jasmine/makeLanguageSpec.php (modified) (history)

Diff [purge]

Index: trunk/extensions/UploadWizard/test/jasmine/makeLanguageSpec.php
@@ -1,4 +1,3 @@
2 -<<<<<<< .mine
32 <?php
43
54 /**
@@ -112,118 +111,4 @@
113112 require_once( "$maintenanceDir/doMaintenance.php" );
114113
115114
116 -=======
117 -<?php
118115
119 -/**
120 - * This PHP script defines the spec that the Javascript message parser should conform to.
121 - *
122 - * It does this by looking up the results of various string kinds of string parsing, with various languages,
123 - * in the current installation of MediaWiki. It then outputs a static specification, mapping expected inputs to outputs,
124 - * which can be used with the JasmineBDD framework. This specification can then be used by simply including it into
125 - * the SpecRunner.html file.
126 - *
127 - * This is similar to Michael Dale (mdale@mediawiki.org)'s parser tests, except that it doesn't look up the
128 - * API results while doing the test, so the Jasmine run is much faster (at the cost of being out of date in rare
129 - * circumstances. But mostly the parsing that we are doing in Javascript doesn't change much.)
130 - *
131 - */
132 -
133 -$maintenanceDir = dirname( dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) ) . '/maintenance';
134 -
135 -require( "$maintenanceDir/Maintenance.php" );
136 -
137 -class MakeLanguageSpec extends Maintenance {
138 -
139 - static $keyToTestArgs = array(
140 - 'undelete_short' => array(
141 - array( 0 ),
142 - array( 1 ),
143 - array( 2 ),
144 - array( 5 ),
145 - array( 21 ),
146 - array( 101 )
147 - ),
148 - 'category-subcat-count' => array(
149 - array( 0, 10 ),
150 - array( 1, 1 ),
151 - array( 1, 2 ),
152 - array( 3, 30 )
153 - )
154 - );
155 -
156 - public function __construct() {
157 - parent::__construct();
158 - $this->mDescription = "Create a JasmineBDD-compatible specification for message parsing";
159 - // add any other options here
160 - }
161 -
162 - public function execute() {
163 - list( $messages, $tests ) = $this->getMessagesAndTests();
164 - $this->writeJavascriptFile( $messages, $tests, "spec/mediawiki.language.parser.spec.data.js" );
165 - }
166 -
167 - private function getMessagesAndTests() {
168 - $messages = array();
169 - $tests = array();
170 - $wfMsgExtOptions = array( 'parsemag' );
171 - foreach ( array( 'en', 'fr', 'ar', 'jp', 'zh' ) as $languageCode ) {
172 - $wfMsgExtOptions['language'] = $languageCode;
173 - foreach ( self::$keyToTestArgs as $key => $testArgs ) {
174 - foreach ($testArgs as $args) {
175 - // get the raw template, without any transformations
176 - $template = wfMsgGetKey( $key, /* useDb */ true, $languageCode, /* transform */ false );
177 -
178 - // get the magic-parsed version with args
179 - $wfMsgExtArgs = array_merge( array( $key, $wfMsgExtOptions ), $args );
180 - $result = call_user_func_array( 'wfMsgExt', $wfMsgExtArgs );
181 -
182 - // record the template, args, language, and expected result
183 - // fake multiple languages by flattening them together
184 - $langKey = $languageCode . '_' . $key;
185 - $messages[ $langKey ] = $template;
186 - $tests[] = array(
187 - 'name' => $languageCode . " " . $key . " " . join( ",", $args ),
188 - 'key' => $langKey,
189 - 'args' => $args,
190 - 'result' => $result,
191 - 'lang' => $languageCode
192 - );
193 - }
194 - }
195 - }
196 - return array( $messages, $tests );
197 - }
198 -
199 - private function writeJavascriptFile( $messages, $tests, $dataSpecFile ) {
200 - global $argv;
201 - $arguments = count($argv) ? $argv : $_SERVER[ 'argv' ];
202 -
203 - $json = new Services_JSON;
204 - $json->pretty = true;
205 - $javascriptPrologue = "// This file stores the results from the PHP parser for certain messages and arguments,\n"
206 - . "// so we can test the equivalent Javascript libraries.\n"
207 - . '// Last generated with ' . join(' ', $arguments) . ' at ' . gmdate('c') . "\n\n";
208 - $javascriptMessages = "mediaWiki.messages.set( " . $json->encode( $messages, true ) . " );\n";
209 - $javascriptTests = 'var jasmineMsgSpec = ' . $json->encode( $tests, true ) . ";\n";
210 -
211 - $fp = fopen( $dataSpecFile, 'w' );
212 - if ( !$fp ) {
213 - die( "couldn't open $dataSpecFile for writing" );
214 - }
215 - $success = fwrite( $fp, $javascriptPrologue . $javascriptMessages . $javascriptTests );
216 - if ( !$success ) {
217 - die( "couldn't write to $dataSpecFile" );
218 - }
219 - $success = fclose( $fp );
220 - if ( !$success ) {
221 - die( "couldn't close $dataSpecFile" );
222 - }
223 - }
224 -}
225 -
226 -$maintClass = "MakeLanguageSpec";
227 -require_once( "$maintenanceDir/doMaintenance.php" );
228 -
229 -
230 ->>>>>>> .r82951

Status & tagging log