File: 08tree-node.t

package info (click to toggle)
libhtml-widgets-navmenu-perl 1.1000-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 636 kB
  • sloc: perl: 8,051; makefile: 9
file content (130 lines) | stat: -rw-r--r-- 4,277 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/perl -w

use Test::More tests => 34;

use strict;

BEGIN
{
    use_ok('HTML::Widgets::NavMenu::Tree::Node');    # TEST
}

{
    my $node = HTML::Widgets::NavMenu::Tree::Node->new();
    ok( $node, "Constructing" );                     # TEST

    $node->url("Rabbi/Zalman/");
    is( $node->url(), "Rabbi/Zalman/", "Testing for URL Setting" );    # TEST
    $node->text("Trail of Innocence");
    is( $node->text(), "Trail of Innocence", "Testing for text" );     # TEST
    $node->show_always(1);
    is( $node->show_always(), 1, "Set/get show_always" );              # TEST
    $node->title("It's Raining");
    is( $node->title(), "It's Raining", "Set/get title" );             # TEST
    $node->host("vipe");
    is( $node->host(), "vipe", "Set/get host" );                       # TEST
    $node->url_type("site_abs");
    is( $node->url_type(), "site_abs", "Set/get url_type" );           # TEST

    # Testing again for the same values to see that they are still OK.

    is( $node->url(),  "Rabbi/Zalman/",      "Testing for URL Setting" ); # TEST
    is( $node->text(), "Trail of Innocence", "Testing for text" );        # TEST
    is( $node->show_always(), 1,              "Set/get show_always" );    # TEST
    is( $node->title(),       "It's Raining", "Set/get title" );          # TEST
    is( $node->host(),        "vipe",         "Set/get host" );           # TEST
    is( $node->url_type(),    "site_abs",     "Set/get url_type" );       # TEST
}

{
    my $node = HTML::Widgets::NavMenu::Tree::Node->new();

    ok( ( !$node->separator() ), "Testing Node Separator - False" );      # TEST
    $node->separator(1);
    ok( $node->separator(), "Testing Node Separator - True" );            # TEST
}

{
    my $node = HTML::Widgets::NavMenu::Tree::Node->new();

    ok( ( !$node->hide() ), "Testing Node Hide - False" );                # TEST
    $node->hide(1);
    ok( $node->hide(), "Testing Node Hide - True" );                      # TEST
}

{
    my $node = HTML::Widgets::NavMenu::Tree::Node->new();

    # TEST
    ok( !defined( $node->role() ), "Testing that role is undeffed at start" );
    $node->role("hoola");
    is( $node->role(), "hoola", "Testing role setted value" );            # TEST
}

{
    my $node = HTML::Widgets::NavMenu::Tree::Node->new();

    ok( ( !$node->expanded() ), "Testing node->expanded()" );             # TEST
    $node->expand();
    ok( $node->expanded(), "Testing node->expanded() after expand()" );   # TEST
}

{
    my $node = HTML::Widgets::NavMenu::Tree::Node->new();

    ok( ( !$node->CurrentlyActive() ), "Testing node->CurrentlyActive()" )
        ;                                                                 # TEST
                                                                          # TEST
    ok( ( !$node->expanded() ),
        "Testing node->expanded() before mark_as_current()" );
    $node->mark_as_current();

    # TEST
    ok( $node->CurrentlyActive(),
        "Testing node->CurAct() after mark_as_current()" );

    # TEST
    ok( $node->expanded(), "Testing node->expanded() after mark_as_current()" );
}

{
    my $node = HTML::Widgets::NavMenu::Tree::Node->new();

    # TEST
    is( scalar( @{ $node->subs() } ),
        0, "Testing emptiness of node->subs at start" );

    my $sub_node1 = HTML::Widgets::NavMenu::Tree::Node->new();
    $sub_node1->url("Emperor/Kuzko/");
    $node->add_sub($sub_node1);

    # TEST
    is( scalar( @{ $node->subs() } ), 1, "node->subs len == 1" );

    # TEST
    is( $node->subs()->[0]->url(), "Emperor/Kuzko/", "node->subs contents" );
    my $sub_node2 = HTML::Widgets::NavMenu::Tree::Node->new();
    $sub_node2->url("gimp/ressionist/");
    $node->add_sub($sub_node2);

    # TEST
    is( scalar( @{ $node->subs() } ), 2, "node->subs len == 2" );

    # TEST
    is( $node->subs()->[0]->url(),
        "Emperor/Kuzko/", "node->subs contents again" );

    # TEST
    is( $node->subs()->[1]->url(),
        "gimp/ressionist/", "node->subs[1] contents" );

    # TEST
    ok( !$node->expanded(), "Node is not expanded" );
    my $sub_node3 = HTML::Widgets::NavMenu::Tree::Node->new();
    $sub_node3->expand();
    $node->add_sub($sub_node3);

    # TEST
    ok( $node->expanded(), "Node is expanded after adding an expanded item" );
}