[Rt-commit] rt branch, cf-date, updated. rt-3.8.8-185-gd1f00fe

? sunnavy sunnavy at bestpractical.com
Fri Jul 23 20:05:14 EDT 2010


The branch, cf-date has been updated
       via  d1f00feb27cd256d65b140a2068b2b2369b7dee2 (commit)
      from  3f3eb8908b1790a1ed46af41e7b22b7cbdf5642f (commit)

Summary of changes:
 share/html/Elements/SelectDate   |    7 ++++++-
 share/html/Helpers/CalPopup.html |    4 +++-
 t/web/cf_date.t                  |   34 +++++++++++++++++++++++++++-------
 3 files changed, 36 insertions(+), 9 deletions(-)

- Log -----------------------------------------------------------------
commit d1f00feb27cd256d65b140a2068b2b2369b7dee2
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sat Jul 24 08:06:38 2010 +0800

    make calendar link work for cf date in search builder

diff --git a/share/html/Elements/SelectDate b/share/html/Elements/SelectDate
index 32a173d..30a9638 100755
--- a/share/html/Elements/SelectDate
+++ b/share/html/Elements/SelectDate
@@ -45,8 +45,10 @@
 %# those contributions and any derivatives thereof.
 %# 
 %# END BPS TAGGED BLOCK }}}
+
+%# we use escaped_name here is because it may contain single quotes, which happens in cf date
 <script type="text/javascript"><!--
-    onLoadHook('createCalendarLink("<% $Name %>");');
+    onLoadHook('createCalendarLink("<% $escaped_name |n %>");');
 --></script>
 <input type="text" id="<% $Name %>" name="<% $Name %>" value="<% $Value %>" size="<% $Size %>" />
 <%init>
@@ -63,6 +65,9 @@ $Value = $Value || $Default;
 unless ($Name) {
 	$Name = $menu_prefix. "_Date";
 }
+
+my $escaped_name = $Name;
+$escaped_name =~ s/'/\\'/g;
 </%init>
 
 <%args>
diff --git a/share/html/Helpers/CalPopup.html b/share/html/Helpers/CalPopup.html
index 70b43c1..7c5962f 100644
--- a/share/html/Helpers/CalPopup.html
+++ b/share/html/Helpers/CalPopup.html
@@ -74,7 +74,9 @@
 % if ( ( $DisplayedYear == $today[5] + 1900 ) && ( $DisplayedMonth == $today[4] + 1 ) && ( $day == $today[3] ) ) {
 %     $class = 'today';
 % }
-        <a <% $class && 'class="'.$class.'"' |n%> href="#" onclick="updateParentField('<% $field %>','<% $datestr %>'); return false;"><% $day %></a>
+%# we use escaped field here is because it may contain single quotes, which happens in cf date
+% my $escaped_field = $field; $escaped_field =~ s/'/\\'/g;
+        <a <% $class && 'class="'.$class.'"' |n%> href="#" onclick="updateParentField('<% $escaped_field |n %>','<% $datestr %>'); return false;"><% $day %></a>
 %         } else {
         &nbsp;
 %         }
diff --git a/t/web/cf_date.t b/t/web/cf_date.t
index 18885fd..2b3cc58 100644
--- a/t/web/cf_date.t
+++ b/t/web/cf_date.t
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use RT::Test tests => 29;
+use RT::Test tests => 35;
 RT->Config->Set( 'Timezone' => 'US/Eastern' );
 my ($baseurl, $m) = RT::Test->started_ok;
 ok $m->login, 'logged in as root';
@@ -67,7 +67,7 @@ diag 'check valid inputs with various timezones in ticket create page' if $ENV{'
     $m->submit_form(
         form_name => "TicketCreate",
         fields    => {
-            Subject                                       => 'test',
+            Subject                                       => 'test 2010-05-04 08:00:00',
             Content                                       => 'test',
             "Object-RT::Ticket--CustomField-$cfid-Values" => '2010-05-04 08:00:00',
         },
@@ -98,9 +98,9 @@ diag 'check valid inputs with various timezones in ticket create page' if $ENV{'
     $m->submit_form(
         form_name => "TicketCreate",
         fields    => {
-            Subject                                       => 'test',
+            Subject                                       => 'test 2010-05-06 08:00:00',
             Content                                       => 'test',
-            "Object-RT::Ticket--CustomField-$cfid-Values" => '2010-05-04 08:00:00',
+            "Object-RT::Ticket--CustomField-$cfid-Values" => '2010-05-06 08:00:00',
         },
     );
     ok( ($id) = $m->content =~ /Ticket (\d+) created/,
@@ -109,15 +109,15 @@ diag 'check valid inputs with various timezones in ticket create page' if $ENV{'
     $ticket->Load($id);
     is(
         $ticket->CustomFieldValues($cfid)->First->Content,
-        '2010-05-04 00:00:00',
+        '2010-05-06 00:00:00',
         'date in db is in UTC'
     );
 
     $m->content_like(qr/test cf date:/, 'has no cf date field on the page');
-    $m->content_like(qr/Tue May 04 08:00:00 2010/, 'cf date input respects user timezone');
+    $m->content_like(qr/Thu May 06 08:00:00 2010/, 'cf date input respects user timezone');
     $root->SetTimezone( 'US/Eastern' ); # back to -04:00
     $m->get_ok( $m->uri );
-    $m->content_like(qr/Mon May 03 20:00:00 2010/, 'cf date value respects user timezone');
+    $m->content_like(qr/Wed May 05 20:00:00 2010/, 'cf date value respects user timezone');
 }
 
 
@@ -144,3 +144,23 @@ diag 'check invalid inputs' if $ENV{'TEST_VERBOSE'};
     $m->content_unlike(qr/foodate/, 'invalid dates not set');
 }
 
+diag 'check search build page' if $ENV{'TEST_VERBOSE'};
+$m->get_ok( $baseurl . '/Search/Build.html?Query=Queue=1' );
+
+# make sure there are at least 2 Calendar links
+$m->content_like( qr/createCalendar.*createCalendar/s, 'have at least 2 Calendar links' );
+$m->form_number(3);
+my ( $cf_op ) = $m->find_all_inputs( type => 'option', name_regex => qr/test cf date/ );
+is_deeply( [$cf_op->possible_values], [ '<', '=', '>' ], 'right oprators' ) ;
+
+my ( $cf_field ) = $m->find_all_inputs( type => 'text', name_regex => qr/test cf date/ );
+$m->submit_form(
+    fields => {
+        $cf_op->name    => '=',
+        $cf_field->name => '2010-05-04'
+    },
+    button => 'DoSearch',
+);
+$m->content_contains( 'Found 1 ticket', 'Found 1 ticket' );
+$m->content_contains( '2010-05-04',     'got the right ticket' );
+$m->content_lacks( '2010-05-06', 'did not get the wrong ticket' );

-----------------------------------------------------------------------


More information about the Rt-commit mailing list