root/trunk/t/c/holder-move.t

Revision 19, 3.9 kB (checked in by evdb, 4 years ago)

Changed: Fixed GETs with effects and added loads of tests

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 use strict;
2 use warnings;
3
4 use Test::More tests => 45;
5
6 require 't/helpers.pl';
7
8 use_ok('Scrpbk::C::Holder');
9 use Scrpbk::M::Person;
10 use Scrpbk::M::Holder;
11 use Data::Dumper;
12
13 ok my $mech      = get_mech(),  "set up the Test::WWW::Mechanize object";
14 ok my $test_user = test_user(), "get test user";
15
16 # delete if there are pages found.
17 for ( grep { $_->url =~ m/^[abc]$/ } $test_user->pages ) {
18     fail "found page that should not have been here:" . $_->url;
19     $_->delete;
20 }
21
22 # Log in as test user.
23 ok login_as_test(), "login as test user";
24
25 ################################################################################
26 # Create a few holders on several pages.
27 foreach my $page_ref (qw/a b c/) {
28     ok my $page =
29       $test_user->add_to_pages(
30         { url => $page_ref, name => "Page $page_ref" } ),
31       "Create page '$page_ref'";
32
33     foreach my $column ( 1 .. 2 ) {
34         foreach my $rank ( 1 .. 3 ) {
35             my $holder_name = "$page_ref-$column-$rank";
36             ok my $holder = $test_user->add_to_holders(
37                 {
38                     page => $page,
39                     col  => $column,
40                     rank => $rank,
41                     name => $holder_name
42                 }
43               ),
44               "  Create holder with name: '$holder_name'";
45         }
46     }
47 }
48
49 ################################################################################
50 # Do a few moves and then check that the col and rank are correct.
51
52 # Go to page 'a'
53 $mech->follow_link_ok( { url => '/~' . $test_user->tag }, "go to users page" );
54 $mech->follow_link_ok( { url_regex => qr/page\/a/ }, "go to page 'a'" );
55
56 # Check that the rank is correct.
57 ok holder('a-1-1')->rank < holder('a-1-2')->rank, "a11s rank is less than a12";
58 ok holder('a-1-2')->rank < holder('a-1-3')->rank, "a12s rank is less than a13";
59
60 {    # 'a-1-2' -> move down.
61     $mech->form('page_edit');
62     $mech->click( 'act_moveholder_' . holder('a-1-2') . '_down' );
63     ok holder('a-1-2')->rank > holder('a-1-3')->rank,
64       "a12s rank is greater than a13";
65 }
66
67 {    # 'a-1-2' -> move up.
68     $mech->form('page_edit');
69     $mech->click( 'act_moveholder_' . holder('a-1-2') . '_up' );
70     ok holder('a-1-2')->rank < holder('a-1-3')->rank,
71       "a12s rank is less than a13";
72 }
73
74 {    # 'a-1-2' -> move right
75     $mech->form('page_edit');
76     $mech->click( 'act_moveholder_' . holder('a-1-2') . '_right' );
77     ok holder('a-1-2')->col == 2, "check that 'a-1-2' is now in col 2";
78     ok holder('a-1-2')->rank < holder('a-2-1')->rank,
79       "a12s rank is less than a21";
80 }
81
82 {    # 'a-2-3' -> move left
83     $mech->form('page_edit');
84     $mech->click( 'act_moveholder_' . holder('a-2-3') . '_left' );
85     ok holder('a-2-3')->col == 1, "check that 'a-2-3' is now in col 1";
86     ok holder('a-2-3')->rank < holder('a-1-1')->rank,
87       "a23s rank is less than a11";
88 }
89
90 ################################################################################
91 # Move holders between pages.
92
93 # Go to page b
94 $mech->follow_link_ok( { url_regex => qr/page\/b/ }, "go to page 'b'" );
95
96 {    # Go to edit page for holder b22.
97     my $id = holder('b-2-2')->id;
98     $mech->follow_link_ok( { url_regex => qr/edit\/$id/ },
99         "edit holder 'a22'" );
100
101     # On the form change the page value to 'c';
102     ok $mech->submit_form(
103         form_name => 'edit_holder',
104         fields    => { page => 'Page c' }
105       ),
106       "submit form";
107
108     # Check that we have come through to page c.
109     like $mech->uri, qr/page\/c$/, "check that we are now on page c";
110
111     # Check that the holder has changed correctly.
112     is holder('b-2-2')->page->url, 'c', "Check on right page";
113     is holder('b-2-2')->col, '1', "in correct column";
114     ok holder('b-2-2')->rank < holder('c-1-1')->rank, "first on list";
115 }
116
117 ################################################################################
118 # delete all pages created.
119 ok $_->delete, "delete page"
120   for grep { $_->url =~ m/^[abc]$/ } $test_user->pages;
121
122 ################################################################################
Note: See TracBrowser for help on using the browser.