/[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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 29 by dpavlin, Mon Feb 19 18:25:12 2007 UTC revision 152 by dpavlin, Sat Jun 9 10:27:19 2007 UTC
# Line 8  A (very) basic test harness for the Sear Line 8  A (very) basic test harness for the Sear
8    
9  =cut  =cut
10    
11  use Jifty::Test tests => 1;  use Jifty::Test tests => 29;
12    
13  # Make sure we can load the action  # Make sure we can load the action
14  use_ok('Grep::Action::Search');  use_ok('Grep::Action::Search');
15    
16    # 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    {
25            use Log::Log4perl::Level;
26            Jifty->web->log->level( $DEBUG );
27    }
28    
29    # 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    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    # 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    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');

Legend:
Removed from v.29  
changed lines
  Added in v.152

  ViewVC Help
Powered by ViewVC 1.1.26