more robust testing platform, #37340
[freeside.git] / FS / t / suite / 01-order_pkg.t
1 #!/usr/bin/perl
2
3 use Test::More tests => 4;
4 use FS::Test;
5 use Date::Parse 'str2time';
6 my $FS = FS::Test->new;
7
8 # get the form
9 $FS->post('/misc/order_pkg.html', custnum => 2);
10 my $form = $FS->form('OrderPkgForm');
11
12 # Customer #2 has three packages:
13 # a $30 monthly prorate, a $90 monthly prorate, and a $25 annual prorate.
14 # Next bill date on the monthly prorates is 2016-04-01.
15 # Add a new package that will start billing on 2016-03-20 (to make prorate
16 # behavior visible).
17
18 my %params = (
19   pkgpart                 => 5,
20   quantity                => 1,
21   start                   => 'on_date',
22   start_date              => '03/20/2016',
23   package_comment0        => $0, # record the test we're executing
24 );
25
26 $form->find_input('start')->disabled(0); # JS
27 foreach (keys %params) {
28   $form->value($_, $params{$_});
29 }
30 $FS->post($form);
31 ok( $FS->error eq '' , 'form posted' );
32 if (
33    ok( $FS->page =~ m[location = '.*/view/cust_main.cgi.*\#cust_pkg(\d+)'],
34       'new package accepted' )
35 ) {
36  # on success, sends us back to cust_main view with #cust_pkg$pkgnum
37   # but with an in-page javascript redirect
38   my $pkg = $FS->qsearchs('cust_pkg', { pkgnum => $1 });
39   isa_ok( $pkg, 'FS::cust_pkg' );
40   ok($pkg->start_date == str2time('2016-03-20'), 'start date set');
41 } else {
42   # try to display the error message, or if not, show everything
43   $FS->post($FS->redirect);
44   diag ($FS->error);
45   done_testing(2);
46 }
47
48 1;
49