JavaScript-Test-Framework auf Basis von QUnit
[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
10 use SL::System::Process;
11
12 use Rose::Object::MakeMethods::Generic
13 (
14   'scalar --get_set_init' => [ qw(all_scripts scripts_to_run) ],
15 );
16
17 #
18 # actions
19 #
20
21 sub action_run {
22   my ($self) = @_;
23
24   $::request->layout->use_stylesheet("css/qunit.css");
25   $self->render('js_tests/run', title => $::locale->text('Run JavaScript unit tests'));
26 }
27
28 #
29 # helpers
30 #
31
32 sub init_all_scripts {
33   my ($self) = @_;
34
35   my $exe_dir = SL::System::Process->exe_dir;
36
37   my @scripts;
38   my $wanted = sub {
39     return if ( ! -f $File::Find::name ) || ($File::Find::name !~ m{\.js$});
40     push @scripts, File::Spec->abs2rel($File::Find::name, $exe_dir);
41   };
42
43   File::Find::find($wanted, $exe_dir . '/js/t');
44
45   return \@scripts;
46 }
47
48 sub init_scripts_to_run {
49   my ($self) = @_;
50   my $filter = $::form->{file_filter} || '.';
51   return [ grep { m{$filter} } @{ $self->all_scripts } ];
52 }
53
54 1;