MT#22063 Allow cyclic number ranges

Change-Id: I83504db004b54485adbc729d5f3c8f167b5ccbe2
changes/76/7776/4
Irina Peshinskaya 9 years ago
parent ec026f1a9b
commit 1ae39de2fc

@ -5,6 +5,7 @@ extends 'HTML::FormHandler::Field::Text';
has 'min_start' => (isa => 'Int', default => 0, is => 'rw');
has 'max_end' => (isa => 'Int', default => 999_999, is => 'rw');
has 'cyclic' => (isa => 'Bool', default => 0, is => 'rw');
sub validate {
my ( $self ) = @_;
@ -14,7 +15,7 @@ sub validate {
$self->add_error('Invalid format');
return;
}
if ($end < $start) {
if ( (!$self->cyclic) && ($end < $start) ) {
$self->add_error('Second value smaller than first');
return;
}

@ -60,7 +60,8 @@ has_field 'times.mday' => (
has_field 'times.wday' => (
type => '+NGCP::Panel::Field::NumRangeAPI',
min_start => 1,
max_end => 8,
max_end => 7,
cyclic => 1,
label => 'Weekday',
empty_select => '',
);

@ -0,0 +1,55 @@
use strict;
use Test::Collection;
use Test::FakeData;
use Test::More;
use Data::Dumper;
#use NGCP::Panel::Utils::Subscriber;
my $test_machine = Test::Collection->new(
name => 'cftimesets',
);
my $fake_data = Test::FakeData->new;
$test_machine->methods->{collection}->{allowed} = {map {$_ => 1} qw(GET HEAD OPTIONS POST)};
$test_machine->methods->{item}->{allowed} = {map {$_ => 1} qw(GET HEAD OPTIONS PUT PATCH DELETE)};
$fake_data->set_data_from_script({
'cftimesets' => {
'data' => {
name => 'API_test call forward time-set',
subscriber_id => sub { return shift->get_id('subscribers',@_); },
times => [{
wday => '1-5',
hour => '5-5',
minute => '50-59',
year => undef,
month => undef,
mday => undef,
},],
},
'query' => ['name'],
},
});
$test_machine->DATA_ITEM_STORE($fake_data->process('cftimesets'));
$test_machine->form_data_item();
$test_machine->check_create_correct( 1 );
$test_machine->check_get2put();
$test_machine->check_bundle();
{
#test cyclic wday input
diag("Cyclic wday input;\n\n");
$test_machine->check_create_correct(1,sub{
$_[0]->{wday} = '6-1';
});
}
$test_machine->clear_test_data_all();#fake data aren't registered in this test machine, so they will stay.
undef $fake_data;
undef $test_machine;
done_testing;
# vim: set tabstop=4 expandtab:
Loading…
Cancel
Save