Zuviel in b24afac71c944 entfernt. Historie und Wiedervorlage wieder anzeigen
[kivitendo-erp.git] / SL / Controller / JSTests.pm
1 package SL::Controller::JSTests;
2
3 use strict;
4
5 use parent qw(SL::Controller::Base);
6
7 use File::Find ();
8 use File::Spec ();
9 use List::UtilsBy qw(sort_by);
10
11 use SL::System::Process;
12
13 use Rose::Object::MakeMethods::Generic
14 (
15   'scalar --get_set_init' => [ qw(all_scripts scripts_to_run) ],
16 );
17
18 #
19 # actions
20 #
21
22 sub action_run {
23   my ($self) = @_;
24
25   $::request->layout->use_stylesheet("css/qunit.css");
26   $self->render('js_tests/run', title => $::locale->text('Run JavaScript unit tests'));
27 }
28
29 #
30 # helpers
31 #
32
33 sub init_all_scripts {
34   my ($self) = @_;
35
36   my $exe_dir = SL::System::Process->exe_dir;
37
38   my @scripts;
39   my $wanted = sub {
40     return if ( ! -f $File::Find::name ) || ($File::Find::name !~ m{\.js$});
41     push @scripts, File::Spec->abs2rel($File::Find::name, $exe_dir);
42   };
43
44   File::Find::find($wanted, $exe_dir . '/js/t');
45
46   return [ sort_by { lc } @scripts ];
47 }
48
49 sub init_scripts_to_run {
50   my ($self) = @_;
51   my $filter = $::form->{file_filter} || '.';
52   return [ grep { m{$filter} } @{ $self->all_scripts } ];
53 }
54
55 1;