
theory at bricolage
Mar 6, 2009, 4:37 PM
Post #1 of 1
(390 views)
Permalink
|
|
[8461] Added test to ensure that a media file with an uppercase
|
|
Revision: 8461 Author: theory Date: 2009-03-06 16:37:47 -0800 (Fri, 06 Mar 2009) ViewCVS: http://viewsvn.bricolage.cc/?rev=8461&view=rev Log Message: ----------- Added test to ensure that a media file with an uppercase character gets the file name lowercased in the URI, and URI-escaped, too. Trying to replicate Bug # 1419, which my production install exhibits, but not having much luck: it works like it should! The URI escaping, BTW, was accidentally checked in early in r8442. Bugzilla Links: -------------- http://bugs.bricolage.cc/show_bug.cgi?id=1419 Modified Paths: -------------- bricolage/trunk/lib/Bric/App/Callback/Profile/FormBuilder.pm bricolage/trunk/lib/Bric/Biz/ElementType/Parts/FieldType.pm bricolage/trunk/t/Bric/Biz/Asset/Business/DevTest.pm bricolage/trunk/t/Bric/Biz/Asset/Business/Media/DevTest.pm Modified: bricolage/trunk/lib/Bric/App/Callback/Profile/FormBuilder.pm =================================================================== --- bricolage/trunk/lib/Bric/App/Callback/Profile/FormBuilder.pm 2009-03-07 00:11:09 UTC (rev 8460) +++ bricolage/trunk/lib/Bric/App/Callback/Profile/FormBuilder.pm 2009-03-07 00:37:47 UTC (rev 8461) @@ -146,13 +146,17 @@ foreach my $aname (@{ mk_aref($param->{attr_name}) } ) { next if $del_attrs{$aname}; - $obj->set_member_attr({ name => $aname, - sql_type => $obj->get_member_attr_sql_type - ({ name => $aname}), - value => $param->{"attr|$aname"} }); - $obj->set_member_meta({ name => $aname, - field => 'pos', - value => $pos{$aname} }); + $obj->set_member_attr({ + name => $aname, + sql_type => $obj->get_member_attr_sql_type + ({ name => $aname}), + value => $param->{"attr|$aname"}, + }); + $obj->set_member_meta({ + name => $aname, + field => 'pos', + value => $pos{$aname}, + }); } my $no_save; # Add in any new attributes. @@ -174,18 +178,21 @@ my $value = $sqltype eq 'date' ? undef : $param->{fb_value}; # Set it for all members of this group. - $obj->set_member_attr({ name => $param->{fb_name}, - sql_type => $sqltype, - value => $value - }); + $obj->set_member_attr({ + name => $param->{fb_name}, + sql_type => $sqltype, + value => $value + }); $param = $clean_param->($param); # Record the metadata so we can properly display the form element. while (my ($k, $v) = each %meta_props) { - $obj->set_member_meta({ name => $param->{fb_name}, - field => $k, - value => $param->{$v} }); + $obj->set_member_meta({ + name => $param->{fb_name}, + field => $k, + value => $param->{$v} + }); } # Log that we've added it. log_event("${key}_ext", $obj, { 'Name' => $param->{fb_name} }); Modified: bricolage/trunk/lib/Bric/Biz/ElementType/Parts/FieldType.pm =================================================================== --- bricolage/trunk/lib/Bric/Biz/ElementType/Parts/FieldType.pm 2009-03-07 00:11:09 UTC (rev 8460) +++ bricolage/trunk/lib/Bric/Biz/ElementType/Parts/FieldType.pm 2009-03-07 00:37:47 UTC (rev 8461) @@ -43,11 +43,11 @@ # (deprecated) Get/Set the quantifier flag. $field = $field->set_quantifier( $quantifier ) $quantifier = $field->get_quantifier() - + # Get/Set min occurrence specification limit $field = $field->set_min_occurrence($amount) $min = $field->get_min_occurrence() - + # Get/Set max occurrence specification limit $field = $field->set_max_occurrence($amount) $max = $field->get_max_occurrence() @@ -141,7 +141,7 @@ vals multiple default_val - active + active ); my @ATTRS = qw( @@ -488,7 +488,7 @@ =item active Boolean valule indicating whether or not the field is active. - + =item max_occurrence Specifies an upper limit to how many instances there may be of this field type. @@ -1139,7 +1139,7 @@ Return the maximum occurrence B<Throws:> NONE. - + B<Side Effects:> NONE. B<Notes:> NONE. @@ -1149,7 +1149,7 @@ Sets the maximum occurrence this field type may occur. B<Throws:> NONE. - + B<Side Effects:> NONE. B<Notes:> NONE. @@ -1159,7 +1159,7 @@ Return the minimum occurrence B<Throws:> NONE. - + B<Side Effects:> NONE. B<Notes:> NONE. @@ -1169,7 +1169,7 @@ Sets the minimum occurrence this field type may occur. B<Throws:> NONE. - + B<Side Effects:> NONE. B<Notes:> NONE. Modified: bricolage/trunk/t/Bric/Biz/Asset/Business/DevTest.pm =================================================================== --- bricolage/trunk/t/Bric/Biz/Asset/Business/DevTest.pm 2009-03-07 00:11:09 UTC (rev 8460) +++ bricolage/trunk/t/Bric/Biz/Asset/Business/DevTest.pm 2009-03-07 00:37:47 UTC (rev 8461) @@ -20,12 +20,13 @@ # necessary in subclasses. sub new_args { my $self = shift; - ( element_type => $self->get_elem, - user__id => $self->user_id, - source__id => 1, - primary_oc_id => 1, - site_id => 100, - ) + return ( + element_type => $self->get_elem, + user__id => $self->user_id, + source__id => 1, + primary_oc_id => 1, + site_id => 100, + ); } sub pe { Modified: bricolage/trunk/t/Bric/Biz/Asset/Business/Media/DevTest.pm =================================================================== --- bricolage/trunk/t/Bric/Biz/Asset/Business/Media/DevTest.pm 2009-03-07 00:11:09 UTC (rev 8460) +++ bricolage/trunk/t/Bric/Biz/Asset/Business/Media/DevTest.pm 2009-03-07 00:37:47 UTC (rev 8461) @@ -8,6 +8,7 @@ use Bric::Biz::Asset::Business::Media::Image; use Bric::Util::DBI qw(:standard :junction); use Bric::Biz::Keyword; +use Bric::Biz::OutputChannel qw(:case_constants); use Bric::Util::Time qw(strfdate); use Test::MockModule; sub class { 'Bric::Biz::Asset::Business::Media' } @@ -40,15 +41,16 @@ my $z; sub new_args { my $self = shift; - ( element_type => $self->get_elem, - user__id => $self->user_id, - file_name => 'fun.foo' . ++$z, - source__id => 1, - primary_oc_id => 1, - site_id => 100, - category__id => 1, - cover_date => '2005-03-22 21:07:56', - ) + return ( + element_type => $self->get_elem, + user__id => $self->user_id, + file_name => 'fun.foo' . ++$z, + source__id => 1, + primary_oc_id => 1, + site_id => 100, + category__id => 1, + cover_date => '2005-03-22 21:07:56', + ); } ############################################################################## @@ -959,7 +961,7 @@ 'asset_grp_ids'); } -sub test_upload_before_save : Test(6) { +sub test_upload_before_save : Test(9) { my $self = shift; my $class = $self->class; @@ -975,6 +977,10 @@ goto $cat_dir; }); + # Let's force lowercase-only. + $self->{oc} = my $oc = $self->get_elem->get_output_channels->[0]; + $oc->set_uri_case(LOWERCASE)->save; + ok my $media = $self->construct( name => 'Flubberman', file_name => 'fun.foo', @@ -982,7 +988,7 @@ # Upload a file before saving the media. ok open my $file, '<', __FILE__ or die 'Cannot open ' . __FILE__ . ": $!"; - ok $media->upload_file($file, __FILE__), 'Upload a media file'; + ok $media->upload_file($file, 'Some file.png'), 'Upload a media file'; # Now save the media. ok $media->save, 'Save the media document'; @@ -994,7 +1000,17 @@ my @id_dirs = $id =~ /(\d\d?)/g; my $dir = Bric::Util::Trans::FS->cat_dir(@id_dirs, "v.$version"); like $media->get_location, qr/$dir/, 'The ID should be in the location'; + + is $media->get_file_name, 'Some file.png', 'The file name should be uppercase'; + like $media->get_location, qr{/Some file[.]png$}, 'So should the location'; + like $media->get_uri, qr{/some%20file[.]png$}, + 'But the URI should be lowercased and URI escaped'; } +sub cleanup_oc : Test(teardown) { + my $oc = shift->{oc} or return; + $oc->set_uri_case(MIXEDCASE)->save; +} + 1; __END__
|