# Copyright (c) 2006 bivio Software, Inc. All Rights Reserved. $Id: # # Visit http://www.bivio.biz for more info. # # This library is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of the # License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; If not, you may get a copy from: # http://www.opensource.org/licenses/lgpl-license.html # # RealmFile.bunit,v 1.5 2006/07/14 23:08:15 nagler Exp $ Request('initialize_fully'); req()->set_realm_and_user(qw(fourem demo)); my($dir) = '/search-parser-realm-file/'; [ { object => class(), compute_params => sub { my(undef, $params) = @_; rollback(); return [class('Search.Parseable')->new( model('RealmFile')->create_with_content({ path => ($params->[1] || $dir) . $params->[0], }, read_file('RealmFile/' . $params->[0])), )]; }, } => [ { method => 'new_text', check_return => sub { my(undef, undef, $expect) = @_; $expect = [@$expect, 'TITLE'] if @$expect == 1; return @$expect == 2 ? [@$expect, qr{^some text\s*$}s] : $expect; }, compute_return => sub { my(undef, $actual) = @_; return [$actual->[0] ? map( ref($_) ? $$_ : $_, $actual->[0]->get(qw(type title text)), ) : ()]; }, } => [ `pdftotext -v 2>&1 < /dev/null` =~ /version/i ? ('t.pdf' => 'application/pdf') : (), 't.txt' => ['text/plain', ''], 't.csv' => ['text/csv', '', "some,text\n"], 't.html' => 'text/html', 't.bwiki' => 'text/plain', 't.eml' => ['message/rfc822', 'TITLE', (sub {chomp(my $x = shift); $x})->(<<'EOF')], Subject: TITLE To: hello From: John Doe some text EOF 'pdf.eml' => ['message/rfc822', 'mysubject', "Subject: mysubject\nTo: SomeList \nFrom: SomeUser \n\nsome text\n\n\nA sample PDF document."], 't.gif' => ['unparsed', '', ''], [TextFile => '/Wiki/'] => ['text/plain', 'TextFile'], TextFile => ['text/plain', '', "some text\n"], BinaryFile => ['unparsed', '', ''], ['t.csv' => '/Wiki'] => ['text/csv', '', "some,text\n"], 't2.bwiki' => ['text/plain', 'TITLE', qr/first text\s+second text\s+third text\s+the end/], 't3.bwiki' => ['text/plain', 'TITLE', qr/email\s+me\s+at\s+foo\@bar.com\s+or\s+A\s+Page\s+home\s+Name\:\s+the\s+end\s+/], 't.doc' => 'application/msword', 't.xls' => ['application/vnd.ms-excel', 'TITLE', "some,text"], 't.docx' => ['application/vnd.openxmlformats-officedocument.wordprocessingml.document', ''], ], { method => 'new_excerpt', compute_return => sub { my(undef, $actual) = @_; return [$actual->[0]->get(qw(excerpt author_user_id author))]; }, } => [ 'excerpt.bwiki' => [qr{^w1( w\d+){42} w44 w45 \.\.\.$}s, realm_id('demo'), ''], 'excerpt.eml' => ['html body', realm_id('demo'), 'Freddy'], ], ], ];