Versioned Metadata
This commit is contained in:
parent
add255388a
commit
ae3e49d622
14 changed files with 546 additions and 54 deletions
|
|
@ -16,6 +16,7 @@ use lib "$FindBin::Bin/../lib";
|
|||
##versions.
|
||||
|
||||
use WebGUI::Test;
|
||||
use WebGUI::Test::Metadata;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Utility;
|
||||
use WebGUI::Asset;
|
||||
|
|
@ -23,7 +24,7 @@ use WebGUI::VersionTag;
|
|||
|
||||
use Test::More; # increment this value for each test you create
|
||||
use Test::Deep;
|
||||
plan tests => 13;
|
||||
plan tests => 16;
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
$session->user({userId => 3});
|
||||
|
|
@ -74,6 +75,21 @@ WebGUI::Test->addToCleanup(sub {
|
|||
cmp_deeply({}, $snippet->getMetaDataFields, 'snippet has no metadata fields');
|
||||
cmp_deeply({}, $folder->getMetaDataFields, 'folder has no metadata fields');
|
||||
|
||||
subtest 'Field with class data' => sub {
|
||||
my $meta = WebGUI::Test::Metadata->new(
|
||||
$folder, {
|
||||
classes => ['WebGUI::Asset::Wobject::Folder']
|
||||
}
|
||||
);
|
||||
my $id = $meta->fieldId;
|
||||
my $snips = $snippet->getMetaDataFields;
|
||||
my $folds = $folder->getMetaDataFields;
|
||||
ok !exists $snips->{$id}, 'snippet does not have field';
|
||||
ok exists $folds->{$id}, 'but folder does';
|
||||
$snips = $snippet->getAllMetaDataFields;
|
||||
ok exists $snips->{$id}, 'snips returns data with getAll';
|
||||
};
|
||||
|
||||
$snippet->addMetaDataField('new', 'searchEngine', '', 'Search Engine preference', 'text');
|
||||
|
||||
my @snipKeys;
|
||||
|
|
@ -223,6 +239,71 @@ cmp_deeply(
|
|||
'getMetaDataAsTemplateVariables returns proper values for folder'
|
||||
);
|
||||
|
||||
{
|
||||
my $asset = $root->addChild(
|
||||
{
|
||||
className => 'WebGUI::Asset::Snippet',
|
||||
}
|
||||
);
|
||||
WebGUI::Test->addToCleanup($asset);
|
||||
my $meta = WebGUI::Test::Metadata->new($asset);
|
||||
my $ff = $asset->getMetaDataAsFormFields;
|
||||
like $ff->{$meta->fieldName}, qr/input/, 'getMetaDataAsFormFields';
|
||||
}
|
||||
|
||||
# check that asset metadata versioning works properly
|
||||
subtest 'asset metadata versioning' => sub {
|
||||
my $asset = WebGUI::Asset->getImportNode($session)->addChild(
|
||||
{
|
||||
className => 'WebGUI::Asset::Snippet',
|
||||
}
|
||||
);
|
||||
WebGUI::Test->addToCleanup($asset);
|
||||
my $meta = WebGUI::Test::Metadata->new($asset);
|
||||
$meta->update('version one');
|
||||
sleep 1;
|
||||
my $rev2 = $asset->addRevision();
|
||||
is $meta->get(), 'version one', 'v1 for 1';
|
||||
is $meta->get($rev2), 'version one', 'v1 for 2';
|
||||
$meta->update('version two', $rev2);
|
||||
is $meta->get($rev2), 'version two', 'v2 has been set';
|
||||
is $meta->get(), 'version one', 'v1 has not been changed';
|
||||
|
||||
my $dup = $asset->duplicate;
|
||||
|
||||
my $db = $session->db;
|
||||
my $count_rev = sub {
|
||||
my $a = shift;
|
||||
my $sql = q{
|
||||
select count(*)
|
||||
from metaData_values
|
||||
where assetId = ? and revisionDate = ?
|
||||
};
|
||||
$db->quickScalar( $sql, [ $a->getId, $a->get('revisionDate') ] );
|
||||
};
|
||||
my $count_all = sub {
|
||||
my $a = shift;
|
||||
my $sql = 'select count(*) from metaData_values where assetId = ?';
|
||||
$db->quickScalar( $sql, [ $a->getId ] );
|
||||
};
|
||||
|
||||
is $count_all->($asset), 2, 'two values for original';
|
||||
is $count_all->($dup), 1, 'one value for dup';
|
||||
|
||||
is $count_rev->($asset), 1, 'one value for v1';
|
||||
is $count_rev->($rev2), 1, 'one value for v2';
|
||||
|
||||
$rev2->purgeRevision;
|
||||
|
||||
note 'after purge';
|
||||
|
||||
is $count_rev->($asset), 1, 'one value for v1';
|
||||
is $count_rev->($rev2), 0, 'no value for v2';
|
||||
|
||||
is $count_all->($asset), 1, 'one value for original';
|
||||
is $count_all->($dup), 1, 'one value for dup';
|
||||
};
|
||||
|
||||
sub buildNameIndex {
|
||||
my ($fidStruct) = @_;
|
||||
my $nameStruct;
|
||||
|
|
|
|||
75
t/Asset/Shortcut/030-basic-criteria.t
Normal file
75
t/Asset/Shortcut/030-basic-criteria.t
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
use warnings;
|
||||
use strict;
|
||||
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../../lib";
|
||||
|
||||
use Test::More;
|
||||
use WebGUI::Test;
|
||||
use WebGUI::Test::Metadata;
|
||||
|
||||
use WebGUI::Asset;
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
my $root = WebGUI::Asset->getImportNode($session);
|
||||
|
||||
sub asset {
|
||||
my $asset = $root->addChild({ @_ });
|
||||
WebGUI::Test->addToCleanup($asset);
|
||||
return $asset;
|
||||
}
|
||||
|
||||
my $state = WebGUI::Test::Metadata->new($root, fieldName => 'State');
|
||||
my $county = WebGUI::Test::Metadata->new($root, fieldName => 'County');
|
||||
|
||||
my $snip = asset className => 'WebGUI::Asset::Snippet';
|
||||
|
||||
sub town {
|
||||
my ($t, $c, $s) = @_;
|
||||
sleep 1; #for different creation dates
|
||||
my $a = asset(className => 'WebGUI::Asset::Snippet', title => $t);
|
||||
$state->update($s, $a);
|
||||
$county->update($c, $a);
|
||||
return $a;
|
||||
}
|
||||
|
||||
sub town_is {
|
||||
my ($got, $expected, $message) = @_;
|
||||
if ($got->getId eq $expected->getId) {
|
||||
pass($message);
|
||||
}
|
||||
else {
|
||||
fail($message);
|
||||
diag <<DIAG;
|
||||
got: ${ \$got->getTitle }
|
||||
expected: ${ \$expected->getTitle }
|
||||
DIAG
|
||||
}
|
||||
}
|
||||
|
||||
my $grafton = town qw(Grafton Ozaukee Wisconsin);
|
||||
my $baraboo = town qw(Baraboo Sauk Wisconsin);
|
||||
my $centralia = town qw(Centralia Lewis Washington);
|
||||
my $seattle = town qw(Seattle King Washington);
|
||||
|
||||
my $short = asset
|
||||
className => 'WebGUI::Asset::Shortcut',
|
||||
shortcutToAssetId => $snip->getId,
|
||||
disableContentLock => 1;
|
||||
|
||||
sub match {
|
||||
$short->update({ shortcutCriteria => shift });
|
||||
$short->getShortcutByCriteria;
|
||||
}
|
||||
|
||||
plan tests => 4;
|
||||
|
||||
town_is match('State = Wisconsin and County != Sauk'), $grafton;
|
||||
town_is match('State != Washington'), $baraboo;
|
||||
town_is match('County = Lewis'), $centralia;
|
||||
town_is match('County != Sauk'), $seattle;
|
||||
|
||||
# If we don't undef these explicitly, destruction order doesn't happen right
|
||||
# because of closure in town()
|
||||
undef $state;
|
||||
undef $county;
|
||||
Loading…
Add table
Add a link
Reference in a new issue