package Ernad::Test; ## functions used for testing use strict; use warnings; use Carp qw(confess); use Data::Dumper; use List::Util qw(shuffle); use File::Slurper; use Ernad::Common; use Krichel::File; ## 2018-03-01 no longer used? sub css_furl { my $e=shift // $main::e // confess "I need an erimp here."; my $css_furl=$e->{'conf'}->{'css_furl'} // confess "I need a css_furl in the constants.xslt.xml file."; my $test_css_furl=$css_furl; $test_css_furl=~s|/([^/]+)$|/$1.test|; return $test_css_furl; } sub change_furl_in_file { my $file=shift // confess "I need a file argument."; my $e=shift // $main::e // confess "I need an erimp here."; if(not -f $file) { warn "I don't see your file '$file'."; } if(-z $file) { warn "I don't see your file '$file' is empty, I remove it."; unlink $file; return; } my $css_furl=$e->{'conf'}->{'css_furl'}; my $test_furl=$e->{'conf'}->{'test_css_furl'}; my $text=&File::Slurper::read_text($file); $text=~s|href="$css_furl"|href="$test_furl"| or warn "I can't change '$css_furl' to '$test_furl' in $file."; &File::Slurper::write_text($file,$text); } sub find_recent_random_sent { my $e=shift // $main::e // confess "I need an erimp here."; my @codes=$e->list_repcodes(); ## bims in the early days #if(not @codes) { # @codes=$e->get_cural_repcodes(); #} @codes=shuffle(@codes); my $repcode; ## continue until we return a result while($repcode=shift @codes) { $e->{'r'}->load($repcode); ## This is a temporary check to skip the allport if(not $e->{'conf'}) { confess "I need this here."; } ## this is temporary, as list_repcodes may have the allport if($e->{'conf'}->{'allport_repcode'} and $repcode eq $e->{'conf'}->{'allport_repcode'}) { next; } my $rerc=$e->{'report'}->{$repcode}; my $sent_dir=$rerc->{'dir'}->{'sent'}; if(not -d $sent_dir) { confess "I don't have $sent_dir"; } my $glob="$sent_dir/*.amf.xml"; my @files=glob($glob); if(not scalar @files) { print "I have no files for $repcode\n"; next; } @files=shuffle(@files); my $file; while($file=shift @files) { my $rix=&Krichel::File::load($file); my $count=$e->{'x'}->count_texts($rix); if(not $count) { next; } else { return $file; } } } } 1;