#!/usr/bin/perl -w
use strict; 

use lib qw(./ ./DADA/perllib ../ ../DADA/perllib ../../ ../../DADA/perllib
/Users/justin/Documents/DadaMail/build/tmp/dada/DADA/perllib/ 


); 

use Test::More qw(no_plan); 

#close STDERR;


use DADA::Config; 
use DADA::App::Guts; 
use DADA::MailingList; 

my $list = 'dadatest'; 

my $list_params = { 

        list             =>  $list, 
        list_name        => 'Justin!', 
        list_owner_email => 'user@example.com',  
        password         => 'abcd', 
        retype_password  => 'abcd', 
        info             => 'info', 
        privacy_policy   => 'privacy_policy',
        physical_address => 'physical_address', 

};

# ok ok ok! We'll actually make the list...
my $ls = DADA::MailingList::Create({ -name => $list }); 
   my $l_list_params = $list_params; 
   delete($list_params->{retype_password}); 
   $ls->save($l_list_params);
   
   
### check_for_valid_email
 
ok(check_for_valid_email('test@example.com')           == 0); 
ok(check_for_valid_email('test@example.co.uk')         == 0); 
ok(check_for_valid_email('test.one.two@example.co.uk') == 0); 
ok(check_for_valid_email('test@example.nu')            == 0); 
ok(check_for_valid_email('test+0@example.nu')          == 0); 

ok(check_for_valid_email('test')                       == 1); 
ok(check_for_valid_email('test@example')               == 1); 
ok(check_for_valid_email('example.co.uk')              == 1); 

TODO: {
    local $TODO = 'This test fails, see bug report at: http://rt.cpan.org/Public/Bug/Display.html?id=24465';
       
   # diag("Next test will fail."); 
   # diag("See: http://rt.cpan.org/Public/Bug/Display.html?id=24465 ");
    ok(check_for_valid_email('test @example.nu')           == 1); 

};



ok(check_for_valid_email('test+0')                     == 1); 



### strip

ok(strip(' foo ') eq 'foo'); 
ok(strip('foo ')  eq 'foo'); 
ok(strip(' foo')  eq 'foo'); 



### pretty

ok(pretty('_foo_') eq ' foo '); 
ok(pretty('foo_')  eq 'foo '); 
ok(pretty('_foo')  eq ' foo'); 


### make_pin
### check_email_pin


### make_template


my $template = 'blah blah blah'; 


ok(make_template() eq undef); 
ok(make_template({ -List => $list }) eq undef); 
ok(make_template({ -List => $list, -Template => $template }) == 1); 

my $template_file = $TEMPLATES . '/' . $list . '.template'; 


ok(-e $template_file); 

    open my $TEMPLATE_FILE, '<', $template_file
        or die $!;

    my $template_info = do { local $/; <$TEMPLATE_FILE> };

    close $TEMPLATE_FILE
        or die $!;
 
ok($template_info eq $template, 'Template info saved correctly'); 




### delete_list_template

ok(delete_list_template() eq undef); 
ok(delete_list_template( { -List => $list })); 
ok(! -e $template_file); 



### delete_list_info
### delete_email_list



### check_if_list_exists

ok(check_if_list_exists(-List => $list)        == 1); 
ok(check_if_list_exists(-List => 'idontexist') == 0); 




my $Remove = DADA::MailingList::Remove({ -name => $list }); 
ok($Remove == 1, "Remove returned a status of, '1'");

ok(date_this(-Packed_Date => '20061120024010') =~ m{(\s*)November 20th 2006(\s*)}); 
ok(date_this(-Packed_Date => '20061120024010', -All => 1) =~ m{(\s*)November 20th 2006 2:40:10 a.m.(\s*)}); 

