
theory at bricolage
Mar 6, 2009, 5:07 PM
Post #1 of 1
(397 views)
Permalink
|
|
[8463] Backported the fix for media URIs from trunk.
|
|
Revision: 8463 Author: theory Date: 2009-03-06 17:07:36 -0800 (Fri, 06 Mar 2009) ViewCVS: http://viewsvn.bricolage.cc/?rev=8463&view=rev Log Message: ----------- Backported the fix for media URIs from trunk. Modified Paths: -------------- bricolage/branches/rev_1_10/lib/Bric/Biz/Asset/Business/Media.pm bricolage/branches/rev_1_10/lib/Bric/Changes.pod bricolage/branches/rev_1_10/t/Bric/Biz/Asset/Business/Media/DevTest.pm Modified: bricolage/branches/rev_1_10/lib/Bric/Biz/Asset/Business/Media.pm =================================================================== --- bricolage/branches/rev_1_10/lib/Bric/Biz/Asset/Business/Media.pm 2009-03-07 00:54:42 UTC (rev 8462) +++ bricolage/branches/rev_1_10/lib/Bric/Biz/Asset/Business/Media.pm 2009-03-07 01:07:36 UTC (rev 8463) @@ -1233,8 +1233,10 @@ my ($uri, $update_uri); if ($self->get_file_name) { $update_uri = 1; - $uri = Bric::Util::Trans::FS->cat_uri - ( $self->_construct_uri($cat, $oc), $oc->get_filename($self)); + $uri = Bric::Util::Trans::FS->cat_uri( + $self->_construct_uri($cat, $oc), + $ESCAPE_URI->($oc->get_filename($self)) + ); } # If we've changed the category we need to repreview it if on autopreview @@ -1261,8 +1263,10 @@ my $oc = Bric::Biz::OutputChannel->lookup({ id => $id }); my $cat = $self->get_category_object; $update_uri = 1; - $uri = Bric::Util::Trans::FS->cat_uri - ( $self->_construct_uri($cat, $oc), $oc->get_filename($self)); + $uri = Bric::Util::Trans::FS->cat_uri( + $self->_construct_uri($cat, $oc), + $ESCAPE_URI->($oc->get_filename($self)) + ); } $self->_set([qw(primary_oc_id uri _update_uri)] => [ $id, $uri, $update_uri]); @@ -1327,7 +1331,6 @@ my $cover_date = db_date(shift); my ($old, $cat, $cat_id) = $self->_get(qw(cover_date _category_obj category__id)); - my $fn = $self->get_file_name; return $self unless (defined $cover_date && not defined $old) || (not defined $cover_date && defined $old) @@ -1338,13 +1341,15 @@ $self->_set(['cover_date'] => [$cover_date]); my ($uri, $update_uri); - if (defined $fn) { + if (defined $self->get_file_name) { $update_uri = 1; $cat ||= Bric::Biz::Category->lookup({ id => $cat_id }); my $oc = $self->get_primary_oc; if ($cat and $oc) { - $uri = Bric::Util::Trans::FS->cat_uri - ($self->_construct_uri($cat, $oc), $fn); + $uri = Bric::Util::Trans::FS->cat_uri( + $self->_construct_uri($cat, $oc), + $ESCAPE_URI->($oc->get_filename($self)) + ); } } @@ -1427,9 +1432,10 @@ "associated with media '" . $self->get_name . "'") unless $self->get_output_channels($oc->get_id); - return Bric::Util::Trans::FS->cat_uri - ($self->_construct_uri($self->get_category_object, $oc), - $oc->get_filename($self)); + return Bric::Util::Trans::FS->cat_uri( + $self->_construct_uri($self->get_category_object, $oc), + $ESCAPE_URI->($oc->get_filename($self)) + ); } ############################################################################## Modified: bricolage/branches/rev_1_10/lib/Bric/Changes.pod =================================================================== --- bricolage/branches/rev_1_10/lib/Bric/Changes.pod 2009-03-07 00:54:42 UTC (rev 8462) +++ bricolage/branches/rev_1_10/lib/Bric/Changes.pod 2009-03-07 01:07:36 UTC (rev 8463) @@ -137,6 +137,15 @@ The "Logged in as" link at the top of every screen now properly uses SSL when appropriate. [David] +=item * + +Fixed an inconsistency in how the case of file names in media documents was +not always properly set according to the rules for the output channel. This +means that if your media document's output channel requires lowercase URIs, +the URI for the media document will always be lowercase, including the file +name. The file name is also now always consistently URI escaped (Bug #1419). +[David] + =back =head1 VERSION 1.10.6 (2008-10-02) Modified: bricolage/branches/rev_1_10/t/Bric/Biz/Asset/Business/Media/DevTest.pm =================================================================== --- bricolage/branches/rev_1_10/t/Bric/Biz/Asset/Business/Media/DevTest.pm 2009-03-07 00:54:42 UTC (rev 8462) +++ bricolage/branches/rev_1_10/t/Bric/Biz/Asset/Business/Media/DevTest.pm 2009-03-07 01:07:36 UTC (rev 8463) @@ -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' } @@ -946,7 +947,7 @@ } ############################################################################## -sub test_upload_before_save : Test(6) { +sub test_upload_before_save : Test(26) { my $self = shift; my $class = $self->class; @@ -962,6 +963,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', @@ -969,7 +974,7 @@ # Upload a file before saving the media. ok open my $file, '<', __FILE__ or die 'Cannot open ' . __FILE__ . ": $!"; - ok $media->upload_file($file, 'foo.png'), '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'; @@ -981,7 +986,58 @@ 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'; + + # Change the cover date. + ok $media->set_cover_date('1968-12-19 19:42:00'), 'Set the cover date'; + is $media->get_file_name, 'Some file.png', 'The file name should still be uppercase'; + like $media->get_location, qr{/Some file[.]png$}, 'So should the location'; + like $media->get_uri, qr{/some%20file[.]png$}, + 'And the URI should still be lowercased and URI escaped'; + + # Change the category. + ok my $cat = Bric::Biz::Category->new({ + name => 'Testing', + site_id => 100, + parent_id => 1, + directory => 'testing', + }), 'Create a new category'; + ok $cat->save, 'Save the new category'; + $self->add_del_ids($cat->get_id, 'category'); + + ok $media->set_category__id($cat->get_id), 'Change the category ID'; + is $media->get_file_name, 'Some file.png', 'The file name should still be uppercase'; + like $media->get_location, qr{/Some file[.]png$}, 'So should the location'; + like $media->get_uri, qr{/some%20file[.]png$}, + 'And the URI should still be lowercased and URI escaped'; + + # Change the primary output channel. + ok my $oc2 = Bric::Biz::OutputChannel->new({ + name => 'Foo', + site_id => 100, + uri_case => LOWERCASE, + }), 'Create a new OC'; + ok $oc2->save, 'Save the new category'; + $self->add_del_ids($oc2->get_id, 'output_channel'); + + ok $media->set_primary_oc_id($oc2->get_id), 'Change the primary OC'; + is $media->get_file_name, 'Some file.png', 'The file name should still be uppercase'; + like $media->get_location, qr{/Some file[.]png$}, 'So should the location'; + like $media->get_uri, qr{/some%20file[.]png$}, + 'And the URI should still be lowercased and URI escaped'; + like $media->get_uri($oc2), qr{/some%20file[.]png$}, + 'And the URI should be lowercased when the OC is passed to uri()'; } +sub cleanup_oc : Test(teardown) { + my $oc = shift->{oc} or return; + $oc->set_uri_case(MIXEDCASE)->save; +} + + 1; __END__
|