| 1 | package XAO::testcases::FS::basic; | ||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 2 | ▶ | use XAO::Utils; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 2 | ▶ | use XAO::Objects; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 2 | ▶ | use Error qw(:try); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 2 | ▶ | use base qw(XAO::testcases::FS::base); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | sub test_reset { | ||||||||||||||||||||
| 10 | 0 | ▶ | my $self=shift; | ||||||||||||||||||
|
Subroutine
test_reset: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 0 | my $odb=$self->{'odb'}; | |||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 0 | $self->assert($odb->objname eq 'FS::Glue', | |||||||||||||||||||
| 15 | "Expected odb objname to be FS::Glue, got ".$odb->objname); | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 0 | my $g=$odb->fetch('/'); | |||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 0 | $g->put(project => 'test'); | |||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 0 | $self->assert($g->_driver->connector->sql_connected, | |||||||||||||||||||
| 22 | "Database is NOT connected before reset"); | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | # This is not normally used! | ||||||||||||||||||||
| 25 | 0 | $g->_driver->disconnect; | |||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 0 | $self->stderr_stop(); | |||||||||||||||||||
| 28 | 0 | my $rc=$g->_driver->connector->sql_connected; | |||||||||||||||||||
| 29 | 0 | $self->stderr_restore(); | |||||||||||||||||||
| 30 | 0 | $self->assert(!$rc, | |||||||||||||||||||
| 31 | "Database is still connected after the disconnect"); | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 0 | $self->stderr_stop(); | |||||||||||||||||||
| 34 | 0 | $g->reset; | |||||||||||||||||||
| 35 | 0 | $self->stderr_restore(); | |||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 0 | $self->assert($g->_driver->connector->sql_connected, | |||||||||||||||||||
| 38 | "Database is NOT connected after reset()"); | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 0 | $self->assert($g->get('project') eq 'test', | |||||||||||||||||||
| 41 | "Value is not the same as stored"); | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | # Checking the reset from a non-disconnected state | ||||||||||||||||||||
| 44 | # | ||||||||||||||||||||
| 45 | 0 | $g->reset; | |||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 0 | $self->assert($g->_driver->connector->sql_connected, | |||||||||||||||||||
| 48 | "Database is NOT connected after reset() (connected)"); | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 0 | $self->assert($g->get('project') eq 'test', | |||||||||||||||||||
| 51 | "Value is not the same as stored after reset() (connected)"); | ||||||||||||||||||||
| 52 | } | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | sub test_xaofs { | ||||||||||||||||||||
| 55 | 0 | ▶ | my $self=shift; | ||||||||||||||||||
|
Subroutine
test_xaofs: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 0 | my $odb=$self->{odb}; | |||||||||||||||||||
| 58 | 0 | ▶ | $self->assert(defined($odb) && ref($odb), | ||||||||||||||||||
|
Condition0%0/3
defined $odb && ref $odb
MC/DC0%0/2
defined $odb && ref $odb
defined $odb
ref $odb
Truth table0%0/3
A && B
A= defined $odbB= ref $odb
| |||||||||||||||||||||
| 59 | 'Object database creating failure'); | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 0 | my %matrix=( | |||||||||||||||||||
| 62 | t1 => { | ||||||||||||||||||||
| 63 | path => '/Customers/c2/name', | ||||||||||||||||||||
| 64 | result => 'Test Customer #2', | ||||||||||||||||||||
| 65 | }, | ||||||||||||||||||||
| 66 | t2 => { | ||||||||||||||||||||
| 67 | path => 'xaofs://uri/Customers/c2/name', | ||||||||||||||||||||
| 68 | result => 'Test Customer #2', | ||||||||||||||||||||
| 69 | }, | ||||||||||||||||||||
| 70 | t3 => { | ||||||||||||||||||||
| 71 | path => 'xaofs://collection/class/Data::Customer/2/name', | ||||||||||||||||||||
| 72 | result => 'Test Customer #2', | ||||||||||||||||||||
| 73 | }, | ||||||||||||||||||||
| 74 | t4 => { | ||||||||||||||||||||
| 75 | path => 'xaofs://collection/class/Data::Customer', | ||||||||||||||||||||
| 76 | result => 'XAO::DO::FS::Collection', | ||||||||||||||||||||
| 77 | objname => 'FS::Collection', | ||||||||||||||||||||
| 78 | }, | ||||||||||||||||||||
| 79 | t5 => { | ||||||||||||||||||||
| 80 | path => 'xaofs://collection/class/Data::Customer/', | ||||||||||||||||||||
| 81 | result => 'XAO::DO::FS::Collection', | ||||||||||||||||||||
| 82 | objname => 'FS::Collection', | ||||||||||||||||||||
| 83 | }, | ||||||||||||||||||||
| 84 | t6 => { | ||||||||||||||||||||
| 85 | path => 'xaofs://uri/Customers', | ||||||||||||||||||||
| 86 | result => 'XAO::DO::FS::List', | ||||||||||||||||||||
| 87 | objname => 'FS::List', | ||||||||||||||||||||
| 88 | }, | ||||||||||||||||||||
| 89 | ); | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 0 | foreach my $test (values %matrix) { | |||||||||||||||||||
| 92 | 0 | my $path=$test->{path}; | |||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | 0 | my $got=$odb->fetch($path); | |||||||||||||||||||
| 95 | 0 | my $expect=$test->{result}; | |||||||||||||||||||
| 96 | 0 | ▶ | $self->assert((ref($got) || $got) eq $expect, | ||||||||||||||||||
|
Condition0%0/3
ref $got || $got
MC/DC0%0/2
ref $got || $got
ref $got
$got
Truth table0%0/3
A || B
A= ref $gotB= $got
| |||||||||||||||||||||
| 97 | "Expected '$expect', got '$got'"); | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | 0 | ▶ | if($test->{'objname'}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 100 | 0 | my $objname=$got->objname; | |||||||||||||||||||
| 101 | 0 | $self->assert($objname eq $test->{'objname'}, | |||||||||||||||||||
| 102 | "Expected objname() to return '$test->{'objname'}', got '$objname'"); | ||||||||||||||||||||
| 103 | } | ||||||||||||||||||||
| 104 | } | ||||||||||||||||||||
| 105 | } | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | sub test_objtype { | ||||||||||||||||||||
| 108 | 0 | ▶ | my $self=shift; | ||||||||||||||||||
|
Subroutine
test_objtype: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 109 | 0 | my $odb=$self->{odb}; | |||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | 0 | my $ot=$odb->objtype; | |||||||||||||||||||
| 112 | 0 | $self->assert($ot eq 'Glue', | |||||||||||||||||||
| 113 | "Glue object returned wrong 'objtype' ($ot)"); | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | 0 | my $list=$odb->fetch('/Customers'); | |||||||||||||||||||
| 116 | 0 | $ot=$list->objtype; | |||||||||||||||||||
| 117 | 0 | $self->assert($ot eq 'List', | |||||||||||||||||||
| 118 | "List object returned wrong 'objtype' ($ot)"); | ||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | 0 | my $hash=$list->get('c1'); | |||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | 0 | $ot=$hash->objtype; | |||||||||||||||||||
| 123 | 0 | $self->assert($ot eq 'Hash', | |||||||||||||||||||
| 124 | "Hash object returned wrong 'objtype' ($ot)"); | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | 0 | $self->assert($hash->upper_class eq 'FS::Global', | |||||||||||||||||||
| 127 | "Wrong upper_class() for the customer Hash"); | ||||||||||||||||||||
| 128 | } | ||||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | sub test_uri { | ||||||||||||||||||||
| 131 | 0 | ▶ | my $self=shift; | ||||||||||||||||||
|
Subroutine
test_uri: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 132 | 0 | my $odb=$self->{odb}; | |||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | 0 | my $global=$odb->fetch('/'); | |||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | 0 | my $uri=$global->uri; | |||||||||||||||||||
| 137 | 0 | $self->assert($uri eq '/', | |||||||||||||||||||
| 138 | "Global returned bad URI ('$uri' != '/')"); | ||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | 0 | $uri=$global->uri('Customers'); | |||||||||||||||||||
| 141 | 0 | $self->assert($uri eq '/Customers', | |||||||||||||||||||
| 142 | "Global returned bad URI ('$uri' != '/Customers')"); | ||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | 0 | my $list=$global->get('Customers'); | |||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | 0 | $uri=$list->uri; | |||||||||||||||||||
| 147 | 0 | $self->assert($uri eq '/Customers', | |||||||||||||||||||
| 148 | "Customers returned bad URI ('$uri' != '/Customers')"); | ||||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | 0 | $uri=$list->uri('c2'); | |||||||||||||||||||
| 151 | 0 | $self->assert($uri eq '/Customers/c2', | |||||||||||||||||||
| 152 | "Customers returned bad URI ('$uri' != '/Customers/c2')"); | ||||||||||||||||||||
| 153 | |||||||||||||||||||||
| 154 | 0 | my $hash=$odb->fetch('/Customers/c1'); | |||||||||||||||||||
| 155 | |||||||||||||||||||||
| 156 | 0 | $uri=$hash->uri; | |||||||||||||||||||
| 157 | 0 | $self->assert($uri eq '/Customers/c1', | |||||||||||||||||||
| 158 | "Hash returned bad URI ('$uri' != '/Customers/c1')"); | ||||||||||||||||||||
| 159 | |||||||||||||||||||||
| 160 | 0 | $uri=$hash->uri('name'); | |||||||||||||||||||
| 161 | 0 | $self->assert($uri eq '/Customers/c1/name', | |||||||||||||||||||
| 162 | "Hash returned bad URI ('$uri' != '/Customers/c1/name')"); | ||||||||||||||||||||
| 163 | } | ||||||||||||||||||||
| 164 | |||||||||||||||||||||
| 165 | sub test_upper_class { | ||||||||||||||||||||
| 166 | 0 | ▶ | my $self=shift; | ||||||||||||||||||
|
Subroutine
test_upper_class: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 167 | 0 | my $odb=$self->{odb}; | |||||||||||||||||||
| 168 | |||||||||||||||||||||
| 169 | 0 | my $got=$odb->upper_class('FS::Global'); | |||||||||||||||||||
| 170 | 0 | ▶ | $self->assert(!defined($got), | ||||||||||||||||||
|
Condition0%0/2
$got || ''
MC/DC0%0/1
$got || ''
$got
Truth table0%0/2
A
A= $got
| |||||||||||||||||||||
| 171 | "Got wrong upper class for Global (" . ($got || '') . ")"); | ||||||||||||||||||||
| 172 | |||||||||||||||||||||
| 173 | 0 | $got=$odb->upper_class('Data::Customer'); | |||||||||||||||||||
| 174 | 0 | $self->assert($got eq 'FS::Global', | |||||||||||||||||||
| 175 | "Got wrong upper class for Data::Customer ($got)"); | ||||||||||||||||||||
| 176 | } | ||||||||||||||||||||
| 177 | |||||||||||||||||||||
| 178 | 2 | 1; | |||||||||||||||||||