File: json-initialdata.t

package info (click to toggle)
request-tracker5 5.0.3%2Bdfsg-3~deb12u3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 77,648 kB
  • sloc: javascript: 187,930; perl: 79,061; sh: 1,302; makefile: 471; python: 37; php: 15
file content (80 lines) | stat: -rw-r--r-- 2,770 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use warnings;
use strict;

use RT::Test tests => undef;

RT->Config->Set('InitialdataFormatHandlers' => [ 'perl', 'RT::Initialdata::JSON' ]);

# None of this should be in the DB
CheckDB('not_ok');

# Load the db from the initialdata test file
my $initialdata = RT::Test::get_relocatable_file("initialdata.json" => "..", "data", "initialdata");
my ($rv, $msg) = RT->DatabaseHandle->InsertData($initialdata, undef, disconnect_after => 0);
ok ($rv, "Insert test data from $initialdata ($msg)");

# Now all of this should be in the DB
CheckDB('ok');

done_testing();

sub CheckDB {
    no strict 'refs';
    no warnings 'uninitialized';

    my $tester = shift;

    my ($r,$m);
    my $su = RT->SystemUser;

    ($r,$m) = RT::Group->new($su)->LoadByCols(Name => 'Test Group 1');
    &$tester ($r, "Test Group 1 found in DB - should be $tester ($m)");

    my $tu1 = RT::User->new($su);
    ($r,$m) = $tu1->Load('testuser1');
    &$tester ($r, "testuser1 user found in DB - should be $tester ($m)");

    my $tq1 = RT::Queue->new($su);
    ($r,$m) = $tq1->Load('Test Queue 1');
    &$tester ($r, "Test Queue 1 found in DB - should be $tester ($m)");

    &$tester ($tu1->HasRight(Object => $tq1, Right => 'SeeQueue'),
        "testuser1 has SeeQueue on Test Queue 1 - should be $tester"
        ) if ($tu1->id and $tq1->id);

    ($r,$m) = RT::ScripAction->new($su)->Load('Test Action 1');
    &$tester ($r, "Test Action 1 found in DB - should be $tester ($m)");

    ($r,$m) = RT::ScripCondition->new($su)->Load('Test Condition 1');
    &$tester ($r, "Test Condition 1 found in DB - should be $tester ($m)");

    ($r,$m) = RT::Template->new($su)->Load('Test Template 1');
    &$tester ($r, "Test Template 1 found in DB - should be $tester ($m)");

    ($r,$m) = RT::CustomField->new($su)->Load('Favorite Color red or blue');
    &$tester ($r, "Favorite Color CF found in DB - should be $tester ($m)");

    ($r,$m) = RT::CustomField->new($su)->Load('Favorite Song');
    &$tester ($r, "Favorite Song CF found in DB - should be $tester ($m)");

    ($r,$m) = RT::Scrip->new($su)->LoadByCols(Description => 'Test Scrip 1');
    &$tester ($r, "Test Scrip 1 found in DB - should be $tester ($m)");

    ($r,$m) = RT::Attribute->new($su)->LoadByNameAndObject(
        Name => 'Test Search 1',
        Object => RT->System
        );
    &$tester ($r, "Test Search 1 found in DB - should be $tester ($m)");

    my $root = RT::Test->load_or_create_user( Name => 'root' );
    ( $r, $m ) = RT::Attribute->new($su)->LoadByNameAndObject(
        Name   => 'Test Search 2',
        Object => $root
    );
    &$tester( $r, "Test Search 2 found in DB - should be $tester ($m)" );
}

sub not_ok {
    local $Test::Builder::Level = $Test::Builder::Level + 1;
    ok (!shift, shift);
}