Photon

Photon Commit Details

Date:2011-03-03 14:34:31 (3 years 4 months ago)
Author:Loïc d'Anterroches
Branch:develop, feature.composer, master
Commit:9bed188e51bf09d02661f79fd6b415393772d5af
Parents: 37ed7febf8cc7fd1af62127d39c7c6399fa6d69d
Message:Added another series of widget tests.

Changes:
Mbuild/package.xml (1 diff)
Msrc/photon/datetime.php (2 diffs)
Msrc/photon/form/widget.php (4 diffs)
Msrc/photon/tests/form/widgetTest.php (2 diffs)

File differences

build/package.xml
7878
7979
8080
81
8182
8283
8384
<file name="photon/tests/data/dummyapp/locale/fr/dummyapp.po" role="php" />
<file name="photon/tests/http/500.html" role="php" />
<file name="photon/tests/http/baseTest.php" role="php" />
<file name="photon/tests/http/responseTest.php" role="php" />
<file name="photon/tests/http/cookiesTest.php" role="php" />
<file name="photon/tests/http/multipartparserTest.php" role="php" />
<file name="photon/tests/mongrel2/mongrel2Test.php" role="php" />
src/photon/datetime.php
9393
9494
9595
96
97
98
99
100
96101
97102
98103
......
159164
160165
161166
162
163
164
165
166
167
168
169
167
170168
171
172
173
169
174170
175
176171
177172
178173
$date = new \DateTime($this->y . '-' . $this->m . '-' . $this->d, $tz);
return $date->format($format);
}
public function __toString()
{
return $this->format('Y-m-d');
}
}
return self::createFromFormat('Y-m-d H:i:s', $date);
}
/**
* Format a date.
*
* @param $format
* @return string Formatted date
*/
/*
public function format($format)
public function __toString()
{
$tz = new \DateTimeZone('UTC');
$date = new \DateTime($this->y . '-' . $this->m . '-' . $this->d, $tz);
return $date->format($format);
return $this->format('Y-m-d H:i:s');
}
*/
}
/**
src/photon/form/widget.php
208208
209209
210210
211
212
213
214
215
216
217
218
219211
220212
221
222
223
224
213
214
215
225216
226217
227218
228219
229220
230
231
232221
233222
234223
......
242231
243232
244233
245
246234
247235
248
249
250236
251237
252238
......
256242
257243
258244
259
260
261
262
263
264245
265246
266247
......
286267
287268
288269
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375270
376271
377272
public $format = 'Y-m-d H:i'; // '2006-10-25 14:30' by default do
// not show the seconds.
/**
* Renders the HTML of the input.
*
* @param string Name of the field.
* @param mixed Value for the field, can be a non valid value.
* @param array Extra attributes to add to the input form (array())
* @return string The HTML string of the input.
*/
public function render($name, $value, $extra_attrs=array())
{
// Internally we use GMT, so we convert back to the current
// timezone.
if (strlen($value) > 0) {
$value = date($this->format, strtotime($value.' GMT'));
if (is_object($value)
&& 'photon\datetime\DateTime' === get_class($value)) {
$value = $value->format($this->format);
}
return parent::render($name, $value, $extra_attrs);
}
}
/**
* Simple input of type file.
*/
$value = '';
return parent::render($name, $value, $extra_attrs);
}
}
/**
* Simple input of type text.
*/
public $is_hidden = true;
}
/**
* Simple input of type text.
*/
}
/**
* reCAPTCHA input for your forms.
*
* Based on http://recaptcha.googlecode.com/files/recaptcha-php-1.10.zip
*
* Copyright (c) 2007 reCAPTCHA -- http://recaptcha.net
* AUTHORS:
* Mike Crawford
* Ben Maurer
*
* @see Pluf_Form_Field_ReCaptcha
*
*/
class ReCaptcha extends Input
{
public $input_type = 'text';
public $ssl = false;
public $pubkey = '';
/**
* Renders the HTML of the input.
*
* @param string Name of the field.
* @param mixed Value for the field, can be a non valid value.
* @param array Extra attributes to add to the input form (array())
* @return string The HTML string of the input.
*/
public function render($name, $value, $extra_attrs=array())
{
return Pluf_Template::markSafe(self::getHtml($this->attrs['pubkey']));
}
/**
* Gets the challenge HTML (javascript and non-javascript
* version). This is called from the browser, and the resulting
* reCAPTCHA HTML widget is embedded within the HTML form it was
* called from.
*
* @param string A public key for reCAPTCHA
* @param string The error given by reCAPTCHA (null)
* @param boolean Should the request be made over ssl? (false)
* @return string The HTML to be embedded in the user's form.
*/
public static function getHtml($pubkey, $error=null, $use_ssl=false)
{
$server = ($use_ssl) ? 'https://api-secure.recaptcha.net'
: 'http://api.recaptcha.net';
$errorpart = ($error) ? '&amp;error='.$error : '';
return '<script type="text/javascript" src="'.$server.'/challenge?k='
.$pubkey.$errorpart.'"></script>
<noscript>
<iframe src="'.$server.'/noscript?k='.$pubkey.$errorpart
.'" height="300" width="500" frameborder="0"></iframe><br/>
<textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
<input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>
</noscript>';
}
/**
* Get the form data from the reCaptcha fields.
*
* We need to get back two fields from the POST request
* 'recaptcha_challenge_field' and 'recaptcha_response_field'.
*
* They are hardcoded, so we do not even bother checking something
* else.
*
* @param string Name of the form
* @param array Submitted form data
* @return array Challenge and answer
*/
public function valueFromFormData($name, $data)
{
$res = array('', '');
$res[0] = isset($data['recaptcha_challenge_field'])
? $data['recaptcha_challenge_field'] : '';
$res[1] = isset($data['recaptcha_response_field'])
? $data['recaptcha_response_field'] : '';
return $res;
}
}
/**
* Simple checkbox with grouping.
*/
src/photon/tests/form/widgetTest.php
3131
3232
3333
34
35
36
37
38
39
40
41
42
43
44
45
3446
3547
3648
......
5971
6072
6173
74
6275
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
6391
6492
93
94
95
96
97
98
99
65100
class WidgetTest extends \PHPUnit_Framework_TestCase
{
protected $timezone;
public function setUp()
{
$this->timezone = date_default_timezone_get();
date_default_timezone_set('UTC');
}
public function tearDown()
{
date_default_timezone_set($this->timezone);
}
public function testWidget()
{
$widget = new widget\Widget();
}
$this->assertSame(false, $widget->valueFromFormData('bar', $in_data));
$this->assertEquals('<input name="on" type="checkbox" checked="checked" value="on" />', (string) $widget->render('on', 'on'));
}
public function testDatetimeInput()
{
$widget = new widget\DatetimeInput();
$datetime = new \photon\datetime\DateTime('2000-01-01');
$this->assertEquals('<input name="datetime" type="text" value="2000-01-01 00:00" />', (string) $widget->render('datetime', $datetime));
$this->assertEquals('<input name="datetime" type="text" />', (string) $widget->render('datetime', null));
}
public function testPasswordInput()
{
$widget = new widget\PasswordInput();
$this->assertEquals('<input name="password1" type="password" />', (string) $widget->render('password1', null));
$this->assertEquals('<input name="password1" type="password" value="foo" />', (string) $widget->render('password1', 'foo'));
$widget = new widget\PasswordInput(array('render_value'=>false));
$this->assertEquals('<input name="password1" type="password" />', (string) $widget->render('password1', 'foo'));
}
public function testFileInput()
{
$widget = new widget\FileInput();
$this->assertEquals('<input name="file1" type="file" />', (string) $widget->render('file1', null));
$this->assertEquals('<input name="file1" type="file" />', (string) $widget->render('file1', 'foo'));
}
}

Archive Download the corresponding diff file