Add new MapPoint code for geolocation, Thingy searching and indexing and a macro for rendering thing data outside of the Thingy.

This commit is contained in:
Colin Kuskie 2011-05-02 13:49:18 -07:00
parent 944c76040a
commit 61534779d5
24 changed files with 1442 additions and 176 deletions

143
t/Asset/MapPoint.t Normal file
View file

@ -0,0 +1,143 @@
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
# 1. The basic framework for a test suite for Map Points.
# Includes setup, cleanup, boilerplate, etc. Basically the really boring,
# repetitive parts of the test that you don't want to write yourself.
use FindBin;
use strict;
use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Session;
use Test::More tests => 18; # increment this value for each test you create
use Test::Deep;
use WebGUI::Asset::Wobject::Map;
use WebGUI::Asset::MapPoint;
use WebGUI::Search;
my $session = WebGUI::Test->session;
#Run as Admin
$session->user({ userId => 3 });
# Do our work in the import node
my $node = WebGUI::Asset->getImportNode($session);
# Grab a named version tag
my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->set({name=>"Map setup"});
# Create a map
my $map = $node->addChild({
className => 'WebGUI::Asset::Wobject::Map',
mapApiKey => undef,
startZoom => "0",
workflowIdPoint => "pbworkflow000000000003",
});
#Commit the map before creating the map point
$versionTag->commit();
WebGUI::Test->addToCleanup($versionTag);
# Create a map point
my $test_point = {
website => 'http://www.plainblack.com',
address1 => '520 University Ave',
address2 => 'Suite 320',
city => 'Madison',
region => 'WI',
zipCode => '53703',
country => 'United States',
phone => '608-555-1212',
fax => '608-555-1212',
email => 'info@plainblack.com',
userDefined1 => 'one-plainblack',
userDefined2 => 'two-plainblack',
userDefined3 => 'three-plainblack',
userDefined4 => 'four-plainblack',
userDefined5 => 'five-plainblack',
};
my $mapPoint = $map->addChild({
className => 'WebGUI::Asset::MapPoint',
latitude => '43.0736',
longitude => '-89.3946',
%{$test_point}
});
#Call commit manually so we don't have to wait on spectre to run the autocommit workflow
$mapPoint->commit;
# Test for a sane object type
isa_ok($mapPoint, 'WebGUI::Asset::MapPoint');
################################################################
#
# indexContent
#
################################################################
# Test indexContent to make sure keywords are added to assetIndex by searching for them and
# ensuring the asset is returned in the results. indexContent itself does not need to be called
# because commit takes care of that for us.
#In all cases we should get back the one map point for these tests.
my $expected = [$mapPoint->getId];
foreach my $keyword (keys %$test_point) {
my $assetIds = WebGUI::Search->new($session)->search({
keywords => $test_point->{$keyword},
lineage => [ $map->get("lineage") ] #Limit the search to just map points under the newly create map.
})->getAssetIds;
is_deeply( $assetIds, $expected, "$keyword found in search" );
}
#my $assetIds = WebGUI::Search->new($session)->search(\%rules)->getAssetIds;
################################################################
#
# processAjaxEditForm
#
################################################################
#Test isHidden
sleep 1; #Make sure we have a different revision date
my $test_point_edit = {
%{$test_point},
'assetId' => $mapPoint->getId,
'isHidden' => 1,
};
$session->request->setup_body($test_point_edit);
$map->www_ajaxEditPointSave;
#Get the newest mapPoint revision
$mapPoint = WebGUI::Asset->newPending($session,$mapPoint->getId);
is($mapPoint->get("isHidden"),1,"isHidden changed");
#TO DO - Try to change isHidden as a user who can add points but cannot edit
#Test isGeocoded
sleep 1; #Make sure we have a different revision date
$test_point_edit = {
%{$test_point},
'assetId' => $mapPoint->getId,
'isGeocoded' => 1,
};
$session->request->setup_body($test_point_edit);
$map->www_ajaxEditPointSave;
#Get the newest mapPoint revision
$mapPoint = WebGUI::Asset->newPending($session,$mapPoint->getId);
is($mapPoint->get("isGeocoded"),1,"isGeocoded changed");

View file

@ -0,0 +1,97 @@
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use FindBin;
use strict;
use JSON qw/from_json/;
use lib "$FindBin::Bin/../../../lib";
##The goal of this test is to test the searching for and returning data about
##records created with WebGUI::Search::Index::addRecord;
use WebGUI::Test;
use WebGUI::Session;
use Test::More tests => 6; # increment this value for each test you create
use Test::Deep;
use WebGUI::Asset::Wobject::Search;
my $session = WebGUI::Test->session;
$session->user({userId => 3});
# Do our work in the import node
my $node = WebGUI::Asset->getImportNode($session);
my $default = WebGUI::Asset->getDefault($session);
my $importArticle = $node->addChild({
className => 'WebGUI::Asset::Wobject::Article',
description => 'rockhound',
});
my $templateId = 'SEARCH_ASSET_TEMPLATE_';
my $templateMock = Test::MockObject->new({});
$templateMock->set_isa('WebGUI::Asset::Template');
$templateMock->set_always('getId', $templateId);
$templateMock->set_always('prepare', 1);
my $templateVars;
$templateMock->mock('process', sub { $templateVars = $_[1]; } );
my $defaultArticle = $default->addChild({
className => 'WebGUI::Asset::Wobject::Article',
description => 'shawshank prison',
url => 'introduction'
});
my $search = $default->addChild({
className => 'WebGUI::Asset::Wobject::Search',
searchRoot => $default->getId,
templateId => $templateId,
});
my $tag = WebGUI::VersionTag->getWorking($session);
$tag->commit;
WebGUI::Test->addToCleanup($tag);
my $indexer = WebGUI::Search::Index->new($defaultArticle);
$indexer->addRecord(url => 'brochure', keywords => 'roomy spacious prison');
{
WebGUI::Test->mockAssetId($templateId, $templateMock);
$search->prepareView();
$session->request->setup_body({doit => 1, keywords => 'shawshank'});
$search->view();
WebGUI::Test->unmockAssetId($templateId);
}
is scalar @{ $templateVars->{result_set} }, 1, 'search for shawshank, returns 1 record';
is $templateVars->{result_set}->[0]->{url}, 'introduction', '... url is correct';
{
WebGUI::Test->mockAssetId($templateId, $templateMock);
$search->prepareView();
$session->request->setup_body({doit => 1, keywords => 'prison'});
$search->view();
WebGUI::Test->unmockAssetId($templateId);
}
is scalar @{ $templateVars->{result_set} }, 2, 'search for prison, returns 2 records';
cmp_bag(
[ map { $_->{url} } @{ $templateVars->{result_set} } ],
[qw/ introduction brochure/ ],
'... urls are correct'
);
cmp_bag(
[ map { $_->{groupIdView} } @{ $templateVars->{result_set} } ],
[ 7, 7 ],
' groupIdViews are correct (2nd record inherits from the parent)'
);
cmp_bag(
[ map { $_->{title_nohighlight} } @{ $templateVars->{result_set} } ],
[ ($defaultArticle->get('title'))x2 ],
' titles are correct (2nd record inherits from the parent)'
);

View file

@ -38,6 +38,8 @@ my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->set({name=>"Thingy Test"});
WebGUI::Test->addToCleanup($versionTag);
my $thingy = $node->addChild({className=>'WebGUI::Asset::Wobject::Thingy'});
$versionTag->commit;
$thingy = $thingy->cloneFromDb;
# Test for a sane object type
isa_ok($thingy, 'WebGUI::Asset::Wobject::Thingy');
@ -257,6 +259,7 @@ cmp_deeply(
field_type => "textarea",
}],
viewScreenTitle => "",
'Thingy field' => 'test value',
},
'Getting newly added thing data as JSON: www_viewThingDataViaAjax returns correct data as JSON.'
);

View file

@ -0,0 +1,294 @@
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use Test::MockTime qw/:all/;
use FindBin;
use strict;
use lib "$FindBin::Bin/../../../lib";
##The goal of this test is to test editThingDataSave, particularly those things not tested in Thingy.t
use WebGUI::Test;
use WebGUI::Session;
use Test::More tests => 24; # increment this value for each test you create
use Test::Deep;
use JSON;
use WebGUI::Asset::Wobject::Thingy;
use WebGUI::Search;
use WebGUI::Search::Index;
use Data::Dumper;
my $session = WebGUI::Test->session;
# Do our work in the import node
my $node = WebGUI::Asset->getImportNode($session);
set_relative_time(-60);
my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->set({name=>"Thingy Test"});
WebGUI::Test->addToCleanup($versionTag);
my $thingy = $node->addChild({
className => 'WebGUI::Asset::Wobject::Thingy',
groupIdView => 7,
url => 'some_thing',
});
is $session->db->quickScalar('select count(*) from assetIndex where assetId=?',[$thingy->getId]), 0, 'no records yet';
$versionTag->commit;
$thingy = $thingy->cloneFromDb;
# Test indexThing, without needing a real thing
my $groupIdEdit = $thingy->get("groupIdEdit");
my %thingProperties = (
thingId => "THING_RECORD",
label => 'Label',
editScreenTitle => 'Edit',
editInstructions => 'instruction_edit',
groupIdAdd => $groupIdEdit,
groupIdEdit => $groupIdEdit,
saveButtonLabel => 'save',
afterSave => 'searchThisThing',
editTemplateId => "ThingyTmpl000000000003",
groupIdView => '2',
viewTemplateId => "ThingyTmpl000000000002",
defaultView => 'searchThing',
searchScreenTitle => 'Search',
searchDescription => 'description_search',
groupIdSearch => $groupIdEdit,
groupIdExport => $groupIdEdit,
groupIdImport => $groupIdEdit,
searchTemplateId => "ThingyTmpl000000000004",
thingsPerPage => 25,
);
is $session->db->quickScalar('select count(*) from assetIndex where assetId=?',[$thingy->getId]), 1, 'committing the asset adds a record';
$thingy->indexThing(\%thingProperties);
is $session->db->quickScalar('select count(*) from assetIndex where assetId=?',[$thingy->getId]), 2, 'indexThing: adds a record to the assetIndex';
my $record;
$record = $session->db->quickHashRef('select * from assetIndex where assetId=?',[$thingy->getId]);
cmp_deeply(
$record,
superhashof({
subId => 'THING_RECORD',
url => $thingy->getUrl('func=search;thingId=THING_RECORD'),
title => 'Label',
groupIdView => 2,
keywords => all(
re('Label'),
re('Edit'),
re('instruction_edit'),
re('Search'),
re('description_search'),
),
}),
'... correct record entered via indexThing'
);
$thingy->deleteThingIndex('THING_RECORD');
is $session->db->quickScalar('select count(*) from assetIndex where assetId=?',[$thingy->getId]), 1, 'deleteThingIndex removes the record of the Thing from assetIndex';
$thingy->indexThing(\%thingProperties);
$thingProperties{saveButtonLabel} = 'Save';
$thingy->indexThing(\%thingProperties);
is $session->db->quickScalar('select count(*) from assetIndex where assetId=?',[$thingy->getId]), 2, 'indexThing safely handles updating the same record';
$thingy->deleteThingIndex('THING_RECORD');
my $thingId = $thingy->addThing(\%thingProperties);
%thingProperties = %{ $thingy->getThing($thingId) };
$thingy->indexThing(\%thingProperties);
is $session->db->quickScalar('select count(*) from assetIndex where assetId=?',[$thingy->getId]), 2, 'two index entries, setup for indexThingData';
my $field1Id = $thingy->addField({
thingId => $thingId,
fieldId => "new",
label => "textual",
dateCreated => time(),
fieldType => "text",
status => "editable",
display => 1,
}, 0);
$thingy->indexThingData($thingId, {
thingDataId => 'THING_DATA',
"field_$field1Id" => 'texty',
});
is $session->db->quickScalar('select count(*) from assetIndex where assetId=?',[$thingy->getId]), 2, 'indexThingData added no records, displayInSearch=0';
$thingy->deleteField($field1Id, $thingId);
$field1Id = $thingy->addField({
thingId => $thingId,
fieldId => "new",
label => "textual",
dateCreated => time(),
fieldType => "text",
status => "editable",
display => 1,
displayInSearch => 1,
}, 0);
$thingy->indexThingData($thingId, {
thingDataId => 'THING_DATA',
"field_$field1Id" => 'texty',
});
is $session->db->quickScalar('select count(*) from assetIndex where assetId=?',[$thingy->getId]), 3, 'indexThingData added one record, displayInSearch=1';
$thingy->indexThingData($thingId, {
thingDataId => 'THING_DATA',
"field_$field1Id" => 'texty',
});
is $session->db->quickScalar('select count(*) from assetIndex where assetId=?',[$thingy->getId]), 3, 'indexThingData added 1 record';
my $search;
$search = WebGUI::Search->new($session)->search({ lineage => [$thingy->get('lineage')], keywords => 'texty'});
is @{ $search->getAssetIds }, 1, '... verify that it is the right record';
cmp_deeply(
$search->getPaginatorResultSet->getPageData,
[
{
assetId => $thingy->getId,
className => 'WebGUI::Asset::Wobject::Thingy',
creationDate => ignore(),
groupIdEdit => $groupIdEdit,
groupIdView => 2, ##From the thing
ownerUserId => 3,
revisionDate => ignore(),
score => ignore(),
synopsis => ignore(),
title => 'Label', ##From the Thing's label
url => $thingy->getUrl('func=viewThingData;thingId='.$thingId.';thingDataId=THING_DATA'),
}
],
'Checking indexed data for the thingData'
);
$thingy->deleteThingDataIndex('THING_DATA');
is $session->db->quickScalar('select count(*) from assetIndex where assetId=?',[$thingy->getId]), 2, 'deleteThingDataIndex deleted just 1 record';
my $field2Id = $thingy->addField({
thingId => $thingId,
fieldId => "new",
label => "dated",
dateCreated => time(),
fieldType => "date",
status => "editable",
display => 1,
displayInSearch => 1,
viewScreenTitle => 1,
}, 0);
my $birthday = WebGUI::Test->webguiBirthday;
$thingy->indexThingData($thingId, {
thingDataId => 'THING_DATA',
"field_$field1Id" => 'texty',
"field_$field2Id" => $birthday,
});
is $session->db->quickScalar('select count(*) from assetIndex where assetId=?',[$thingy->getId]), 3, 'indexThingData added 1 record';
$search = WebGUI::Search->new($session)->search({ lineage => [$thingy->get('lineage')], keywords => $birthday});
is @{ $search->getAssetIds }, 0, 'birthday not added as a keyword';
$search = WebGUI::Search->new($session)->search({ lineage => [$thingy->get('lineage')], keywords => 'texty'});
is @{ $search->getAssetIds }, 1, 'texty added as a keyword';
$search = WebGUI::Search->new($session)->search({ lineage => [$thingy->get('lineage')], keywords => 'texty'});
cmp_deeply(
$search->getPaginatorResultSet->getPageData,
[
{
assetId => $thingy->getId,
className => 'WebGUI::Asset::Wobject::Thingy',
creationDate => ignore(),
groupIdEdit => $groupIdEdit,
groupIdView => 2, ##From the thing
ownerUserId => 3,
revisionDate => ignore(),
score => ignore(),
synopsis => ignore(),
title => '8/16/2001', ##From viewScreenTitle, which is $birthday in user's preferred date format
url => $thingy->getUrl('func=viewThingData;thingId='.$thingId.';thingDataId=THING_DATA'),
}
],
'Checking indexed data for the thingData'
);
$thingy->deleteThingDataIndex('THING_DATA');
my $field3Id = $thingy->addField({
thingId => $thingId,
fieldId => "new",
label => "nailfile",
dateCreated => time(),
fieldType => "file",
status => "editable",
display => 1,
displayInSearch => 1,
}, 0);
my $storage = WebGUI::Storage->create($session);
$storage->addFileFromScalar('filing.txt', 'filings');
WebGUI::Test->addToCleanup($storage);
$thingy->indexThingData($thingId, {
thingDataId => 'THING_DATA',
"field_$field1Id" => 'texty',
"field_$field2Id" => $birthday,
"field_$field3Id" => $storage->getId,
});
$search = WebGUI::Search->new($session)->search({ lineage => [$thingy->get('lineage')], keywords => 'texty'});
is @{ $search->getAssetIds }, 1, 'texty added as a keyword';
$search = WebGUI::Search->new($session)->search({ lineage => [$thingy->get('lineage')], keywords => 'filings'});
is @{ $search->getAssetIds }, 1, 'filings added as a keyword from a file';
restore_time();
##Make a real data entry for indexContent
$thingy->deleteThingDataIndex('THING_DATA');
$thingy->editThingDataSave($thingId, 'new', {
thingDataId => 'new',
"field_$field1Id" => 'texty',
"field_$field2Id" => $birthday,
"field_$field3Id" => $storage->getId,
});
$search = WebGUI::Search->new($session)->search({ lineage => [$thingy->get('lineage')], });
is @{ $search->getAssetIds }, 3, 'setup for indexContent, start with 3 records...';
my $updateTag = WebGUI::VersionTag->getWorking($session);
WebGUI::Test->addToCleanup($updateTag);
$thingy = $thingy->addRevision({ url => 'wild_thing' });
$updateTag->commit;
$thingy = $thingy->cloneFromDb;
$search = WebGUI::Search->new($session)->search({ lineage => [$thingy->get('lineage')], });
is @{ $search->getAssetIds }, 3, '... end with 3 records';
my $records = $search->getResultSet();
my @urls;
while (my $record = $records->hashRef) {
push @urls, $record->{url};
}
cmp_deeply(
\@urls,
array_each(re('wild_thing')),
'All search URLs updated on commit'
) or diag Dumper(\@urls);
$search = WebGUI::Search->new($session)->search({ lineage => [$thingy->get('lineage')], keywords => 'texty'});
is @{ $search->getAssetIds }, 1, 'setup for deleteField, texty keyword has one hit';
$thingy->deleteField($field1Id, $thingId);
$search = WebGUI::Search->new($session)->search({ lineage => [$thingy->get('lineage')], keywords => 'texty'});
is @{ $search->getAssetIds }, 0, 'deleteField causes the thing to be reindexed';

View file

@ -40,7 +40,7 @@ WebGUI::Test->addToCleanup(
#----------------------------------------------------------------------------
# Tests
plan tests => 16; # Increment this number for each test you create
plan tests => 24; # Increment this number for each test you create
use_ok( 'WebGUI::Search::Index' );
@ -72,6 +72,7 @@ cmp_deeply (
re("keyword1"), re("keyword2"),
),
lineage => $article->get('lineage'),
subId => undef,
},
"Index has correct information"
);
@ -84,7 +85,7 @@ is( $indexer->getId, $article->getId, "getId() returns assetId" );
# setIsPublic
$indexer->setIsPublic(0);
is( $db->quickScalar( "SELECT isPublic FROM assetIndex WHERE assetId=?", [$article->getId] ),
is( $db->quickScalar( "SELECT isPublic FROM assetIndex WHERE assetId=? and url=?", [$article->getId, $article->get('url')] ),
0,
"setIsPublic updates database",
);
@ -94,7 +95,7 @@ isa_ok( $indexer->session, 'WebGUI::Session', 'session returns session' );
# updateSynopsis
$indexer->updateSynopsis( "A new synopsis" );
is( $db->quickScalar( "SELECT synopsis FROM assetIndex WHERE assetId=?", [$article->getId] ),
is( $db->quickScalar( "SELECT synopsis FROM assetIndex WHERE assetId=? and url=?", [$article->getId, $article->get('url')] ),
"A new synopsis",
"updateSynopsis updates assetIndex"
);
@ -109,9 +110,9 @@ isnt(
# TODO
# addKeywords
my $currentKeywords = $db->quickScalar( "SELECT keywords FROM assetIndex WHERE assetId=?", [$article->getId] );
my $currentKeywords = $db->quickScalar( "SELECT keywords FROM assetIndex WHERE assetId=? and url=?", [$article->getId, $article->get('url')] );
$indexer->addKeywords("shawshank");
my $newKeywords = $db->quickScalar( "SELECT keywords FROM assetIndex WHERE assetId=?", [$article->getId] );
my $newKeywords = $db->quickScalar( "SELECT keywords FROM assetIndex WHERE assetId=? and url=?", [$article->getId, $article->get('url')] );
like( $newKeywords, qr{$currentKeywords}, "addKeywords keeps old keywords" );
like( $newKeywords, qr{shawshank}, "addKeywords adds the keywords" );
@ -123,7 +124,7 @@ $article->update({
} );
$indexer = WebGUI::Search::Index->create( $article );
ok ( $row = $db->quickHashRef( "SELECT * FROM assetIndex WHERE assetId=?", [ $article->getId ] ),
ok ( $row = $db->quickHashRef( "SELECT * FROM assetIndex WHERE assetId=? and url=?", [ $article->getId, $article->get('url') ] ),
"assetId exists in assetIndex"
);
cmp_deeply (
@ -148,6 +149,7 @@ cmp_deeply (
re("keyword1"), re("keyword2"),
),
lineage => $article->get('lineage'),
subId => undef,
},
"Index has synopsis information in keywords"
);
@ -161,7 +163,7 @@ $article->update({
});
$indexer = WebGUI::Search::Index->create( $article );
$row = $db->quickHashRef( "SELECT * FROM assetIndex WHERE assetId=?", [ $article->getId ]);
$row = $db->quickHashRef( "SELECT * FROM assetIndex WHERE assetId=? and url=?", [ $article->getId, $article->get('url') ]);
cmp_deeply (
$row,
{
@ -184,6 +186,7 @@ cmp_deeply (
re("keyword1"), re("keyword2"),
),
lineage => $article->get('lineage'),
subId => undef,
},
"Index has description in keywords"
);
@ -197,7 +200,7 @@ $article->update({
});
$indexer = WebGUI::Search::Index->create( $article );
$row = $db->quickHashRef( "SELECT * FROM assetIndex WHERE assetId=?", [ $article->getId ] );
$row = $db->quickHashRef( "SELECT * FROM assetIndex WHERE assetId=? and url=?", [ $article->getId, $article->get('url') ] );
cmp_deeply (
$row,
{
@ -219,6 +222,7 @@ cmp_deeply (
re("keyword1"), re("keyword2"),
),
lineage => $article->get('lineage'),
subId => undef,
},
"Index has synopsis and description in keywords"
);
@ -230,7 +234,7 @@ $article->update({
});
$indexer = WebGUI::Search::Index->create( $article );
$row = $db->quickHashRef( "SELECT * FROM assetIndex WHERE assetId=?", [ $article->getId ] );
$row = $db->quickHashRef( "SELECT * FROM assetIndex WHERE assetId=? and url=?", [ $article->getId, $article->get('url') ] );
cmp_deeply (
$row,
superhashof({
@ -256,7 +260,7 @@ SKIP: {
});
$indexer = WebGUI::Search::Index->create( $article );
$row = $db->quickHashRef( "SELECT * FROM assetIndex WHERE assetId=?", [ $article->getId ] );
$row = $db->quickHashRef( "SELECT * FROM assetIndex WHERE assetId=? and url=?", [ $article->getId, $article->get('url') ] );
cmp_deeply (
$row,
superhashof({
@ -270,4 +274,39 @@ SKIP: {
);
}
#----------------------------------------------------------------------------
# Test addRecord
note "addRecord";
$article->update({
description => "descriptive",
});
$indexer = WebGUI::Search::Index->create( $article );
is $session->db->quickScalar('select count(*) from assetIndex where assetId=?', [$article->getId]), 1, 'create puts 1 record into the db';
$indexer->addRecord( url => 'something else');
is $session->db->quickScalar('select count(*) from assetIndex where assetId=?', [$article->getId]), 1, 'addRecord does nothing without url and keywords entries';
$indexer->addRecord( keywords => 'something else');
is $session->db->quickScalar('select count(*) from assetIndex where assetId=?', [$article->getId]), 1, 'addRecord does nothing without url and keywords entries';
$indexer->addRecord( keywords => 'something else', url => '', );
is $session->db->quickScalar('select count(*) from assetIndex where assetId=?', [$article->getId]), 1, 'addRecord does nothing without url and keywords entries';
$indexer->addRecord( keywords => 'something else', url => 'another/thing/coming', );
is $session->db->quickScalar('select count(*) from assetIndex where assetId=?', [$article->getId]), 2, 'new record added';
my %original_record = $session->db->quickHash('select * from assetIndex where assetId=? and url=?', [$article->getId, $article->get('url')]);
my %new_record = $session->db->quickHash('select * from assetIndex where assetId=? and url=?', [$article->getId, 'another/thing/coming']);
delete @original_record{qw/url keywords/};
delete @new_record{qw/url keywords/};
cmp_deeply(\%original_record, \%new_record, 'records are the same, aside from url and keywords');
$indexer->delete;
is $session->db->quickScalar('select count(*) from assetIndex where assetId=?', [$article->getId]), 0, 'all records deleted';
$indexer = WebGUI::Search::Index->create( $article );
$indexer->addRecord(url => 'other', keywords => 'yada yada yada', lineage => 'hike');
my %original_record = $session->db->quickHash('select * from assetIndex where assetId=? and url=?', [$article->getId, $article->get('url')]);
my %new_record = $session->db->quickHash('select * from assetIndex where assetId=? and url=?', [$article->getId, 'other']);
is $original_record{lineage}, $new_record{lineage}, 'lineage is not allowed to be overridden';
#vim:ft=perl