[209] | 1 | use strict; |
---|
| 2 | use warnings; |
---|
[1378] | 3 | use Test::More tests => 21; |
---|
[335] | 4 | use File::Temp qw(mkstemp); |
---|
[209] | 5 | |
---|
| 6 | use_ok('LATMOS::Accounts::Utils'); |
---|
[1216] | 7 | use_ok('LATMOS::Accounts::Mail'); |
---|
[210] | 8 | use LATMOS::Accounts::Log; |
---|
| 9 | |
---|
| 10 | ok(la_log(LA_NOTICE, "a notice"), "can run la_log"); |
---|
[335] | 11 | |
---|
| 12 | my ($fh, $file) = mkstemp( "tmpfileXXXXX" ); |
---|
| 13 | print $fh <<EOF; |
---|
| 14 | attr1: attr1 |
---|
| 15 | attr: val1 |
---|
| 16 | attr: val2 |
---|
| 17 | EOF |
---|
| 18 | |
---|
| 19 | seek($fh, 0, 0); |
---|
| 20 | |
---|
| 21 | my %attributes = LATMOS::Accounts::Utils::parse_obj_file($fh); |
---|
| 22 | $fh = undef; |
---|
[338] | 23 | unlink($file); |
---|
[335] | 24 | |
---|
| 25 | # now testing |
---|
| 26 | is($attributes{'attr1'}, 'attr1', "can get attribute from file"); |
---|
| 27 | ok(eq_set($attributes{'attr'}, [ qw(val1 val2) ]), |
---|
| 28 | "can get multiple values attribute"); |
---|
| 29 | |
---|
| 30 | $ENV{EDITOR} = 'sleep 1; /bin/touch'; |
---|
| 31 | |
---|
| 32 | ok(LATMOS::Accounts::Utils::dump_read_temp_file( |
---|
| 33 | sub { 1; }, sub { 1; }), "Can edit temp file"); |
---|
[674] | 34 | |
---|
| 35 | ok(!LATMOS::Accounts::Utils::check_oid_validity('toto'), '"toto" is valid oid'); |
---|
| 36 | ok(!LATMOS::Accounts::Utils::check_oid_validity('toTo'), '"toTo" is valid oid'); |
---|
| 37 | ok(LATMOS::Accounts::Utils::check_oid_validity('to to'), '"to to" is invalid oid'); |
---|
| 38 | ok(LATMOS::Accounts::Utils::check_oid_validity(' toto'), '" toto" is invalid oid'); |
---|
| 39 | |
---|
| 40 | ok(!LATMOS::Accounts::Utils::check_ug_validity('toto'), '"toto" is valid username'); |
---|
| 41 | ok(LATMOS::Accounts::Utils::check_ug_validity('toTo'), '"toTo" is invalid username'); |
---|
| 42 | ok(LATMOS::Accounts::Utils::check_ug_validity('to to'), '"to to" is invalid username'); |
---|
| 43 | ok(LATMOS::Accounts::Utils::check_ug_validity(' toto'), '" toto" is invalid username'); |
---|
| 44 | ok(LATMOS::Accounts::Utils::check_ug_validity('5toto'), '"5toto" is invalid username'); |
---|
| 45 | ok(!LATMOS::Accounts::Utils::check_ug_validity('t5oto'), '"t5oto" is valid username'); |
---|
[1378] | 46 | |
---|
| 47 | is(yesno('yes'), 1, 'yes is true'); |
---|
| 48 | is(yesno('true'), 1, 'true is true'); |
---|
| 49 | is(yesno('23'), 1, '23 is true'); |
---|
| 50 | is(yesno('no'), 0, 'no is false'); |
---|
| 51 | is(yesno('what'), 'what', 'what is what?'); |
---|