|
| 1 | +#------------------------------------------------------------------- |
| 2 | +# WebGUI is Copyright 2001-2009 Plain Black Corporation. |
| 3 | +#------------------------------------------------------------------- |
| 4 | +# Please read the legal notices (docs/legal.txt) and the license |
| 5 | +# (docs/license.txt) that came with this distribution before using |
| 6 | +# this software. |
| 7 | +#------------------------------------------------------------------- |
| 8 | +# http://www.plainblack.com info@plainblack.com |
| 9 | +#------------------------------------------------------------------- |
| 10 | + |
| 11 | +use FindBin; |
| 12 | +use strict; |
| 13 | +use warnings; |
| 14 | +use lib "$FindBin::Bin/lib"; ##t/lib |
| 15 | + |
| 16 | +use WebGUI::Test; |
| 17 | +use WebGUI::Session; |
| 18 | +use Data::Dumper; |
| 19 | +use WebGUI::Asset; |
| 20 | +use WebGUI::Asset::Template; |
| 21 | +use WebGUI::Macro; |
| 22 | + |
| 23 | +#The goal of this test is to find template attachments that do not resolve. |
| 24 | + |
| 25 | +use Test::More; # increment this value for each test you create |
| 26 | +my $numTests = 0; |
| 27 | + |
| 28 | +my $session = WebGUI::Test->session; |
| 29 | + |
| 30 | +# put your tests here |
| 31 | + |
| 32 | +$numTests = $session->db->quickScalar('select count(distinct(assetId)) from template'); |
| 33 | + |
| 34 | +my $getATemplate = WebGUI::Asset::Template->getIsa($session); |
| 35 | + |
| 36 | +WebGUI::Test->originalConfig('extrasURL'); |
| 37 | +$session->config->set('extrasURL', ''); |
| 38 | + |
| 39 | +TEMPLATE: while (my $templateAsset = $getATemplate->()) { |
| 40 | + my $bad_attachments = 0; |
| 41 | + foreach my $attachment (@{ $templateAsset->getAttachments }) { |
| 42 | + my $url = $attachment->{url}; |
| 43 | + WebGUI::Macro::process($session, \$url); |
| 44 | + my $url_exists = 0; |
| 45 | + if ($attachment->{url} =~ /\^Extras/) { |
| 46 | + ##File system path for /extras, adjust the URL for that. |
| 47 | + $url = $session->config->get('extrasPath') . $url; |
| 48 | + $url_exists = -e $url; |
| 49 | + } |
| 50 | + else { |
| 51 | + my $asset = eval { WebGUI::Asset->newByUrl($session, $url) }; |
| 52 | + $url_exists = defined $asset; |
| 53 | + } |
| 54 | + ok $url_exists, sprintf "%s: %s (%s) has a bad attachment url: %s", $templateAsset->getTitle, $templateAsset->getId, $templateAsset->getUrl, $attachment->{url}; |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +done_testing; |
0 commit comments