4 use RT::Test no_plan => 1;
5 my ( $url, $m ) = RT::Test->started_ok;
8 my $search = RT::Attribute->new(RT->SystemUser);
9 my $ticket = RT::Ticket->new(RT->SystemUser);
10 my ( $ret, $msg ) = $ticket->Create(
11 Subject => 'base ticket' . $$,
14 Requestor => 'root@localhost',
15 MIMEObj => MIME::Entity->build(
16 From => 'root@localhost',
18 Subject => 'base ticket' . $$,
22 ok( $ret, "ticket created: $msg" );
24 ok( $m->login, 'logged in' );
26 $m->get_ok( $url . "/Search/Chart.html?Query=" . 'id=1' );
27 my ($owner) = $m->content =~ /value="(RT::User-\d+)"/;
30 form_name => 'SaveSearch',
32 SavedSearchDescription => 'first chart',
33 SavedSearchOwner => $owner,
35 button => 'SavedSearchSave',
38 $m->content_contains("Chart first chart saved", 'saved first chart' );
40 my ( $search_uri, $id ) = $m->content =~ /value="(RT::User-\d+-SavedSearch-(\d+))"/;
42 form_name => 'SaveSearch',
43 fields => { SavedSearchLoad => $search_uri },
46 $m->content_like( qr/name="SavedSearchDelete"\s+value="Delete"/,
47 'found Delete button' );
49 qr/name="SavedSearchDescription"\s+value="first chart"/,
50 'found Description input with the value filled'
52 $m->content_like( qr/name="SavedSearchSave"\s+value="Update"/,
53 'found Update button' );
54 $m->content_unlike( qr/name="SavedSearchSave"\s+value="Save"/,
58 form_name => 'SaveSearch',
64 button => 'SavedSearchSave',
67 $m->content_contains("Chart first chart updated", 'found updated message' );
68 $m->content_contains("id=2", 'Query is updated' );
69 $m->content_like( qr/value="Status"\s+selected="selected"/,
70 'GroupBy is updated' );
71 $m->content_like( qr/value="pie"\s+selected="selected"/,
72 'ChartType is updated' );
73 ok( $search->Load($id) );
74 is( $search->SubValue('Query'), 'id=2', 'Query is indeed updated' );
75 is( $search->SubValue('GroupBy'),
76 'Status', 'GroupBy is indeed updated' );
77 is( $search->SubValue('ChartStyle'), 'pie', 'ChartStyle is indeed updated' );
79 # finally, let's test delete
81 form_name => 'SaveSearch',
82 button => 'SavedSearchDelete',
84 $m->content_contains("Chart first chart deleted", 'found deleted message' );
85 $m->content_unlike( qr/value="RT::User-\d+-SavedSearch-\d+"/,
94 for ([A => 'subject="'.$$.'A"'], [BorC => 'subject="'.$$.'B" OR subject="'.$$.'C"']) {
95 $m->get_ok('/Search/Edit.html');
96 $m->form_name('BuildQueryAdvanced');
97 $m->field('Query', $_->[1]);
101 $m->follow_link_ok({id => 'page-chart'});
102 $m->form_name('SaveSearch');
103 $m->field(SavedSearchDescription => $_->[0]);
104 $m->click_ok('SavedSearchSave');
105 $m->text_contains('Chart ' . $_->[0] . ' saved.');
109 $m->form_name('SaveSearch');
110 my @saved_search_ids =
111 $m->current_form->find_input('SavedSearchLoad')->possible_values;
112 shift @saved_search_ids; # first value is blank
114 cmp_ok(@saved_search_ids, '==', 2, 'Two saved charts were made');
116 # TODO get find_link('page-chart')->URI->params to work...
117 sub page_chart_link_has {
118 my ($m, $id, $msg) = @_;
120 $Test::Builder::Level = $Test::Builder::Level + 1;
122 (my $dec_id = $id) =~ s/:/%3A/g;
124 my $chart_url = $m->find_link(id => 'page-chart')->url;
126 $chart_url, qr{SavedChartSearchId=\Q$dec_id\E},
127 $msg || 'Page chart link matches the pattern we expected'
131 # load the first chart
132 $m->field('SavedSearchLoad' => $saved_search_ids[0]);
133 $m->click('SavedSearchLoadSubmit');
135 page_chart_link_has($m, $saved_search_ids[0]);
137 $m->form_name('SaveSearch');
138 is($m->form_number(3)->value('SavedChartSearchId'), $saved_search_ids[0]);
140 $m->form_name('SaveSearch');
142 # now load the second chart
143 $m->field('SavedSearchLoad' => $saved_search_ids[1]);
144 $m->click('SavedSearchLoadSubmit');
146 page_chart_link_has($m, $saved_search_ids[1]);
149 $m->form_number(3)->value('SavedChartSearchId'), $saved_search_ids[1],
150 'Second form is seen as a hidden field'
153 page_chart_link_has($m, $saved_search_ids[1]);