123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- use NRT::Test;
- use NRT::Helper;
- use NRT::User;
- use NRT::Activity;
- use NRT::Task;
-
- package Batch;
-
- sub new {
- my ($classe, %config) = @_;
- my $this = {};
- $classe = ref($classe) || $classe;
- bless ( $this, $classe );
- $this->{config} = {%config} ;
- $this->{tester} = Test->new( %config );
- $this->{users} = [];
- $this->{users_index} = 0;
- $this->{default_user_index} = "";
- return $this;
- }
-
- sub test_rq_empty {
- my $this = shift;
- print "\nTesting requests\n";
- my $rq = $this->{tester}->get_code();
- return $this->{tester}->assertEqual( $rq, "404 Not Found" );
- }
-
- sub test_user {
- my $this = shift;
- print "\nTesting users\n";
- $this->{tester}->test_user_authentification( $this->get_default_user );
- $this->{tester}->test_user_already_created( $this->get_default_user );
- my $user2_index = $this->add_user(
- $this->{config}{User}{Email},
- $this->{config}{User}{Username},
- $this->{config}{User}{Password} );
- $this->{tester}->test_user_not_exists(
- $this->{users}[$user2_index]);
- $this->{tester}->test_user_create(
- $this->{users}[$user2_index]);
- $this->{tester}->test_user_exists(
- $this->{users}[$user2_index]);
- $this->{tester}->test_user_remove(
- $this->{users}[$user2_index]);
- $this->{tester}->test_user_removed(
- $this->{users}[$user2_index]);
- $this->{tester}->test_user_already_removed(
- $this->{users}[$user2_index]);
- }
-
- sub add_user {
- my ($this, $email, $username, $password) = @_ ;
- push(
- @{$this->{users}},
- User->new( $email, $username, $password, $this->{tester})) ;
- return $this->{users_index}++;
- }
-
- sub add_default_user {
- my ($this) = @_ ;
- return $this->{default_user_index} = $this->add_user(
- $this->{config}{Authentification}{Email},
- $this->{config}{Authentification}{Username},
- $this->{config}{Authentification}{Password} )
- }
-
- sub get_default_user {
- my ($this) = @_ ;
- if( $this->{default_user_index} eq "" ){
- $this->add_default_user ;
- }
- return $this->{users}[ $this->{default_user_index} ];
- }
-
- sub test_activity {
- my $this = shift;
- print "\nTesting activities\n";
- my $activity = Activity->new( "test_1", $this->get_default_user );
- $this->{tester}->test_create_activity( $activity );
- $this->{tester}->test_activity_exists( $activity );
- my $task = Task->new( "test_1", $activity );
- $this->{tester}->test_task_not_exists( $task );
- $this->{tester}->test_create_task( $task );
- $this->{tester}->test_task_exists( $task );
- $this->{tester}->test_task_remove( $task );
- $this->{tester}->test_task_not_exists( $task );
- $this->{tester}->test_activity_remove( $activity );
- $this->{tester}->test_activity_not_exists( $activity );
- }
-
- sub run {
- my $this = shift;
- $this->test_rq_empty();
- $this->test_user();
- $this->test_activity();
- $this->brief();
- }
-
- sub brief {
- my $this = shift;;
- print "\nResults :\n";
- Helper::printColor( "bright_green", "Tests succeed : ".$this->{tester}->{countSuccess}."\n" );
- Helper::printColor( "bright_red", "Tests failed : ".$this->{tester}->{countFailure}."\n" );
- }
-
- return 1;
|