/[Grep]/t/00-action-Search.t
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /t/00-action-Search.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 152 - (hide annotations)
Sat Jun 9 10:27:19 2007 UTC (16 years, 11 months ago) by dpavlin
File MIME type: application/x-troff
File size: 2479 byte(s)
test Grep::Search also
1 dpavlin 29 #!/usr/bin/env perl
2     use warnings;
3     use strict;
4    
5     =head1 DESCRIPTION
6    
7     A (very) basic test harness for the Search action.
8    
9     =cut
10    
11 dpavlin 152 use Jifty::Test tests => 29;
12 dpavlin 29
13     # Make sure we can load the action
14     use_ok('Grep::Action::Search');
15    
16 dpavlin 147 # Make sure we can load the model
17     use_ok('Grep::Model::Item');
18     use_ok('Grep::Model::Feed');
19    
20     # Grab a system user
21     my $system_user = Grep::CurrentUser->superuser;
22     ok($system_user, "Found a system user");
23    
24 dpavlin 152 {
25     use Log::Log4perl::Level;
26     Jifty->web->log->level( $DEBUG );
27     }
28    
29 dpavlin 147 # create test feed
30     my $feed = Grep::Model::Feed->new(current_user => $system_user);
31     my ($id) = $feed->create(
32     uri => 'http://www.example.com/',
33     title => 'example feed',
34     );
35     ok($id, "Feed create returned success");
36     ok($feed->id, "New Feed has valid id set");
37     is($feed->id, $id, "Create returned the right id");
38    
39     # Try testing a create
40     my $o = Grep::Model::Item->new(current_user => $system_user);
41     ($id) = $o->create(
42     in_feed => $feed,
43     title => 'example title',
44     link => 'http://www.example.com/item1',
45     content => 'some content',
46     );
47     ok($id, "Item create returned success");
48     ok($o->id, "New Item has valid id set");
49     is($o->id, $id, "Create returned the right id");
50    
51 dpavlin 152 use_ok('Grep::Search');
52     ok(my $index = Grep::Search->new, 'Grep::Search->new');
53     isa_ok( $index, 'Grep::Search' );
54    
55     ok($index->add( $o, $system_user->id ), 'add ' . $o->id );
56    
57     ok($index->finish, 'finish');
58    
59 dpavlin 147 # Searches in general
60     my $collection = Grep::Model::ItemCollection->new(current_user => $system_user);
61     $collection->unlimit;
62     is($collection->count, 1, "Finds one record");
63    
64     my $search = Jifty::Test->web->new_action(
65     class => 'Search',
66     moniker => 'search',
67     current_user => $system_user,
68     arguments => {}
69     );
70    
71     isa_ok($search, 'Grep::Action::Search');
72    
73     my %args = %{$search->arguments};
74    
75     ok($args{q}, "Can search on q");
76    
77     # Search on q
78     $search->argument_values({ q => 'example' });
79     $search->run;
80    
81     my $result = $search->result->content('search');
82    
83     isa_ok($result, 'Jifty::Collection');
84     is($result->count, 1);
85    
86 dpavlin 152 isa_ok( $result->first, 'Grep::Model::Item' );
87    
88     eval {
89     is($result->first->in_feed->id, $feed->id);
90     is($result->first->title, 'example title');
91     is($result->first->link, 'http://www.example.com/item1');
92     is($result->first->content, 'some content');
93     };
94    
95     ok($index = Grep::Search->new, 'Grep::Search->new');
96     isa_ok( $index, 'Grep::Search' );
97     ok($index->invindexer->delete_by_term( 'id', $o->id ), 'invindexer->delete_by_term( id, ' . $o->id . ')' );
98    
99     ok($index->finish, 'finish');

  ViewVC Help
Powered by ViewVC 1.1.26