[Jifty-commit] r2263 - in jifty/branches/template-declare: .
lib/Jifty/Web/Form share/web/templates/__jifty/webservices
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Sat Dec 2 10:44:56 EST 2006
Author: audreyt
Date: Sat Dec 2 10:44:54 2006
New Revision: 2263
Added:
jifty/branches/template-declare/share/web/templates/__jifty/webservices/json
Modified:
jifty/branches/template-declare/ (props changed)
jifty/branches/template-declare/AUTHORS
jifty/branches/template-declare/Makefile.PL
jifty/branches/template-declare/lib/Jifty/Web/Form/Field.pm
jifty/branches/template-declare/t/06-forms.t
Log:
* Merge down into template-declare branch.
Modified: jifty/branches/template-declare/AUTHORS
==============================================================================
--- jifty/branches/template-declare/AUTHORS (original)
+++ jifty/branches/template-declare/AUTHORS Sat Dec 2 10:44:54 2006
@@ -20,3 +20,4 @@
Edmund von der Burg <evdb at ecclestoad.co.uk>
Yves Agostini <agostini at univ-metz.fr>
Agent Zhang <agentzh at gmail.com>
+Pawel Murias <pmurias at woobling.org>
Modified: jifty/branches/template-declare/Makefile.PL
==============================================================================
--- jifty/branches/template-declare/Makefile.PL (original)
+++ jifty/branches/template-declare/Makefile.PL Sat Dec 2 10:44:54 2006
@@ -59,6 +59,8 @@
requires('SQL::ReservedWords');
requires('Template::Declare');
requires('Test::Base');
+requires('Test::MockModule' => '0.05');
+requires('Test::MockObject' => '1.07');
requires('UNIVERSAL::require');
requires('URI');
requires('XML::Writer' => '0.601');
Modified: jifty/branches/template-declare/lib/Jifty/Web/Form/Field.pm
==============================================================================
--- jifty/branches/template-declare/lib/Jifty/Web/Form/Field.pm (original)
+++ jifty/branches/template-declare/lib/Jifty/Web/Form/Field.pm Sat Dec 2 10:44:54 2006
@@ -164,6 +164,10 @@
canonicalized before the action is run, whether or not they also
C<ajax_canonicalize>
+=head2 preamble [VALUE]
+
+Gets or sets the preamble located in front of the field.
+
=head2 id
For the purposes of L<Jifty::Web::Form::Element>, the unique id of
@@ -412,7 +416,7 @@
sub render_preamble {
my $self = shift;
Jifty->web->out(
-qq!<span class="preamble @{[$self->classes]}" >@{[_($self->preamble) || '' ]}</span>\n!
+qq!<span class="preamble @{[$self->classes]}">@{[_($self->preamble) || '' ]}</span>\n!
);
return '';
Added: jifty/branches/template-declare/share/web/templates/__jifty/webservices/json
==============================================================================
--- (empty file)
+++ jifty/branches/template-declare/share/web/templates/__jifty/webservices/json Sat Dec 2 10:44:54 2006
@@ -0,0 +1,2 @@
+% $r->content_type("text/x-json");
+<% Jifty::JSON::objToJson({Jifty->web->response->results}) |n%>
Modified: jifty/branches/template-declare/t/06-forms.t
==============================================================================
--- jifty/branches/template-declare/t/06-forms.t (original)
+++ jifty/branches/template-declare/t/06-forms.t Sat Dec 2 10:44:54 2006
@@ -1,7 +1,8 @@
use warnings;
use strict;
-
-use Jifty::Test tests => 11;
+use Jifty::Test tests => 24;
+use Test::MockObject;
+use Test::MockModule;
use_ok ('Jifty::Web::Form::Field');
@@ -10,7 +11,6 @@
my $field = Jifty::Web::Form::Field->new();
-
# Form::Fields don't work without a framework
is($field->name, undef);
ok($field->name('Jesse'));
@@ -22,3 +22,127 @@
is($field->name, 'Jesse');
is ($field->type, 'text', "type defaults to text");
+
+# Test render_XXX methods:
+{
+ my $out; # buf to store mason outputs
+
+ # mock up an instance of Jifty::Result
+ my $result = Test::MockObject->new;
+ $result->set_series('field_error', 'error: invalid email address', '');
+ $result->set_series('field_warning', 'warning: password too short', '');
+ $result->set_series('field_canonicalization_note', "I've changed it!", '');
+
+ # mock up an instance of Jifty::Action
+ my $action = Test::MockObject->new;
+ $action->set_always('result', $result);
+ $action->set_always('form_field_name', 'search_keys');
+ $action->set_series('error_div_id', 'FOO-error', 'no-error');
+ $action->set_series('warning_div_id', 'BAR-warning', 'no-warning');
+ $action->set_series('canonicalization_note_div_id', 'canonicalize', 'nothing');
+
+ # mock up an instance of Jifty::Web
+ my $web = Test::MockObject->new;
+ $web->mock('out', sub {
+ shift;
+ if (@_) { $out .= "@_" }
+ $out;
+ });
+ $web->set_always('serial', 32);
+
+ # mock up the Jifty package
+ my $module = new Test::MockModule('Jifty');
+ $module->mock('web', sub { $web });
+
+ # Test nonempty render_XXX:
+
+ $field = Jifty::Web::Form::Field->new();
+ $field->action($action);
+ $field->class('blah');
+ $field->name('agentz');
+
+ # Test render_lable:
+ $field->label('Audrey Tang');
+ $out = '';
+ $field->render_label;
+ is $out, qq{<label class="label text blah argument-agentz" for="search_keys-32">}.
+ qq{Audrey Tang</label>\n};
+
+ # Test render_hints:
+ $field->hints('She is here!');
+ $out = '';
+ $field->render_hints;
+ is $out, qq{<span class="hints text blah argument-agentz">She is here!</span>\n};
+
+ # Test render_errors:
+ $out = '';
+ $field->render_errors;
+ is $out, qq{<span class="error text blah argument-agentz" id="FOO-error">}.
+ qq{error: invalid email address</span>\n};
+
+ # Test render_warnings:
+ $out = '';
+ $field->render_warnings;
+ is $out, qq{<span class="warning text blah argument-agentz" id="BAR-warning">}.
+ qq{warning: password too short</span>\n};
+
+ # Test render_canonicalization_notes:
+ $out = '';
+ $field->render_canonicalization_notes;
+ is $out, qq{<span class="canonicalization_note text blah argument-agentz" }.
+ qq{id="canonicalize">I've changed it!</span>\n};
+
+ # Test render_preamble:
+ $out = '';
+ $field->preamble("preamble's here!");
+ $field->render_preamble;
+ is $out, qq{<span class="preamble text blah argument-agentz">}.
+ qq{preamble's here!</span>\n};
+
+ # Test empty labels:
+ $field->name('yichun');
+ $field->label('');
+ $field->class('');
+ $out = '';
+ $field->render_label;
+ is $out, qq{<label class="label text argument-yichun" for="search_keys-32"></label>\n};
+
+ # Test default labels:
+ $field->name('yichun');
+ $field->label(undef);
+ $field->class('hey');
+ $out = '';
+ $field->render_label;
+ is $out, qq{<label class="label text hey argument-yichun" for="search_keys-32">}.
+ qq{yichun</label>\n};
+
+ # Test empty hints:
+ $field->name('xunxin');
+ $field->class('ujs');
+ $field->hints('');
+ $out = '';
+ $field->render_hints;
+ is $out, qq{<span class="hints text ujs argument-xunxin"></span>\n};
+
+ # Test empty errors:
+ $out = '';
+ $field->render_errors;
+ is $out, qq{<span class="error text ujs argument-xunxin" id="no-error"></span>\n};
+
+ # Test empty warnings:
+ $out = '';
+ $field->render_warnings;
+ is $out, qq{<span class="warning text ujs argument-xunxin" id="no-warning"></span>\n};
+
+ # Test empty canonicalization note:
+ $out = '';
+ $field->render_canonicalization_notes;
+ is $out, qq{<span class="canonicalization_note text ujs argument-xunxin" }.
+ qq{id="nothing"></span>\n};
+
+ # Test empty preambles:
+ $out = '';
+ $field->preamble("");
+ $field->render_preamble;
+ is $out, qq{<span class="preamble text ujs argument-xunxin"></span>\n};
+}
More information about the Jifty-commit
mailing list