From: <chr...@us...> - 2006-05-15 22:14:31
|
Revision: 866 Author: chromatic Date: 2006-05-15 15:14:20 -0700 (Mon, 15 May 2006) ViewCVS: http://svn.sourceforge.net/everydevel/?rev=866&view=rev Log Message: ----------- r16721@windwheel: chromatic | 2006-05-15 15:14:13 -0700 Ported usergroup tests to the new style. Modified Paths: -------------- trunk/ebase/MANIFEST trunk/ebase/t/Node/usergroup.t Added Paths: ----------- trunk/ebase/lib/Everything/Node/Test/usergroup.pm Property Changed: ---------------- trunk/ebase/ Property changes on: trunk/ebase ___________________________________________________________________ Name: svk:merge - a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:16719 + a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:16721 Modified: trunk/ebase/MANIFEST =================================================================== --- trunk/ebase/MANIFEST 2006-05-15 22:07:05 UTC (rev 865) +++ trunk/ebase/MANIFEST 2006-05-15 22:14:20 UTC (rev 866) @@ -105,6 +105,7 @@ lib/Everything/Node/Test/setting.pm lib/Everything/Node/Test/themesetting.pm lib/Everything/Node/Test/user.pm +lib/Everything/Node/Test/usergroup.pm lib/Everything/Node/Test/workspace.pm lib/Everything/Nodeball.pm lib/Everything/NodeBase.pm Added: trunk/ebase/lib/Everything/Node/Test/usergroup.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/usergroup.pm (rev 0) +++ trunk/ebase/lib/Everything/Node/Test/usergroup.pm 2006-05-15 22:14:20 UTC (rev 866) @@ -0,0 +1,23 @@ +package Everything::Node::Test::usergroup; + +use strict; +use warnings; + +use base 'Everything::Node::Test::nodegroup'; +use Test::More; + +sub test_conflicts_with :Test( 1 ) +{ + my $self = shift; + my $node = $self->{node}; + ok( ! $node->conflictsWith(), 'conflictsWith() should return false' ); +} + +sub test_update_from_import :Test( 1 ) +{ + my $self = shift; + my $node = $self->{node}; + ok( ! $node->updateFromImport(), 'updateFromImport() should return false' ); +} + +1; Property changes on: trunk/ebase/lib/Everything/Node/Test/usergroup.pm ___________________________________________________________________ Name: svn:mime-type + text/plain; charset=UTF-8 Name: svn:eol-style + native Modified: trunk/ebase/t/Node/usergroup.t =================================================================== --- trunk/ebase/t/Node/usergroup.t 2006-05-15 22:07:05 UTC (rev 865) +++ trunk/ebase/t/Node/usergroup.t 2006-05-15 22:14:20 UTC (rev 866) @@ -1,33 +1,4 @@ -#!/usr/bin/perl +#! perl -use strict; -use warnings; - -BEGIN -{ - chdir 't' if -d 't'; - use lib 'lib'; -} - -use Test::More tests => 6; - -my $module = 'Everything::Node::usergroup'; -use_ok( $module ) or exit; - -ok( $module->isa( 'Everything::Node::nodegroup' ), - 'usergroup should extend nodegroup' ); - -can_ok( $module, 'dbtables' ); -my @tables = $module->dbtables(); -is_deeply( \@tables, [qw( node )], - 'dbtables() should return node tables' ); - -ok( - !Everything::Node::usergroup::conflictsWith(), - 'conflictsWith() should return false' -); - -ok( - !Everything::Node::usergroup::updateFromImport(), - 'updateFromImport() should return false' -); +use Everything::Node::Test::usergroup; +Everything::Node::Test::usergroup->runtests(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-05-15 21:24:47
|
Revision: 861 Author: chromatic Date: 2006-05-15 14:24:36 -0700 (Mon, 15 May 2006) ViewCVS: http://svn.sourceforge.net/everydevel/?rev=861&view=rev Log Message: ----------- r16711@windwheel: chromatic | 2006-05-15 14:24:13 -0700 Fixed the SUPER() call. Modified Paths: -------------- trunk/ebase/lib/Everything/Node/document.pm Property Changed: ---------------- trunk/ebase/ Property changes on: trunk/ebase ___________________________________________________________________ Name: svk:merge - a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:16664 + a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:16711 Modified: trunk/ebase/lib/Everything/Node/document.pm =================================================================== --- trunk/ebase/lib/Everything/Node/document.pm 2006-05-12 23:05:56 UTC (rev 860) +++ trunk/ebase/lib/Everything/Node/document.pm 2006-05-15 21:24:36 UTC (rev 861) @@ -22,7 +22,7 @@ sub dbtables { my $self = shift; - return 'document', $self->SUPER::dbtables(); + return 'document', $self->SUPER(); } 1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-05-15 21:24:55
|
Revision: 862 Author: chromatic Date: 2006-05-15 14:24:46 -0700 (Mon, 15 May 2006) ViewCVS: http://svn.sourceforge.net/everydevel/?rev=862&view=rev Log Message: ----------- r16712@windwheel: chromatic | 2006-05-15 14:24:25 -0700 Ported the nodemethod tests to the new form. Modified Paths: -------------- trunk/ebase/MANIFEST trunk/ebase/t/Node/nodemethod.t Added Paths: ----------- trunk/ebase/lib/Everything/Node/Test/nodemethod.pm Property Changed: ---------------- trunk/ebase/ Property changes on: trunk/ebase ___________________________________________________________________ Name: svk:merge - a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:16711 + a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:16712 Modified: trunk/ebase/MANIFEST =================================================================== --- trunk/ebase/MANIFEST 2006-05-15 21:24:36 UTC (rev 861) +++ trunk/ebase/MANIFEST 2006-05-15 21:24:46 UTC (rev 862) @@ -93,9 +93,10 @@ lib/Everything/Node/Test/location.pm lib/Everything/Node/Test/mail.pm lib/Everything/Node/Test/node.pm -lib/Everything/Node/Test/nodelet.pm lib/Everything/Node/Test/nodeball.pm lib/Everything/Node/Test/nodegroup.pm +lib/Everything/Node/Test/nodelet.pm +lib/Everything/Node/Test/nodemethod.pm lib/Everything/Node/Test/nodetype.pm lib/Everything/Node/Test/restricted_superdoc.pm lib/Everything/Node/Test/superdoc.pm Added: trunk/ebase/lib/Everything/Node/Test/nodemethod.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/nodemethod.pm (rev 0) +++ trunk/ebase/lib/Everything/Node/Test/nodemethod.pm 2006-05-15 21:24:46 UTC (rev 862) @@ -0,0 +1,30 @@ +package Everything::Node::Test::nodemethod; + +use strict; +use warnings; + +use base 'Everything::Node::Test::node'; +use Test::More; + +sub test_dbtables :Test( 2 ) +{ + my $self = shift; + my $class = $self->node_class(); + + can_ok( $class, 'dbtables' ); + + my @tables = $class->dbtables(); + is_deeply( \@tables, [qw( nodemethod node )], + 'dbtables() should return node tables' ); +} + +sub test_get_identifying_fields :Test( 1 ) +{ + my $self = shift; + my $node = $self->{node}; + + is_deeply( $node->getIdentifyingFields(), [ 'supports_nodetype' ], + 'getIdentifyingFields() should report "supports_nodetype"' ); +} + +1; Property changes on: trunk/ebase/lib/Everything/Node/Test/nodemethod.pm ___________________________________________________________________ Name: svn:mime-type + text/plain; charset=UTF-8 Name: svn:eol-style + native Modified: trunk/ebase/t/Node/nodemethod.t =================================================================== --- trunk/ebase/t/Node/nodemethod.t 2006-05-15 21:24:36 UTC (rev 861) +++ trunk/ebase/t/Node/nodemethod.t 2006-05-15 21:24:46 UTC (rev 862) @@ -1,61 +1,4 @@ -#!/usr/bin/perl +#! perl -use strict; -use warnings; - -BEGIN -{ - chdir 't' if -d 't'; - use lib 'lib'; -} - -use FakeNode; -use Test::More tests => 12; - -my $module = 'Everything::Node::nodemethod'; -use_ok( $module ) or exit; - -ok( $module->isa( 'Everything::Node::node' ), 'nodemethod should extend node' ); - -ok( $INC{'Everything/Node.pm'}, - 'Everything::Node::nodemethod should use Everything::Node' -); - -can_ok( $module, 'dbtables' ); -my @tables = $module->dbtables(); -is_deeply( \@tables, [qw( nodemethod node )], - 'dbtables() should return node tables' ); - -is( Everything::Node::nodemethod::getIdentifyingFields()->[0], - 'supports_nodetype', - 'getIdentifyingFields() should report "supports_nodetype"' ); - -my $node = FakeNode->new(); -$node->{DB}{cache} = $node; -$node->{type} = 'type'; - -SKIP: -{ - my @subs = ( - \&Everything::Node::nodemethod::insert, - \&Everything::Node::nodemethod::update, - \&Everything::Node::nodemethod::nuke - ); - - skip( 'insert(), update(), nuke() not defined', 6 ) - unless grep { defined &$_ } @subs; - - foreach my $method (@subs) - { - - $node->{_calls} = []; - $method->($node); - is( $node->{_calls}[0][0], - 'SUPER', '... other methods should call SUPER()' ); - is( - join( ' ', @{ $node->{_calls}[1] } ), - 'incrementGlobalVersion type', - '... and should call incrementGlobalVersion() with type' - ); - } -} +use Everything::Node::Test::nodemethod; +Everything::Node::Test::nodemethod->runtests(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-05-15 22:02:54
|
Revision: 864 Author: chromatic Date: 2006-05-15 15:02:43 -0700 (Mon, 15 May 2006) ViewCVS: http://svn.sourceforge.net/everydevel/?rev=864&view=rev Log Message: ----------- r16717@windwheel: chromatic | 2006-05-15 15:02:31 -0700 Ported workspace tests to new system. Modified Paths: -------------- trunk/ebase/MANIFEST trunk/ebase/lib/Everything/Node/workspace.pm trunk/ebase/t/Node/workspace.t Added Paths: ----------- trunk/ebase/lib/Everything/Node/Test/workspace.pm Property Changed: ---------------- trunk/ebase/ Property changes on: trunk/ebase ___________________________________________________________________ Name: svk:merge - a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:16715 + a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:16717 Modified: trunk/ebase/MANIFEST =================================================================== --- trunk/ebase/MANIFEST 2006-05-15 21:43:37 UTC (rev 863) +++ trunk/ebase/MANIFEST 2006-05-15 22:02:43 UTC (rev 864) @@ -104,6 +104,7 @@ lib/Everything/Node/Test/setting.pm lib/Everything/Node/Test/themesetting.pm lib/Everything/Node/Test/user.pm +lib/Everything/Node/Test/workspace.pm lib/Everything/Nodeball.pm lib/Everything/NodeBase.pm lib/Everything/NodeBase/mysql.pm Added: trunk/ebase/lib/Everything/Node/Test/workspace.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/workspace.pm (rev 0) +++ trunk/ebase/lib/Everything/Node/Test/workspace.pm 2006-05-15 22:02:43 UTC (rev 864) @@ -0,0 +1,38 @@ +package Everything::Node::Test::workspace; + +use strict; +use warnings; + +use base 'Everything::Node::Test::setting'; +use Test::More; + +use SUPER; +*Everything::Node::workspace::SUPER = \&UNIVERSAL::SUPER; + +sub test_nuke :Test( 7 ) +{ + my $self = shift; + my $node = $self->{node}; + my $db = $self->{mock_db}; + + $node->set_series( SUPER => 0, 1 ); + $db->set_true( 'sqlDelete' ); + + my $result = $node->nuke( 'user' ); + my ($method, $args) = $node->next_call(); + is( $method, 'SUPER', 'nuke() should call SUPER()' ); + is( $args->[1], 'user', '... with the user' ); + + ok( ! $result, '... returning false if it fails' ); + + $node->{node_id} = 'my_id'; + ok( $node->nuke( 'user' ), '... and true if it succeeds' ); + + ($method, $args) = $db->next_call(); + is( $method, 'sqlDelete', '... so should delete from the database' ); + is( $args->[1], 'revision', '... a revision' ); + is( $args->[2], 'inside_workspace=my_id', '... inside the node workspace' ); +} + +1; +__END__ Property changes on: trunk/ebase/lib/Everything/Node/Test/workspace.pm ___________________________________________________________________ Name: svn:mime-type + text/plain; charset=UTF-8 Name: svn:eol-style + native Modified: trunk/ebase/lib/Everything/Node/workspace.pm =================================================================== --- trunk/ebase/lib/Everything/Node/workspace.pm 2006-05-15 21:43:37 UTC (rev 863) +++ trunk/ebase/lib/Everything/Node/workspace.pm 2006-05-15 22:02:43 UTC (rev 864) @@ -17,11 +17,11 @@ { my ( $this, $USER ) = @_; - return 0 unless ( $this->hasAccess( $USER, "d" ) ); + return unless $this->SUPER( $USER ); - $this->{DB}->sqlDelete( "revision", "inside_workspace=$$this{node_id}" ); - $this->SUPER(); + $this->{DB}->sqlDelete( 'revision', "inside_workspace=$this->{node_id}" ); + return 1; } 1; Modified: trunk/ebase/t/Node/workspace.t =================================================================== --- trunk/ebase/t/Node/workspace.t 2006-05-15 21:43:37 UTC (rev 863) +++ trunk/ebase/t/Node/workspace.t 2006-05-15 22:02:43 UTC (rev 864) @@ -1,57 +1,4 @@ -#!/usr/bin/perl +#! perl -use strict; -use warnings; - -BEGIN -{ - chdir 't' if -d 't'; - use lib 'lib'; -} - -use FakeNode; -use Test::More tests => 9; - -my $module = 'Everything::Node::workspace'; -use_ok( $module ) or exit; - -ok( $module->isa( 'Everything::Node::setting' ), - 'workspace should extend setting' ); - -can_ok( $module, 'dbtables' ); -SKIP: -{ - skip( 'SUPER not appropriate yet', 1 ); - my @tables = $module->dbtables(); - is_deeply( \@tables, [qw( setting node )], - 'dbtables() should return node tables' ); -} - -my $node = FakeNode->new(); -$node->{_subs}{hasAccess} = [ undef, 1 ]; -ok( - !Everything::Node::workspace::nuke( $node, 'user' ), - 'nuke() should return false unless user has delete permission' -); -is( - join( ' ', @{ pop( @{ $node->{_calls} } ) } ), - 'hasAccess user d', - '... and should call hasAccess to prove it' -); - -# and add in data for further calls -$node->{DB} = $node; -$node->{node_id} = 'node_id'; -$node->{_subs}{SUPER} = [1]; -ok( Everything::Node::workspace::nuke( $node, 'user2' ), - '... and true if user does' ); - -# remove the hasAccess() call -shift @{ $node->{_calls} }; -is( - join( ' ', @{ shift( @{ $node->{_calls} } ) } ), - 'sqlDelete revision inside_workspace=node_id', - '... calling sqlDelete to remove revision' -); -is( join( ' ', @{ shift( @{ $node->{_calls} } ) } ), - 'SUPER', '... and calling SUPER to handle deletion' ); +use Everything::Node::Test::workspace; +Everything::Node::Test::workspace->runtests(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-05-16 19:20:05
|
Revision: 867 Author: chromatic Date: 2006-05-16 12:19:58 -0700 (Tue, 16 May 2006) ViewCVS: http://svn.sourceforge.net/everydevel/?rev=867&view=rev Log Message: ----------- r16723@windwheel: chromatic | 2006-05-16 12:19:17 -0700 Mark dependency on updated version of SUPER. Modified Paths: -------------- trunk/ebase/Build.PL Property Changed: ---------------- trunk/ebase/ Property changes on: trunk/ebase ___________________________________________________________________ Name: svk:merge - a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:16721 + a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:16723 Modified: trunk/ebase/Build.PL =================================================================== --- trunk/ebase/Build.PL 2006-05-15 22:14:20 UTC (rev 866) +++ trunk/ebase/Build.PL 2006-05-16 19:19:58 UTC (rev 867) @@ -35,7 +35,7 @@ 'Mail::Address' => 1.53, 'Mail::Sender' => 0, 'Scalar::Util' => 1.01, - 'SUPER' => 1.12, + 'SUPER' => 1.14, }, build_requires => { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-05-16 19:20:31
|
Revision: 868 Author: chromatic Date: 2006-05-16 12:20:23 -0700 (Tue, 16 May 2006) ViewCVS: http://svn.sourceforge.net/everydevel/?rev=868&view=rev Log Message: ----------- r16725@windwheel: chromatic | 2006-05-16 12:20:13 -0700 Ported nodeletgroup tests to the new style. Modified Paths: -------------- trunk/ebase/MANIFEST trunk/ebase/t/Node/nodeletgroup.t Added Paths: ----------- trunk/ebase/lib/Everything/Node/Test/nodeletgroup.pm Property Changed: ---------------- trunk/ebase/ Property changes on: trunk/ebase ___________________________________________________________________ Name: svk:merge - a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:16723 + a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:16725 Modified: trunk/ebase/MANIFEST =================================================================== --- trunk/ebase/MANIFEST 2006-05-16 19:19:58 UTC (rev 867) +++ trunk/ebase/MANIFEST 2006-05-16 19:20:23 UTC (rev 868) @@ -98,6 +98,7 @@ lib/Everything/Node/Test/nodeball.pm lib/Everything/Node/Test/nodegroup.pm lib/Everything/Node/Test/nodelet.pm +lib/Everything/Node/Test/nodeletgroup.pm lib/Everything/Node/Test/nodemethod.pm lib/Everything/Node/Test/nodetype.pm lib/Everything/Node/Test/restricted_superdoc.pm Added: trunk/ebase/lib/Everything/Node/Test/nodeletgroup.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/nodeletgroup.pm (rev 0) +++ trunk/ebase/lib/Everything/Node/Test/nodeletgroup.pm 2006-05-16 19:20:23 UTC (rev 868) @@ -0,0 +1,20 @@ +package Everything::Node::Test::nodeletgroup; + +use strict; +use warnings; + +use base 'Everything::Node::Test::nodegroup'; + +use Test::More; + +sub test_extends :Test( +1 ) +{ + my $self = shift; + my $class = $self->node_class(); + ok( $class->isa( 'Everything::Node::nodegroup' ), + 'nodeletgroup should extend nodegroup' ); + + $self->SUPER(); +} + +1; Property changes on: trunk/ebase/lib/Everything/Node/Test/nodeletgroup.pm ___________________________________________________________________ Name: svn:mime-type + text/plain; charset=UTF-8 Name: svn:eol-style + native Modified: trunk/ebase/t/Node/nodeletgroup.t =================================================================== --- trunk/ebase/t/Node/nodeletgroup.t 2006-05-16 19:19:58 UTC (rev 867) +++ trunk/ebase/t/Node/nodeletgroup.t 2006-05-16 19:20:23 UTC (rev 868) @@ -1,22 +1,4 @@ -#!/usr/bin/perl +#! perl -use strict; -use warnings; - -BEGIN -{ - chdir 't' if -d 't'; - use lib 'lib'; -} - -use Test::More tests => 4; - -my $module = 'Everything::Node::nodeletgroup'; -use_ok( $module ) or exit; - -ok( $module->isa( 'Everything::Node::nodegroup' ), - 'nodeletgroup should extend nodegroup' ); - -can_ok( $module, 'dbtables' ); -my @tables = $module->dbtables(); -is_deeply( \@tables, [qw( node )], 'dbtables() should return node tables' ); +use Everything::Node::Test::nodeletgroup; +Everything::Node::Test::nodeletgroup->runtests(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-05-16 19:24:46
|
Revision: 869 Author: chromatic Date: 2006-05-16 12:24:37 -0700 (Tue, 16 May 2006) ViewCVS: http://svn.sourceforge.net/everydevel/?rev=869&view=rev Log Message: ----------- r16727@windwheel: chromatic | 2006-05-16 12:24:25 -0700 Ported htmlsnippet tests to the new system. Modified Paths: -------------- trunk/ebase/MANIFEST trunk/ebase/t/Node/htmlsnippet.t Added Paths: ----------- trunk/ebase/lib/Everything/Node/Test/htmlsnippet.pm Property Changed: ---------------- trunk/ebase/ Property changes on: trunk/ebase ___________________________________________________________________ Name: svk:merge - a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:16725 + a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:16727 Modified: trunk/ebase/MANIFEST =================================================================== --- trunk/ebase/MANIFEST 2006-05-16 19:20:23 UTC (rev 868) +++ trunk/ebase/MANIFEST 2006-05-16 19:24:37 UTC (rev 869) @@ -91,6 +91,7 @@ lib/Everything/Node/Test/document.pm lib/Everything/Node/Test/htmlcode.pm lib/Everything/Node/Test/htmlpage.pm +lib/Everything/Node/Test/htmlsnippet.pm lib/Everything/Node/Test/image.pm lib/Everything/Node/Test/location.pm lib/Everything/Node/Test/mail.pm Added: trunk/ebase/lib/Everything/Node/Test/htmlsnippet.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/htmlsnippet.pm (rev 0) +++ trunk/ebase/lib/Everything/Node/Test/htmlsnippet.pm 2006-05-16 19:24:37 UTC (rev 869) @@ -0,0 +1,8 @@ +package Everything::Node::Test::htmlsnippet; + +use strict; +use warnings; + +use base 'Everything::Node::Test::htmlcode'; + +1; Property changes on: trunk/ebase/lib/Everything/Node/Test/htmlsnippet.pm ___________________________________________________________________ Name: svn:mime-type + text/plain; charset=UTF-8 Name: svn:eol-style + native Modified: trunk/ebase/t/Node/htmlsnippet.t =================================================================== --- trunk/ebase/t/Node/htmlsnippet.t 2006-05-16 19:20:23 UTC (rev 868) +++ trunk/ebase/t/Node/htmlsnippet.t 2006-05-16 19:24:37 UTC (rev 869) @@ -1,23 +1,4 @@ -#!/usr/bin/perl +#! perl -use strict; -use warnings; - -BEGIN -{ - chdir 't' if -d 't'; - use lib 'lib'; -} - -use Test::More tests => 4; - -my $module = 'Everything::Node::htmlsnippet'; -use_ok( $module ) or exit; - -ok( $module->isa( 'Everything::Node::htmlcode' ), - 'htmlsnippet should extend htmlcode' ); - -can_ok( $module, 'dbtables' ); -my @tables = $module->dbtables(); -is_deeply( \@tables, [qw( htmlcode node )], - 'dbtables() should return node tables' ); +use Everything::Node::Test::htmlsnippet; +Everything::Node::Test::htmlsnippet->runtests(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-05-16 19:29:15
|
Revision: 870 Author: chromatic Date: 2006-05-16 12:29:06 -0700 (Tue, 16 May 2006) ViewCVS: http://svn.sourceforge.net/everydevel/?rev=870&view=rev Log Message: ----------- r16729@windwheel: chromatic | 2006-05-16 12:28:54 -0700 Ported permission tests to the new system. Modified Paths: -------------- trunk/ebase/MANIFEST trunk/ebase/t/Node/permission.t Added Paths: ----------- trunk/ebase/lib/Everything/Node/Test/permission.pm Property Changed: ---------------- trunk/ebase/ Property changes on: trunk/ebase ___________________________________________________________________ Name: svk:merge - a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:16727 + a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:16729 Modified: trunk/ebase/MANIFEST =================================================================== --- trunk/ebase/MANIFEST 2006-05-16 19:24:37 UTC (rev 869) +++ trunk/ebase/MANIFEST 2006-05-16 19:29:06 UTC (rev 870) @@ -102,6 +102,7 @@ lib/Everything/Node/Test/nodeletgroup.pm lib/Everything/Node/Test/nodemethod.pm lib/Everything/Node/Test/nodetype.pm +lib/Everything/Node/Test/permission.pm lib/Everything/Node/Test/restricted_superdoc.pm lib/Everything/Node/Test/superdoc.pm lib/Everything/Node/Test/setting.pm Added: trunk/ebase/lib/Everything/Node/Test/permission.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/permission.pm (rev 0) +++ trunk/ebase/lib/Everything/Node/Test/permission.pm 2006-05-16 19:29:06 UTC (rev 870) @@ -0,0 +1,8 @@ +package Everything::Node::Test::permission; + +use strict; +use warnings; + +use base 'Everything::Node::Test::htmlcode'; + +1; Property changes on: trunk/ebase/lib/Everything/Node/Test/permission.pm ___________________________________________________________________ Name: svn:mime-type + text/plain; charset=UTF-8 Name: svn:eol-style + native Modified: trunk/ebase/t/Node/permission.t =================================================================== --- trunk/ebase/t/Node/permission.t 2006-05-16 19:24:37 UTC (rev 869) +++ trunk/ebase/t/Node/permission.t 2006-05-16 19:29:06 UTC (rev 870) @@ -1,23 +1,4 @@ -#!/usr/bin/perl +#! perl -use strict; -use warnings; - -BEGIN -{ - chdir 't' if -d 't'; - use lib 'lib'; -} - -use Test::More tests => 4; - -my $module = 'Everything::Node::permission'; -use_ok( $module ) or exit; - -ok( $module->isa( 'Everything::Node::htmlcode' ), - 'permission should extend htmlcode' ); - -can_ok( $module, 'dbtables' ); -my @tables = $module->dbtables(); -is_deeply( \@tables, [qw( htmlcode node )], - 'dbtables() should return node tables' ); +use Everything::Node::Test::permission; +Everything::Node::Test::permission->runtests(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-05-16 20:19:07
|
Revision: 871 Author: chromatic Date: 2006-05-16 13:18:57 -0700 (Tue, 16 May 2006) ViewCVS: http://svn.sourceforge.net/everydevel/?rev=871&view=rev Log Message: ----------- r16731@windwheel: chromatic | 2006-05-16 13:13:44 -0700 Fix uninitialized value warning in applyXMLFix(). Modified Paths: -------------- trunk/ebase/lib/Everything/Node/nodeball.pm Property Changed: ---------------- trunk/ebase/ Property changes on: trunk/ebase ___________________________________________________________________ Name: svk:merge - a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:16729 + a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:16731 Modified: trunk/ebase/lib/Everything/Node/nodeball.pm =================================================================== --- trunk/ebase/lib/Everything/Node/nodeball.pm 2006-05-16 19:29:06 UTC (rev 870) +++ trunk/ebase/lib/Everything/Node/nodeball.pm 2006-05-16 20:18:57 UTC (rev 871) @@ -117,7 +117,7 @@ my ( $this, $FIX, $printError ) = @_; return Everything::Node::setting::applyXMLFix( $this, $FIX, $printError ) - if $FIX->{fixBy} eq 'setting'; + if exists $FIX->{fixBy} and $FIX->{fixBy} eq 'setting'; return $this->SUPER( $FIX, $printError ); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-05-16 20:19:16
|
Revision: 872 Author: chromatic Date: 2006-05-16 13:19:07 -0700 (Tue, 16 May 2006) ViewCVS: http://svn.sourceforge.net/everydevel/?rev=872&view=rev Log Message: ----------- r16732@windwheel: chromatic | 2006-05-16 13:14:45 -0700 Ported theme tests to the new system. Modified Paths: -------------- trunk/ebase/MANIFEST trunk/ebase/lib/Everything/Node/Test/nodeball.pm trunk/ebase/t/Node/theme.t Added Paths: ----------- trunk/ebase/lib/Everything/Node/Test/theme.pm Property Changed: ---------------- trunk/ebase/ Property changes on: trunk/ebase ___________________________________________________________________ Name: svk:merge - a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:16731 + a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:16732 Modified: trunk/ebase/MANIFEST =================================================================== --- trunk/ebase/MANIFEST 2006-05-16 20:18:57 UTC (rev 871) +++ trunk/ebase/MANIFEST 2006-05-16 20:19:07 UTC (rev 872) @@ -106,6 +106,7 @@ lib/Everything/Node/Test/restricted_superdoc.pm lib/Everything/Node/Test/superdoc.pm lib/Everything/Node/Test/setting.pm +lib/Everything/Node/Test/theme.pm lib/Everything/Node/Test/themesetting.pm lib/Everything/Node/Test/user.pm lib/Everything/Node/Test/usergroup.pm Modified: trunk/ebase/lib/Everything/Node/Test/nodeball.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/nodeball.pm 2006-05-16 20:18:57 UTC (rev 871) +++ trunk/ebase/lib/Everything/Node/Test/nodeball.pm 2006-05-16 20:19:07 UTC (rev 872) @@ -160,7 +160,6 @@ is( "$node $node", "@saveargs", '... passing node and tag' ); } - sub test_apply_xml_fix :Test( 4 ) { my $self = shift; Added: trunk/ebase/lib/Everything/Node/Test/theme.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/theme.pm (rev 0) +++ trunk/ebase/lib/Everything/Node/Test/theme.pm 2006-05-16 20:19:07 UTC (rev 872) @@ -0,0 +1,44 @@ +package Everything::Node::Test::theme; + +use strict; +use warnings; + +use base 'Everything::Node::Test::nodeball'; +use Test::More; + +sub test_extends :Test( +1 ) +{ + my $self = shift; + my $class = $self->node_class(); + + ok( $class->isa( 'Everything::Node::nodeball' ), + 'theme should extend nodeball' ); + + $self->SUPER(); +} + +sub test_insert_access :Test( 1 ) +{ + local $TODO = 'Make nodegroup contain the setting node'; + ok( 0, 'nodegroup cannot call setting methods as functions' ); +} + +sub test_insert_restrictions :Test( 1 ) +{ + local $TODO = 'Make nodegroup contain the setting node'; + ok( 0, 'nodegroup cannot call setting methods as functions' ); +} + +sub test_insert_restrict_dupes :Test( 1 ) +{ + local $TODO = 'Make nodegroup contain the setting node'; + ok( 0, 'nodegroup cannot call setting methods as functions' ); +} + +sub test_apply_xml_fix_no_fixby_node :Test( 1 ) +{ + local $TODO = 'Make nodegroup contain the setting node'; + ok( 0, 'nodegroup cannot call setting methods as functions' ); +} + +1; Property changes on: trunk/ebase/lib/Everything/Node/Test/theme.pm ___________________________________________________________________ Name: svn:mime-type + text/plain; charset=UTF-8 Name: svn:eol-style + native Modified: trunk/ebase/t/Node/theme.t =================================================================== --- trunk/ebase/t/Node/theme.t 2006-05-16 20:18:57 UTC (rev 871) +++ trunk/ebase/t/Node/theme.t 2006-05-16 20:19:07 UTC (rev 872) @@ -1,23 +1,4 @@ -#!/usr/bin/perl +#! perl -use strict; -use warnings; - -BEGIN -{ - chdir 't' if -d 't'; - use lib 'lib'; -} - -use Test::More tests => 4; - -my $module = 'Everything::Node::theme'; -use_ok( $module ) or exit; - -ok( $module->isa( 'Everything::Node::nodeball' ), - 'theme should extend nodeball' ); - -can_ok( $module, 'dbtables' ); -my @tables = $module->dbtables(); -is_deeply( \@tables, [qw( setting node )], - 'dbtables() should return node tables' ); +use Everything::Node::Test::theme; +Everything::Node::Test::theme->runtests(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-05-16 20:21:00
|
Revision: 873 Author: chromatic Date: 2006-05-16 13:20:48 -0700 (Tue, 16 May 2006) ViewCVS: http://svn.sourceforge.net/everydevel/?rev=873&view=rev Log Message: ----------- r16735@windwheel: chromatic | 2006-05-16 13:20:39 -0700 Ported opcode tests to the new format. Modified Paths: -------------- trunk/ebase/MANIFEST trunk/ebase/t/Node/opcode.t Added Paths: ----------- trunk/ebase/lib/Everything/Node/Test/opcode.pm Property Changed: ---------------- trunk/ebase/ Property changes on: trunk/ebase ___________________________________________________________________ Name: svk:merge - a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:16732 + a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:16735 Modified: trunk/ebase/MANIFEST =================================================================== --- trunk/ebase/MANIFEST 2006-05-16 20:19:07 UTC (rev 872) +++ trunk/ebase/MANIFEST 2006-05-16 20:20:48 UTC (rev 873) @@ -102,6 +102,7 @@ lib/Everything/Node/Test/nodeletgroup.pm lib/Everything/Node/Test/nodemethod.pm lib/Everything/Node/Test/nodetype.pm +lib/Everything/Node/Test/opcode.pm lib/Everything/Node/Test/permission.pm lib/Everything/Node/Test/restricted_superdoc.pm lib/Everything/Node/Test/superdoc.pm Added: trunk/ebase/lib/Everything/Node/Test/opcode.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/opcode.pm (rev 0) +++ trunk/ebase/lib/Everything/Node/Test/opcode.pm 2006-05-16 20:20:48 UTC (rev 873) @@ -0,0 +1,18 @@ +package Everything::Node::Test::opcode; + +use strict; +use warnings; + +use base 'Everything::Node::Test::htmlcode'; +use Test::More; + +sub test_extends :Test( +1 ) +{ + my $self = shift; + my $class = $self->node_class(); + ok( $class->isa( 'Everything::Node::htmlcode' ), + 'opcode should extend htmlcode' ); + $self->SUPER(); +} + +1; Property changes on: trunk/ebase/lib/Everything/Node/Test/opcode.pm ___________________________________________________________________ Name: svn:mime-type + text/plain; charset=UTF-8 Name: svn:eol-style + native Modified: trunk/ebase/t/Node/opcode.t =================================================================== --- trunk/ebase/t/Node/opcode.t 2006-05-16 20:19:07 UTC (rev 872) +++ trunk/ebase/t/Node/opcode.t 2006-05-16 20:20:48 UTC (rev 873) @@ -1,23 +1,4 @@ -#!/usr/bin/perl +#! perl -use strict; -use warnings; - -BEGIN -{ - chdir 't' if -d 't'; - use lib 'lib'; -} - -use Test::More tests => 4; - -my $module = 'Everything::Node::opcode'; -use_ok( $module ) or exit; - -ok( $module->isa( 'Everything::Node::htmlcode' ), - 'theme should extend htmlcode' ); - -can_ok( $module, 'dbtables' ); -my @tables = $module->dbtables(); -is_deeply( \@tables, [qw( htmlcode node )], - 'dbtables() should return node tables' ); +use Everything::Node::Test::opcode; +Everything::Node::Test::opcode->runtests(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-05-16 20:25:41
|
Revision: 874 Author: chromatic Date: 2006-05-16 13:25:30 -0700 (Tue, 16 May 2006) ViewCVS: http://svn.sourceforge.net/everydevel/?rev=874&view=rev Log Message: ----------- r16737@windwheel: chromatic | 2006-05-16 13:25:20 -0700 Ported container node tests to the new style. Modified Paths: -------------- trunk/ebase/MANIFEST trunk/ebase/t/Node/container.t Added Paths: ----------- trunk/ebase/lib/Everything/Node/Test/container.pm Property Changed: ---------------- trunk/ebase/ Property changes on: trunk/ebase ___________________________________________________________________ Name: svk:merge - a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:16735 + a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:16737 Modified: trunk/ebase/MANIFEST =================================================================== --- trunk/ebase/MANIFEST 2006-05-16 20:20:48 UTC (rev 873) +++ trunk/ebase/MANIFEST 2006-05-16 20:25:30 UTC (rev 874) @@ -87,6 +87,7 @@ lib/Everything/Node/user.pm lib/Everything/Node/usergroup.pm lib/Everything/Node/workspace.pm +lib/Everything/Node/Test/container.pm lib/Everything/Node/Test/dbtable.pm lib/Everything/Node/Test/document.pm lib/Everything/Node/Test/htmlcode.pm Added: trunk/ebase/lib/Everything/Node/Test/container.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/container.pm (rev 0) +++ trunk/ebase/lib/Everything/Node/Test/container.pm 2006-05-16 20:25:30 UTC (rev 874) @@ -0,0 +1,21 @@ +package Everything::Node::Test::container; + +use strict; +use warnings; + +use base 'Everything::Node::Test::node'; +use Test::More; + +sub test_dbtables :Test( 2 ) +{ + my $self = shift; + my $class = $self->node_class(); + + can_ok( $class, 'dbtables' ); + + my @tables = $class->dbtables(); + is_deeply( \@tables, [qw( container node )], + 'dbtables() should return node tables' ); +} + +1; Property changes on: trunk/ebase/lib/Everything/Node/Test/container.pm ___________________________________________________________________ Name: svn:mime-type + text/plain; charset=UTF-8 Name: svn:eol-style + native Modified: trunk/ebase/t/Node/container.t =================================================================== --- trunk/ebase/t/Node/container.t 2006-05-16 20:20:48 UTC (rev 873) +++ trunk/ebase/t/Node/container.t 2006-05-16 20:25:30 UTC (rev 874) @@ -1,22 +1,4 @@ -#!/usr/bin/perl +#! perl -use strict; -use warnings; - -BEGIN -{ - chdir 't' if -d 't'; - use lib 'lib'; -} - -use Test::More tests => 4; - -my $module = 'Everything::Node::container'; -use_ok( $module ) or exit; - -ok( $module->isa( 'Everything::Node::node' ), 'container should extend node' ); - -can_ok( $module, 'dbtables' ); -my @tables = $module->dbtables(); -is_deeply( \@tables, [qw( container node )], - 'dbtables() should return node tables' ); +use Everything::Node::Test::container; +Everything::Node::Test::container->runtests(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-05-16 20:30:50
|
Revision: 875 Author: chromatic Date: 2006-05-16 13:30:39 -0700 (Tue, 16 May 2006) ViewCVS: http://svn.sourceforge.net/everydevel/?rev=875&view=rev Log Message: ----------- r16739@windwheel: chromatic | 2006-05-16 13:30:27 -0700 Ported tests for javascript node to the new style. Modified Paths: -------------- trunk/ebase/MANIFEST trunk/ebase/t/Node/javascript.t Added Paths: ----------- trunk/ebase/lib/Everything/Node/Test/javascript.pm Property Changed: ---------------- trunk/ebase/ Property changes on: trunk/ebase ___________________________________________________________________ Name: svk:merge - a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:16737 + a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:16739 Modified: trunk/ebase/MANIFEST =================================================================== --- trunk/ebase/MANIFEST 2006-05-16 20:25:30 UTC (rev 874) +++ trunk/ebase/MANIFEST 2006-05-16 20:30:39 UTC (rev 875) @@ -94,6 +94,7 @@ lib/Everything/Node/Test/htmlpage.pm lib/Everything/Node/Test/htmlsnippet.pm lib/Everything/Node/Test/image.pm +lib/Everything/Node/Test/javascript.pm lib/Everything/Node/Test/location.pm lib/Everything/Node/Test/mail.pm lib/Everything/Node/Test/node.pm Added: trunk/ebase/lib/Everything/Node/Test/javascript.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/javascript.pm (rev 0) +++ trunk/ebase/lib/Everything/Node/Test/javascript.pm 2006-05-16 20:30:39 UTC (rev 875) @@ -0,0 +1,22 @@ +package Everything::Node::Test::javascript; + +use strict; +use warnings; + +use base 'Everything::Node::Test::node'; + +use Test::More; + +sub test_dbtables :Test( 2 ) +{ + my $self = shift; + my $class = $self->node_class(); + + can_ok( $class, 'dbtables' ); + + my @tables = $class->dbtables(); + is_deeply( \@tables, [qw( javascript node )], + 'dbtables() should return node tables' ); +} + +1; Property changes on: trunk/ebase/lib/Everything/Node/Test/javascript.pm ___________________________________________________________________ Name: svn:mime-type + text/plain; charset=UTF-8 Name: svn:eol-style + native Modified: trunk/ebase/t/Node/javascript.t =================================================================== --- trunk/ebase/t/Node/javascript.t 2006-05-16 20:25:30 UTC (rev 874) +++ trunk/ebase/t/Node/javascript.t 2006-05-16 20:30:39 UTC (rev 875) @@ -1,22 +1,4 @@ -#!/usr/bin/perl +#! perl -use strict; -use warnings; - -BEGIN -{ - chdir 't' if -d 't'; - use lib 'lib'; -} - -use Test::More tests => 4; - -my $module = 'Everything::Node::javascript'; -use_ok( $module ) or exit; - -ok( $module->isa( 'Everything::Node::node' ), 'javascript should extend node' ); - -can_ok( $module, 'dbtables' ); -my @tables = $module->dbtables(); -is_deeply( \@tables, [qw( javascript node )], - 'dbtables() should return node tables' ); +use Everything::Node::Test::javascript; +Everything::Node::Test::javascript->runtests(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-05-16 20:45:12
|
Revision: 876 Author: chromatic Date: 2006-05-16 13:45:03 -0700 (Tue, 16 May 2006) ViewCVS: http://svn.sourceforge.net/everydevel/?rev=876&view=rev Log Message: ----------- r16741@windwheel: chromatic | 2006-05-16 13:44:20 -0700 Ported symlink tests to new style. Modified Paths: -------------- trunk/ebase/MANIFEST trunk/ebase/t/Node/symlink.t Added Paths: ----------- trunk/ebase/lib/Everything/Node/Test/symlink.pm Property Changed: ---------------- trunk/ebase/ Property changes on: trunk/ebase ___________________________________________________________________ Name: svk:merge - a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:16739 + a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:16741 Modified: trunk/ebase/MANIFEST =================================================================== --- trunk/ebase/MANIFEST 2006-05-16 20:30:39 UTC (rev 875) +++ trunk/ebase/MANIFEST 2006-05-16 20:45:03 UTC (rev 876) @@ -109,6 +109,7 @@ lib/Everything/Node/Test/restricted_superdoc.pm lib/Everything/Node/Test/superdoc.pm lib/Everything/Node/Test/setting.pm +lib/Everything/Node/Test/symlink.pm lib/Everything/Node/Test/theme.pm lib/Everything/Node/Test/themesetting.pm lib/Everything/Node/Test/user.pm Added: trunk/ebase/lib/Everything/Node/Test/symlink.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/symlink.pm (rev 0) +++ trunk/ebase/lib/Everything/Node/Test/symlink.pm 2006-05-16 20:45:03 UTC (rev 876) @@ -0,0 +1,21 @@ +package Everything::Node::Test::symlink; + +use strict; +use warnings; + +use base 'Everything::Node::Test::node'; + +use Test::More; + +sub test_dbtables :Test( 2 ) +{ + my $self = shift; + my $class = $self->node_class(); + can_ok( $class, 'dbtables' ); + + my @tables = $class->dbtables(); + is_deeply( \@tables, [qw( symlink node )], + 'dbtables() should return node tables' ); +} + +1; Property changes on: trunk/ebase/lib/Everything/Node/Test/symlink.pm ___________________________________________________________________ Name: svn:mime-type + text/plain; charset=UTF-8 Name: svn:eol-style + native Modified: trunk/ebase/t/Node/symlink.t =================================================================== --- trunk/ebase/t/Node/symlink.t 2006-05-16 20:30:39 UTC (rev 875) +++ trunk/ebase/t/Node/symlink.t 2006-05-16 20:45:03 UTC (rev 876) @@ -1,22 +1,4 @@ -#!/usr/bin/perl +#! perl -use strict; -use warnings; - -BEGIN -{ - chdir 't' if -d 't'; - use lib 'lib'; -} - -use Test::More tests => 4; - -my $module = 'Everything::Node::symlink'; -use_ok( $module ) or exit; - -ok( $module->isa( 'Everything::Node::node' ), 'theme should extend node' ); - -can_ok( $module, 'dbtables' ); -my @tables = $module->dbtables(); -is_deeply( \@tables, [qw( symlink node )], - 'dbtables() should return node tables' ); +use Everything::Node::Test::symlink; +Everything::Node::Test::symlink->runtests(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-05-16 20:45:28
|
Revision: 877 Author: chromatic Date: 2006-05-16 13:45:15 -0700 (Tue, 16 May 2006) ViewCVS: http://svn.sourceforge.net/everydevel/?rev=877&view=rev Log Message: ----------- r16742@windwheel: chromatic | 2006-05-16 13:44:48 -0700 Check inheritance in several test classes that didn't before. Modified Paths: -------------- trunk/ebase/lib/Everything/Node/Test/htmlsnippet.pm trunk/ebase/lib/Everything/Node/Test/mail.pm trunk/ebase/lib/Everything/Node/Test/permission.pm trunk/ebase/lib/Everything/Node/Test/restricted_superdoc.pm trunk/ebase/lib/Everything/Node/Test/superdoc.pm trunk/ebase/lib/Everything/Node/Test/usergroup.pm trunk/ebase/lib/Everything/Node/Test/workspace.pm Property Changed: ---------------- trunk/ebase/ Property changes on: trunk/ebase ___________________________________________________________________ Name: svk:merge - a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:16741 + a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:16742 Modified: trunk/ebase/lib/Everything/Node/Test/htmlsnippet.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/htmlsnippet.pm 2006-05-16 20:45:03 UTC (rev 876) +++ trunk/ebase/lib/Everything/Node/Test/htmlsnippet.pm 2006-05-16 20:45:15 UTC (rev 877) @@ -4,5 +4,15 @@ use warnings; use base 'Everything::Node::Test::htmlcode'; +use Test::More; +sub test_extends :Test( +1 ) +{ + my $self = shift; + my $class = $self->node_class(); + ok( $class->isa( 'Everything::Node::htmlcode' ), + 'htmlsnippet should extend htmlcode' ); + $self->SUPER(); +} + 1; Modified: trunk/ebase/lib/Everything/Node/Test/mail.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/mail.pm 2006-05-16 20:45:03 UTC (rev 876) +++ trunk/ebase/lib/Everything/Node/Test/mail.pm 2006-05-16 20:45:15 UTC (rev 877) @@ -14,10 +14,23 @@ { my $self = shift; my $class = $self->node_class(); + can_ok( $class, 'dbtables' ); + my @tables = $class->dbtables(); is_deeply( \@tables, [qw( mail document node )], 'dbtables() should return node tables' ); } +sub test_extends :Test( +1 ) +{ + my $self = shift; + my $class = $self->node_class(); + + ok( $class->isa( 'Everything::Node::document' ), + 'mail should extend document' ); + + $self->SUPER(); +} + 1; Modified: trunk/ebase/lib/Everything/Node/Test/permission.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/permission.pm 2006-05-16 20:45:03 UTC (rev 876) +++ trunk/ebase/lib/Everything/Node/Test/permission.pm 2006-05-16 20:45:15 UTC (rev 877) @@ -5,4 +5,17 @@ use base 'Everything::Node::Test::htmlcode'; +use Test::More; + +sub test_extends :Test( +1 ) +{ + my $self = shift; + my $class = $self->node_class(); + + ok( $class->isa( 'Everything::Node::htmlcode' ), + 'permission should extend htmlcode' ); + + $self->SUPER(); +} + 1; Modified: trunk/ebase/lib/Everything/Node/Test/restricted_superdoc.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/restricted_superdoc.pm 2006-05-16 20:45:03 UTC (rev 876) +++ trunk/ebase/lib/Everything/Node/Test/restricted_superdoc.pm 2006-05-16 20:45:15 UTC (rev 877) @@ -5,4 +5,17 @@ use base 'Everything::Node::Test::superdoc'; +use Test::More; + +sub test_extends :Test( +1 ) +{ + my $self = shift; + my $class = $self->node_class(); + + ok( $class->isa( 'Everything::Node::superdoc' ), + 'restricted_superdoc should extend superdoc' ); + + $self->SUPER(); +} + 1; Modified: trunk/ebase/lib/Everything/Node/Test/superdoc.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/superdoc.pm 2006-05-16 20:45:03 UTC (rev 876) +++ trunk/ebase/lib/Everything/Node/Test/superdoc.pm 2006-05-16 20:45:15 UTC (rev 877) @@ -20,4 +20,15 @@ 'dbtables() should return node tables' ); } +sub test_extends :Test( +1 ) +{ + my $self = shift; + my $class = $self->node_class(); + + ok( $class->isa( 'Everything::Node::document' ), + 'superdoc should extend document' ); + + $self->SUPER(); +} + 1; Modified: trunk/ebase/lib/Everything/Node/Test/usergroup.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/usergroup.pm 2006-05-16 20:45:03 UTC (rev 876) +++ trunk/ebase/lib/Everything/Node/Test/usergroup.pm 2006-05-16 20:45:15 UTC (rev 877) @@ -6,6 +6,17 @@ use base 'Everything::Node::Test::nodegroup'; use Test::More; +sub test_extends :Test( +1 ) +{ + my $self = shift; + my $class = $self->node_class(); + + ok( $class->isa( 'Everything::Node::nodegroup' ), + 'usergroup should extend nodegroup' ); + + $self->SUPER(); +} + sub test_conflicts_with :Test( 1 ) { my $self = shift; Modified: trunk/ebase/lib/Everything/Node/Test/workspace.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/workspace.pm 2006-05-16 20:45:03 UTC (rev 876) +++ trunk/ebase/lib/Everything/Node/Test/workspace.pm 2006-05-16 20:45:15 UTC (rev 877) @@ -9,6 +9,17 @@ use SUPER; *Everything::Node::workspace::SUPER = \&UNIVERSAL::SUPER; +sub test_extends :Test( +1 ) +{ + my $self = shift; + my $class = $self->node_class(); + + ok( $class->isa( 'Everything::Node::setting' ), + 'workspace should extend setting' ); + + $self->SUPER(); +} + sub test_nuke :Test( 7 ) { my $self = shift; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-05-18 22:12:18
|
Revision: 878 Author: chromatic Date: 2006-05-18 15:12:07 -0700 (Thu, 18 May 2006) ViewCVS: http://svn.sourceforge.net/everydevel/?rev=878&view=rev Log Message: ----------- r17177@windwheel: chromatic | 2006-05-18 15:11:55 -0700 Minor documentation fixes. Removed deprecated methods. Fixed isa() calls. Modified Paths: -------------- trunk/ebase/lib/Everything/NodeBase.pm trunk/ebase/t/NodeBase.t Property Changed: ---------------- trunk/ebase/ Property changes on: trunk/ebase ___________________________________________________________________ Name: svk:merge - a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:16742 + a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:17177 Modified: trunk/ebase/lib/Everything/NodeBase.pm =================================================================== --- trunk/ebase/lib/Everything/NodeBase.pm 2006-05-16 20:45:15 UTC (rev 877) +++ trunk/ebase/lib/Everything/NodeBase.pm 2006-05-18 22:12:07 UTC (rev 878) @@ -1,26 +1,21 @@ - =head1 Everything::NodeBase Wrapper for the Everything database and cache. -Copyright 1999 - 2003 Everything Development Inc. +Copyright 1999 - 2006 Everything Development Inc. =cut package Everything::NodeBase; -# Format: tabs = 4 spaces - use strict; use DBI; use File::Spec; use Everything (); use Everything::NodeCache; use Everything::Node; +use Scalar::Util 'reftype'; -=cut - - =head2 C<new> Constructor for this module @@ -82,9 +77,6 @@ return $this; } -=cut - - =head2 C<joinWorkspace> create the $DB-E<gt>{workspace} object if a workspace is specified. If the @@ -118,9 +110,6 @@ 1; } -=cut - - =head2 C<getNodeWorkspace> Helper funciton for getNode's workspace functionality. Given a $WHERE hash ( @@ -185,9 +174,6 @@ \@results; } -=cut - - =head2 C<rebuildNodetypeModules> Call this to account for any new nodetypes that may have been installed. @@ -204,9 +190,6 @@ return; } -=cut - - =head2 C<buildNodetypeModules> Perl 5.6 throws errors if we test "can" on a non-existing module. This @@ -257,9 +240,6 @@ return exists $INC{$modpath}; } -=cut - - =head2 C<resetNodeCache> The node cache holds onto nodes after they have been loaded from the database. @@ -277,9 +257,6 @@ $this->{cache}->resetCache(); } -=cut - - =head2 C<getDatabaseHandle> This returns the DBI connection to the database. This can be used to do raw @@ -297,9 +274,6 @@ return $this->{dbh}; } -=cut - - =head2 C<getCache> This returns the NodeCache object that we are using to cache nodes. In @@ -357,9 +331,6 @@ or Everything::logErrors( '', "Delete failed: '$sql' [@$bound]" ); } -=cut - - =head2 C<sqlSelect> Select specific fields from a single record. If you need multiple records, use @@ -404,9 +375,6 @@ return \@result; } -=cut - - =head2 C<sqlSelectJoined> A general wrapper function for a standard SQL select command involving left @@ -462,9 +430,6 @@ return $cursor; } -=cut - - =head2 C<sqlSelectMany> A general wrapper function for a standard SQL select command. This returns the @@ -516,9 +481,6 @@ return; } -=cut - - =head2 C<sqlSelectHashref> Grab one row from a table and return it as a hash. This just grabs the first @@ -560,9 +522,6 @@ return $hash; } -=cut - - =head2 C<sqlUpdate> Wrapper for sql update command. @@ -606,9 +565,6 @@ return $this->sqlExecute( $sql, $bound ); } -=cut - - =head2 C<sqlInsert> Wrapper for the sql insert command. @@ -648,7 +604,6 @@ =cut - C<_quoteData> Private method @@ -688,9 +643,6 @@ return \@names, \@values, \@bound; } -=cut - - =head2 C<sqlExecute> Wrapper for the SQL execute command. @@ -739,9 +691,6 @@ return $this->getNode( $node_id, $selectop ); } -=cut - - =head2 C<newNode> A more programatically "graceful" way than getNode() to get a node that does @@ -775,9 +724,6 @@ return $this->getNode( $title, $type, 'create force' ); } -=cut - - =head2 C<getNode> This is the one and only function needed to get a single node. If any function @@ -830,7 +776,7 @@ return unless defined $node and $node ne ''; # it may already be a node - return $node if UNIVERSAL::isa( $node, 'Everything::Node' ); + return $node if eval { $node->isa( 'Everything::Node' ) }; my $NODE; my $cache = ""; @@ -928,7 +874,6 @@ return $NODE; } -############################################################################# sub getNodeByName { my ( $this, $node, $TYPE ) = @_; @@ -961,9 +906,6 @@ return $NODE; } -=cut - - =head2 C<getNodeZero> The node with zero as its ID is a "dummy" node that represents the root @@ -994,7 +936,6 @@ return $$this{nodezero}; } -############################################################################# sub getNodeByIdNew { my ( $this, $node_id, $selectop ) = @_; @@ -1032,9 +973,6 @@ return $NODE; } -=cut - - =head2 C<constructNode> Given a hash that contains a row of data from the 'node' table, get its type @@ -1096,9 +1034,6 @@ return 1; } -=cut - - =head2 C<getNodeWhere> Get a list of NODE hashes. This constructs a complete node. @@ -1150,7 +1085,7 @@ return unless defined $selectNodeWhere - and UNIVERSAL::isa( $selectNodeWhere, 'ARRAY' ); + and reftype( $selectNodeWhere || '' ) eq 'ARRAY'; my @nodelist; @@ -1163,12 +1098,9 @@ return \@nodelist; } -=cut - - =head2 C<selectNodeWhere> -Retrieves node id's that match the given query. +Retrieves node ids that match the given query. =over 4 @@ -1244,9 +1176,6 @@ return \@nodelist; } -=cut - - =head2 C<getNodeCursor> This returns the sql cursor for node matches. Users of this object can call @@ -1361,9 +1290,6 @@ return $cursor; } -=cut - - =head2 C<countNodeMatches> Doing a full query has some extra overhead. If you just want @@ -1402,9 +1328,6 @@ return $matches; } -=cut - - =head2 C<getType> This is just a quickie wrapper to get a nodetype by name or id. Saves extra @@ -1421,16 +1344,13 @@ return unless defined $idOrName and $idOrName ne ''; # The thing they passed in is good to go. - return $idOrName if UNIVERSAL::isa( $idOrName, 'Everything::Node' ); + return $idOrName if eval { $idOrName->isa( 'Everything::Node' ) }; return $this->getNode( $idOrName, 1 ) if $idOrName =~ /\D/; return $this->getNode($idOrName) if $idOrName > 0; return; } -=cut - - =head2 C<getAllTypes> This returns an array that contains all of the nodetypes in the system. Useful @@ -1459,9 +1379,6 @@ return @allTypes; } -=cut - - =head2 C<getFields> Get the field names of a table. @@ -1485,9 +1402,6 @@ return $this->getFieldsHash( $table, 0 ); } -=cut - - =head2 C<dropNodeTable> Drop (delete) a table from the database. Note!!! This is permanent! You will @@ -1532,9 +1446,6 @@ return $this->{dbh}->do( "drop table " . $this->genTableName($table) ); } -=cut - - =head2 C<quote> A quick access to DBI's quote function for quoting strings so that they do not @@ -1559,9 +1470,6 @@ return $this->{dbh}->quote($str); } -=cut - - =head2 C<genWhereString> This code was stripped from selectNodeWhere. This takes a WHERE hash and a @@ -1606,7 +1514,7 @@ # if your where hash includes a hash to a node, you probably really # want to compare the ID of the node, not the hash reference. - if ( UNIVERSAL::isa( $WHERE->{$key}, 'Everything::Node' ) ) + if ( eval { $WHERE->{$key}->isa( 'Everything::Node' ) } ) { $$WHERE{$key} = $this->getId( $WHERE->{$key} ); } @@ -1667,15 +1575,12 @@ return $wherestr; } -############################################################################# -# "Private" functions to this module -############################################################################# +=head1 Private methods -=cut +These methods are private. Don't call them. They won't call you. +=head2 C<getNodetypeTables> -C<getNodetypeTables> - Returns an array of all the tables that a given nodetype joins on. This will create the array, if it has not already created it. @@ -1725,13 +1630,10 @@ return \@tablelist; } -=cut +=head2 C<getRef> +This makes sure that we have an array of node hashes, not node ids. -C<getRef> - -This makes sure that we have an array of node hashes, not node id's. - Returns the node hash of the first element passed in. =cut @@ -1743,18 +1645,15 @@ for (@_) { - next if UNIVERSAL::isa( $_, 'Everything::Node' ); + next if eval { $_->isa( 'Everything::Node' ) }; $_ = $this->getNode($_) if defined $_; } return $_[0]; } -=cut +=head2 C<getId> - -C<getId> - Given a node object or a node id, return the id. Just a quick function to call to make sure that you have an id. @@ -1775,14 +1674,11 @@ my ( $this, $node ) = @_; return unless $node; - return $node->{node_id} if UNIVERSAL::isa( $node, 'Everything::Node' ); + return $node->{node_id} if eval { $node->isa( 'Everything::Node' ) }; return $node if $node =~ /^-?\d+$/; return; } -=cut - - =head2 C<hasPermission> This does dynamic permission calculations using the specified @@ -1837,40 +1733,4 @@ # if the database returns odd column names, override this to fix them sub fix_node_keys { } -############################################################################# -# DEPRECATED - use hasAccess() -sub canCreateNode -{ - my ( $this, $USER, $TYPE ) = @_; - return $this->hasAccess( $TYPE, $USER, "c" ); -} - -############################################################################# -# DEPRECATED - use hasAccess() -sub canDeleteNode -{ - my ( $this, $USER, $NODE ) = @_; - return $this->hasAccess( $NODE, $USER, "d" ); -} - -############################################################################# -# DEPRECATED - use hasAccess() -sub canUpdateNode -{ - my ( $this, $USER, $NODE ) = @_; - return $this->hasAccess( $NODE, $USER, "w" ); -} - -############################################################################# -# DEPRECATED - use hasAccess() -sub canReadNode -{ - my ( $this, $USER, $NODE ) = @_; - return $this->hasAccess( $NODE, $USER, "r" ); -} - -############################################################################# -# End of Package -############################################################################# - 1; Modified: trunk/ebase/t/NodeBase.t =================================================================== --- trunk/ebase/t/NodeBase.t 2006-05-16 20:45:15 UTC (rev 877) +++ trunk/ebase/t/NodeBase.t 2006-05-18 22:12:07 UTC (rev 878) @@ -1,13 +1,8 @@ -#!/usr/bin/perl -w +#! perl use strict; +use warnings; -BEGIN -{ - chdir 't' if -d 't'; - unshift @INC, '../blib/lib', 'lib/', '..'; -} - use strict; use vars qw( $AUTOLOAD ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-05-18 22:32:15
|
Revision: 879 Author: chromatic Date: 2006-05-18 15:31:43 -0700 (Thu, 18 May 2006) ViewCVS: http://svn.sourceforge.net/everydevel/?rev=879&view=rev Log Message: ----------- r17179@windwheel: chromatic | 2006-05-18 15:31:29 -0700 Removed SUPER() and AUTOLOAD() from Everything::Node. Modified Paths: -------------- trunk/ebase/lib/Everything/Node/Test/container.pm trunk/ebase/lib/Everything/Node/Test/dbtable.pm trunk/ebase/lib/Everything/Node/Test/document.pm trunk/ebase/lib/Everything/Node/Test/htmlcode.pm trunk/ebase/lib/Everything/Node/Test/htmlpage.pm trunk/ebase/lib/Everything/Node/Test/htmlsnippet.pm trunk/ebase/lib/Everything/Node/Test/image.pm trunk/ebase/lib/Everything/Node/Test/location.pm trunk/ebase/lib/Everything/Node/Test/mail.pm trunk/ebase/lib/Everything/Node/Test/node.pm trunk/ebase/lib/Everything/Node/Test/nodeball.pm trunk/ebase/lib/Everything/Node/Test/nodegroup.pm trunk/ebase/lib/Everything/Node/Test/nodelet.pm trunk/ebase/lib/Everything/Node/Test/nodemethod.pm trunk/ebase/lib/Everything/Node/Test/nodetype.pm trunk/ebase/lib/Everything/Node/Test/opcode.pm trunk/ebase/lib/Everything/Node/Test/setting.pm trunk/ebase/lib/Everything/Node/Test/superdoc.pm trunk/ebase/lib/Everything/Node/Test/theme.pm trunk/ebase/lib/Everything/Node/Test/themesetting.pm trunk/ebase/lib/Everything/Node/Test/user.pm trunk/ebase/lib/Everything/Node/Test/usergroup.pm trunk/ebase/lib/Everything/Node/Test/workspace.pm trunk/ebase/lib/Everything/Node.pm trunk/ebase/t/Node.t Property Changed: ---------------- trunk/ebase/ Property changes on: trunk/ebase ___________________________________________________________________ Name: svk:merge - a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:17177 + a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:17179 Modified: trunk/ebase/lib/Everything/Node/Test/container.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/container.pm 2006-05-18 22:12:07 UTC (rev 878) +++ trunk/ebase/lib/Everything/Node/Test/container.pm 2006-05-18 22:31:43 UTC (rev 879) @@ -4,6 +4,7 @@ use warnings; use base 'Everything::Node::Test::node'; + use Test::More; sub test_dbtables :Test( 2 ) Modified: trunk/ebase/lib/Everything/Node/Test/dbtable.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/dbtable.pm 2006-05-18 22:12:07 UTC (rev 878) +++ trunk/ebase/lib/Everything/Node/Test/dbtable.pm 2006-05-18 22:31:43 UTC (rev 879) @@ -5,11 +5,8 @@ use base 'Everything::Node::Test::node'; -use SUPER; use Test::More; -*Everything::Node::dbtable::SUPER = \&UNIVERSAL::SUPER; - sub test_insert :Test( 8 ) { my $self = shift; Modified: trunk/ebase/lib/Everything/Node/Test/document.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/document.pm 2006-05-18 22:12:07 UTC (rev 878) +++ trunk/ebase/lib/Everything/Node/Test/document.pm 2006-05-18 22:31:43 UTC (rev 879) @@ -5,11 +5,8 @@ use base 'Everything::Node::Test::node'; -use SUPER; use Test::More; -*Everything::Node::document::SUPER = \&UNIVERSAL::SUPER; - sub test_dbtables :Test( 2 ) { my $self = shift; Modified: trunk/ebase/lib/Everything/Node/Test/htmlcode.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/htmlcode.pm 2006-05-18 22:12:07 UTC (rev 878) +++ trunk/ebase/lib/Everything/Node/Test/htmlcode.pm 2006-05-18 22:31:43 UTC (rev 879) @@ -6,10 +6,7 @@ use base 'Everything::Node::Test::node'; use Test::More; -use SUPER; -*Everything::Node::htmlcode::SUPER = \&UNIVERSAL::SUPER; - sub test_dbtables :Test( 2 ) { my $self = shift; Modified: trunk/ebase/lib/Everything/Node/Test/htmlpage.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/htmlpage.pm 2006-05-18 22:12:07 UTC (rev 878) +++ trunk/ebase/lib/Everything/Node/Test/htmlpage.pm 2006-05-18 22:31:43 UTC (rev 879) @@ -4,11 +4,9 @@ use warnings; use base 'Everything::Node::Test::node'; + use Test::More; -use SUPER; -*Everything::Node::htmlpage::SUPER = \&UNIVERSAL::SUPER; - sub test_dbtables { my $self = shift; Modified: trunk/ebase/lib/Everything/Node/Test/htmlsnippet.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/htmlsnippet.pm 2006-05-18 22:12:07 UTC (rev 878) +++ trunk/ebase/lib/Everything/Node/Test/htmlsnippet.pm 2006-05-18 22:31:43 UTC (rev 879) @@ -4,6 +4,7 @@ use warnings; use base 'Everything::Node::Test::htmlcode'; + use Test::More; sub test_extends :Test( +1 ) Modified: trunk/ebase/lib/Everything/Node/Test/image.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/image.pm 2006-05-18 22:12:07 UTC (rev 878) +++ trunk/ebase/lib/Everything/Node/Test/image.pm 2006-05-18 22:31:43 UTC (rev 879) @@ -6,10 +6,7 @@ use base 'Everything::Node::Test::node'; use Test::More; -use SUPER; -*Everything::Node::image::SUPER = \&UNIVERSAL::SUPER; - sub test_dbtables { my $self = shift; Modified: trunk/ebase/lib/Everything/Node/Test/location.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/location.pm 2006-05-18 22:12:07 UTC (rev 878) +++ trunk/ebase/lib/Everything/Node/Test/location.pm 2006-05-18 22:31:43 UTC (rev 879) @@ -4,9 +4,8 @@ use warnings; use base 'Everything::Node::Test::node'; + use Test::More; -use SUPER; -*Everything::Node::location::SUPER = \&UNIVERSAL::SUPER; sub test_nuke :Test( +8 ) { Modified: trunk/ebase/lib/Everything/Node/Test/mail.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/mail.pm 2006-05-18 22:12:07 UTC (rev 878) +++ trunk/ebase/lib/Everything/Node/Test/mail.pm 2006-05-18 22:31:43 UTC (rev 879) @@ -5,11 +5,8 @@ use base 'Everything::Node::Test::document'; -use SUPER; use Test::More; -*Everything::Node::document::SUPER = \&UNIVERSAL::SUPER; - sub test_dbtables :Test( 2 ) { my $self = shift; Modified: trunk/ebase/lib/Everything/Node/Test/node.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/node.pm 2006-05-18 22:12:07 UTC (rev 878) +++ trunk/ebase/lib/Everything/Node/Test/node.pm 2006-05-18 22:31:43 UTC (rev 879) @@ -11,8 +11,6 @@ use Scalar::Util qw( reftype blessed ); -local *Everything::Node::SUPER = \&UNIVERSAL::SUPER; - sub node_class { my $self = shift; Modified: trunk/ebase/lib/Everything/Node/Test/nodeball.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/nodeball.pm 2006-05-18 22:12:07 UTC (rev 878) +++ trunk/ebase/lib/Everything/Node/Test/nodeball.pm 2006-05-18 22:31:43 UTC (rev 879) @@ -5,11 +5,8 @@ use base 'Everything::Node::Test::nodegroup'; -use SUPER; use Test::More; -*Everything::Node::nodeball::SUPER = \&UNIVERSAL::SUPER; - sub test_dbtables :Test( 2 ) { my $self = shift; Modified: trunk/ebase/lib/Everything/Node/Test/nodegroup.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/nodegroup.pm 2006-05-18 22:12:07 UTC (rev 878) +++ trunk/ebase/lib/Everything/Node/Test/nodegroup.pm 2006-05-18 22:31:43 UTC (rev 879) @@ -5,11 +5,8 @@ use base 'Everything::Node::Test::node'; -use SUPER; use Test::More; -*Everything::Node::nodegroup::SUPER = \&UNIVERSAL::SUPER; - sub test_construct :Test( 1 ) { my $self = shift; @@ -780,3 +777,5 @@ is( $result, 11, '... returning the result' ); } + +1; Modified: trunk/ebase/lib/Everything/Node/Test/nodelet.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/nodelet.pm 2006-05-18 22:12:07 UTC (rev 878) +++ trunk/ebase/lib/Everything/Node/Test/nodelet.pm 2006-05-18 22:31:43 UTC (rev 879) @@ -5,11 +5,8 @@ use base 'Everything::Node::Test::node'; -use SUPER; use Test::More; -*Everything::Node::nodelet::SUPER = \&UNIVERSAL::SUPER; - sub test_dbtables :Test( 2 ) { my $self = shift; Modified: trunk/ebase/lib/Everything/Node/Test/nodemethod.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/nodemethod.pm 2006-05-18 22:12:07 UTC (rev 878) +++ trunk/ebase/lib/Everything/Node/Test/nodemethod.pm 2006-05-18 22:31:43 UTC (rev 879) @@ -4,6 +4,7 @@ use warnings; use base 'Everything::Node::Test::node'; + use Test::More; sub test_dbtables :Test( 2 ) Modified: trunk/ebase/lib/Everything/Node/Test/nodetype.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/nodetype.pm 2006-05-18 22:12:07 UTC (rev 878) +++ trunk/ebase/lib/Everything/Node/Test/nodetype.pm 2006-05-18 22:31:43 UTC (rev 879) @@ -4,12 +4,9 @@ use warnings; use base 'Everything::Node::Test::node'; + use Test::More; -use SUPER; -# XXX - hack for now -*Everything::Node::nodetype::SUPER = \&UNIVERSAL::SUPER; - sub startup :Test( +1 ) { my $self = shift; Modified: trunk/ebase/lib/Everything/Node/Test/opcode.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/opcode.pm 2006-05-18 22:12:07 UTC (rev 878) +++ trunk/ebase/lib/Everything/Node/Test/opcode.pm 2006-05-18 22:31:43 UTC (rev 879) @@ -4,6 +4,7 @@ use warnings; use base 'Everything::Node::Test::htmlcode'; + use Test::More; sub test_extends :Test( +1 ) Modified: trunk/ebase/lib/Everything/Node/Test/setting.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/setting.pm 2006-05-18 22:12:07 UTC (rev 878) +++ trunk/ebase/lib/Everything/Node/Test/setting.pm 2006-05-18 22:31:43 UTC (rev 879) @@ -5,11 +5,8 @@ use base 'Everything::Node::Test::node'; -use SUPER; use Test::More; -*Everything::Node::setting::SUPER = \&UNIVERSAL::SUPER; - sub test_extends :Test( +1 ) { my $self = shift; Modified: trunk/ebase/lib/Everything/Node/Test/superdoc.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/superdoc.pm 2006-05-18 22:12:07 UTC (rev 878) +++ trunk/ebase/lib/Everything/Node/Test/superdoc.pm 2006-05-18 22:31:43 UTC (rev 879) @@ -5,11 +5,8 @@ use base 'Everything::Node::Test::document'; -use SUPER; use Test::More; -*Everything::Node::document::SUPER = \&UNIVERSAL::SUPER; - sub test_dbtables :Test( 2 ) { my $self = shift; Modified: trunk/ebase/lib/Everything/Node/Test/theme.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/theme.pm 2006-05-18 22:12:07 UTC (rev 878) +++ trunk/ebase/lib/Everything/Node/Test/theme.pm 2006-05-18 22:31:43 UTC (rev 879) @@ -4,6 +4,7 @@ use warnings; use base 'Everything::Node::Test::nodeball'; + use Test::More; sub test_extends :Test( +1 ) Modified: trunk/ebase/lib/Everything/Node/Test/themesetting.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/themesetting.pm 2006-05-18 22:12:07 UTC (rev 878) +++ trunk/ebase/lib/Everything/Node/Test/themesetting.pm 2006-05-18 22:31:43 UTC (rev 879) @@ -5,9 +5,7 @@ use base 'Everything::Node::Test::setting'; -use SUPER; use Test::More; -*Everything::Node::themesetting::SUPER = \&UNIVERSAL::SUPER; sub test_extends :Test( +1 ) { @@ -30,3 +28,5 @@ is_deeply( \@tables, [qw( themesetting setting node )], 'dbtables() should return node tables' ); } + +1; Modified: trunk/ebase/lib/Everything/Node/Test/user.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/user.pm 2006-05-18 22:12:07 UTC (rev 878) +++ trunk/ebase/lib/Everything/Node/Test/user.pm 2006-05-18 22:31:43 UTC (rev 879) @@ -3,15 +3,11 @@ use strict; use warnings; -use SUPER; -use Scalar::Util 'reftype'; +use base 'Everything::Node::Test::setting'; use Test::More; +use Scalar::Util 'reftype'; -*Everything::Node::user::SUPER = \&UNIVERSAL::SUPER; - -use base 'Everything::Node::Test::setting'; - sub test_extends :Test( +1 ) { my $self = shift; Modified: trunk/ebase/lib/Everything/Node/Test/usergroup.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/usergroup.pm 2006-05-18 22:12:07 UTC (rev 878) +++ trunk/ebase/lib/Everything/Node/Test/usergroup.pm 2006-05-18 22:31:43 UTC (rev 879) @@ -4,6 +4,7 @@ use warnings; use base 'Everything::Node::Test::nodegroup'; + use Test::More; sub test_extends :Test( +1 ) Modified: trunk/ebase/lib/Everything/Node/Test/workspace.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/workspace.pm 2006-05-18 22:12:07 UTC (rev 878) +++ trunk/ebase/lib/Everything/Node/Test/workspace.pm 2006-05-18 22:31:43 UTC (rev 879) @@ -4,11 +4,9 @@ use warnings; use base 'Everything::Node::Test::setting'; + use Test::More; -use SUPER; -*Everything::Node::workspace::SUPER = \&UNIVERSAL::SUPER; - sub test_extends :Test( +1 ) { my $self = shift; Modified: trunk/ebase/lib/Everything/Node.pm =================================================================== --- trunk/ebase/lib/Everything/Node.pm 2006-05-18 22:12:07 UTC (rev 878) +++ trunk/ebase/lib/Everything/Node.pm 2006-05-18 22:31:43 UTC (rev 879) @@ -22,6 +22,7 @@ use Everything (); use Everything::Util; use XML::DOM; +use SUPER; =cut @@ -131,175 +132,6 @@ return $$this{node_id}; } -=cut - - -=head2 C<AUTOLOAD> - -This allows us to call functions like $NODE-E<gt>someFunc(), while implementing -them in either a .pm or a nodemethod node. This is the magic behind how -Everything implements its method inheritance. MAKE SURE YOU UNDERSTAND HOW -THIS WORKS before changing anything in here. You could break the whole system -if this is wrong. - -Returns whatever the function you are calling returns - -=cut - -sub AUTOLOAD -{ - my $this = shift; - - # We just want the function name, not all the package info. - my ($func) = $Everything::Node::AUTOLOAD =~ /::(\w+)$/; - - my $TYPE = $this->{DB}->getType( $$this{SUPERtype} ); - my $origType = $this->{SUPERtype}; - my $origFunc = $this->{SUPERfunc}; - my $origParams = $this->{SUPERparams}; - my $result; - - if ( ( defined( $this->{SUPERfunc} ) ) && ( $func ne $this->{SUPERfunc} ) ) - { - - # If the function being called is different from what we have - # as a SUPERfunc, that means the implementation has called - # another function on this same object. We don't want to have - # this call the function on the SUPERtype - $TYPE = $this->{type}; - } - else - { - $TYPE ||= $this->{type}; - } - - $this->{SUPERtype} = $TYPE->{node_id}; - $this->{SUPERfunc} = $func; - - # Make a copy of the parameters in case they modify the default array. - $this->{SUPERparams} = [@_]; - - my $METHOD = $this->getNodeMethod( $func, $TYPE ); - - if ( defined $METHOD ) - { - my ( $warn, $code, $N ); - my $error = ''; - - # When we search for a method, on type X, we may find it on - # one of its parent types. So, we want to make sure we set - # the current type appropriately otherwise we may end up - # executing the same function 2 or more times (bad). - $this->{SUPERtype} = $METHOD->{SUPERtype}; - - local $SIG{__WARN__} = sub { - $warn .= $_[0] unless $_[0] =~ /^Use of uninitialized value/; - }; - - if ( $METHOD->{type} eq 'nodemethod' ) - { - - # This a method that is in a node. Eval it. - unshift @_, $this; - $N = $this->{DB}->getNode( $METHOD->{node} ); - $code = $N->{code}; - $code =~ tr/\015//d; - $result = eval($code); - $error = $@; - } - - if ( $error or $METHOD->{type} eq 'pm' ) - { - - # We didn't find a method in node form. Execute the default in - # the corresponding .pm. - $code = $METHOD->{name} . "(\@_);"; - my $meth = $METHOD->{name}; - $result = eval { $this->$meth(@_) }; - } - - Everything::logErrors( $warn, $@, $code, $N ) if $warn or $@; - } - else - { - - # A function of the given name was not found for us! Throw an error! - die -"Error! No function '$func' for nodetype $this->{type}{title}.\n($TYPE->{node_id},$this->{title},$this->{node_id})"; - } - - # Set these back to what they were. - $this->{SUPERtype} = $origType; - $this->{SUPERfunc} = $origFunc; - $this->{SUPERparams} = $origParams; - - return $result; -} - -=cut - - -=head2 C<SUPER> - -This implements the idea of calling a parent (inherited) implementation from a -overrided function. This allows you to call $this-E<gt>SUPER(); from a -function implementation and it will call the parent's implementation of that -function. This is similar to the concept in Java. - -Returns the result of calling the parent implementation - -=cut - -sub SUPER -{ - my $this = shift @_; - my $TYPE = $$this{DB}->getType( $$this{SUPERtype} ); - my $PARENT = $$this{DB}->getType( $$TYPE{extends_nodetype} ); - - if ($PARENT) - { - my $origType = $$this{SUPERtype}; - my $origParams = $$this{SUPERparams}; - my $origFunc = $$this{SUPERfunc}; - my $result; - - $$this{SUPERtype} = $PARENT->getId(); - - # If no parameters were passed, we will use the parameters passed - # to the original call to this function. - unless (@_) - { - my $params = $$this{SUPERparams}; - push @_, @$params; - } - - # We use the object reference here to call the function. - my $exec = "\$this->$$this{SUPERfunc}(\@_);"; - my $warn; - - local $SIG{__WARN__} = sub { - $warn .= $_[0]; - }; - - $result = eval($exec); - - local $SIG{__WARN__} = sub { }; - - Everything::logErrors( $warn, $@, $exec ); - - $$this{SUPERtype} = $origType; - $$this{SUPERparams} = $origParams; - $$this{SUPERfunc} = $origFunc; - - return $result; - } - - die "No SUPER for function $$this{SUPERfunc} for type $$TYPE{title}\n"; -} - -=cut - - =head2 C<getNodeMethod> This is a utility function that finds the method of the given name for the Modified: trunk/ebase/t/Node.t =================================================================== --- trunk/ebase/t/Node.t 2006-05-18 22:12:07 UTC (rev 878) +++ trunk/ebase/t/Node.t 2006-05-18 22:31:43 UTC (rev 879) @@ -1,16 +1,10 @@ -#!/usr/bin/perl -w +#! perl use strict; +use warnings; -BEGIN -{ - chdir 't' if -d 't'; - unshift @INC, '../blib/lib', 'lib/', '..'; -} +use vars '$AUTOLOAD'; -use strict; -use vars qw( $AUTOLOAD ); - use Test::More tests => 42; use Test::MockObject; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-05-22 23:24:35
|
Revision: 881 Author: chromatic Date: 2006-05-22 16:24:16 -0700 (Mon, 22 May 2006) ViewCVS: http://svn.sourceforge.net/everydevel/?rev=881&view=rev Log Message: ----------- r17440@windwheel: chromatic | 2006-05-22 16:24:07 -0700 Extracted Everything::NodeBase::Workspace from Everything::NodeBase. Started porting Everything::NodeBase tests to the new style. Modified Paths: -------------- trunk/ebase/MANIFEST trunk/ebase/lib/Everything/HTML.pm trunk/ebase/lib/Everything/NodeBase.pm trunk/ebase/t/NodeBase.t Added Paths: ----------- trunk/ebase/lib/Everything/NodeBase/Workspace.pm trunk/ebase/lib/Everything/Test/ trunk/ebase/lib/Everything/Test/NodeBase.pm Property Changed: ---------------- trunk/ebase/ Property changes on: trunk/ebase ___________________________________________________________________ Name: svk:merge - a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:17231 + a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:17440 Modified: trunk/ebase/MANIFEST =================================================================== --- trunk/ebase/MANIFEST 2006-05-20 01:01:56 UTC (rev 880) +++ trunk/ebase/MANIFEST 2006-05-22 23:24:16 UTC (rev 881) @@ -120,8 +120,10 @@ lib/Everything/Node/Test/workspace.pm lib/Everything/Nodeball.pm lib/Everything/NodeBase.pm +lib/Everything/NodeBase/Workspace.pm lib/Everything/NodeCache.pm lib/Everything/Security.pm +lib/Everything/Test/NodeBase.pm lib/Everything/Util.pm lib/Everything/XML.pm Makefile.PL Modified: trunk/ebase/lib/Everything/HTML.pm =================================================================== --- trunk/ebase/lib/Everything/HTML.pm 2006-05-20 01:01:56 UTC (rev 880) +++ trunk/ebase/lib/Everything/HTML.pm 2006-05-22 23:24:16 UTC (rev 881) @@ -3032,7 +3032,7 @@ $query = getCGI($initializer); - $AUTH ||= new Everything::Auth($options); + $AUTH ||= Everything::Auth->new($options); ( $USER, $VARS ) = $AUTH->authUser(); Added: trunk/ebase/lib/Everything/NodeBase/Workspace.pm =================================================================== --- trunk/ebase/lib/Everything/NodeBase/Workspace.pm (rev 0) +++ trunk/ebase/lib/Everything/NodeBase/Workspace.pm 2006-05-22 23:24:16 UTC (rev 881) @@ -0,0 +1,204 @@ +=head1 Everything::NodeBase::Workspace + +Wrapper for the Everything database and cache with workspace ability. + +Copyright 2006 Everything Development Inc. + +=cut + +package Everything::NodeBase::Workspace; + +use strict; +use warnings; + +use base 'Everything::NodeBase'; + +use File::Spec; + +=head2 C<joinWorkspace> + +create the $DB-E<gt>{workspace} object if a workspace is specified. If the +sole parameter is 0, then the workspace is deleted. + +=over 4 + +=item * WORKSPACE + +workspace_id, node, or 0 for none + +=back + +=cut + +sub joinWorkspace +{ + my ( $this, $WORKSPACE ) = @_; + + delete $this->{workspace} if exists $this->{workspace}; + + return 1 unless $WORKSPACE; + + $this->getRef($WORKSPACE); + return -1 unless $WORKSPACE; + + $this->{workspace} = $WORKSPACE; + $this->{workspace}{nodes} = $WORKSPACE->getVars(); + $this->{workspace}{nodes} ||= {}; + $this->{workspace}{cached_nodes} = {}; + + 1; +} + +=head2 C<getNodeWorkspace> + +Helper funciton for getNode's workspace functionality. Given a $WHERE hash ( +field =E<gt> value, or field =E<gt> [value1, value2, value3]) return a list of +nodes in the workspace which fullfill this query + +=over 4 + +=item * $WHERE + +where hash, similar to getNodeWhere + +=item * $TYPE + +type discrimination (optional) + +=back + +=cut + +sub getNodeWorkspace +{ + my ( $this, $WHERE, $TYPE ) = @_; + my @results; + $TYPE = $this->getType($TYPE) if $TYPE; + + my $cmpval = sub { + my ( $val1, $val2 ) = @_; + + $val1 = $val1->{node_id} if eval { $val1->isa( 'Everything::Node' ) }; + $val2 = $val2->{node_id} if eval { $val2->isa( 'Everything::Node' ) }; + + $val1 eq $val2; + }; + + #we need to iterate through our workspace + foreach my $node ( keys %{ $this->{workspace}{nodes} } ) + { + my $N = $this->getNode($node); + next if $TYPE and $$N{type}{node_id} != $$TYPE{node_id}; + + my $match = 1; + foreach ( keys %$WHERE ) + { + if ( ref $$WHERE{$_} eq 'ARRAY' ) + { + my $matchor = 0; + foreach my $orval ( @{ $$WHERE{$_} } ) + { + $matchor = 1 if $cmpval->( $$N{$_}, $orval ); + } + $match = 0 unless $matchor; + } + else + { + $match = 0 unless $cmpval->( $$N{$_}, $$WHERE{$_} ); + } + } + push @results, $N if $match; + } + + \@results; +} + +=head2 C<getNode> + +This overrides C<getNode()> to allow for workspaced fetches. + +=over 4 + +=item * $node + +either the string title, node id, NODE object, or "where hash ref". The NODE +object is just for ease of use, so you can call this function without worrying +if the node thingy is an ID or object. If this is a where hash ref, this +simply does a getNodeWhere() and returns the first match only (just a quicky +way of doing a getNodeWhere()) + +=item * $ext + +extra info. If $node is a string title, this must be either a hashref to a +nodetype node, or a nodetype id. If $node is an id, $ext is optional and can +be either 'light' or 'force'. If 'light' it will retrieve only the information +from the node table (faster). If 'force', it will reload the node even if it +is cached. + +=item * $ext2 + +more extra info. If this is a "title/type" query, passing 'create' will cause +a dummy object to be created and returned if a node is not found. Using the +dummy node, you can then add or modify its fields and then do a +$NODE-E<gt>insert($USER) to insert it into the database. If you wish to create +a node even if a node of the same "title/type" exists, pass "create force". A +dummy node has a node_id of '-1'. + +If $node is a "where hash ref", this is the "order by" string that you can pass +to order the result by (you will still only get one node). + +=back + +Returns a node object if successful. undef otherwise. + +=cut + +sub getNode +{ + my ( $this, $node, $ext, $ext2 ) = @_; + warn "<$node>\n"; + return unless defined $node and $node ne ''; + + # it may already be a node + return $node if eval { $node->isa( 'Everything::Node' ) }; + warn "Not a node\n"; + + my $cache = ""; + + if ( ref $node eq 'HASH' ) + { + # This a "where" select + my $nodeArray = $this->getNodeWhere( $node, $ext, $ext2, 1 ) || []; + my $wspaceArray = $this->getNodeWorkspace( $node, $ext ); + + # the nodes we get back are unordered, must be merged with the + # workspace. Also any nodes which were in the nodearray, and the + # workspace, but not the wspace array must be removed + + my @results = ( + ( grep { !exists $this->{workspace}{nodes}{ $_->{node_id} } } + @$nodeArray ), + @$wspaceArray + ); + + return unless @results; + my $orderby = $ext2 || 'node_id'; + my $position = ( $orderby =~ /\s+desc/i ) ? -1 : 0; + @results = sort { $a->{$orderby} cmp $b->{$orderby} } @results; + return $results[$position]; + } + + my $NODE = $this->SUPER( $node, $ext, $ext2 ); + return unless $NODE; + + if (exists $this->{workspace}{nodes}{ $NODE->{node_id} } + and $this->{workspace}{nodes}{ $NODE->{node_id} } ) + { + my $WS = $NODE->getWorkspaced(); + return $WS if $WS; + } + + return $NODE; +} + +1; Property changes on: trunk/ebase/lib/Everything/NodeBase/Workspace.pm ___________________________________________________________________ Name: svn:mime-type + text/plain; charset=UTF-8 Name: svn:eol-style + native Modified: trunk/ebase/lib/Everything/NodeBase.pm =================================================================== --- trunk/ebase/lib/Everything/NodeBase.pm 2006-05-20 01:01:56 UTC (rev 880) +++ trunk/ebase/lib/Everything/NodeBase.pm 2006-05-22 23:24:16 UTC (rev 881) @@ -16,6 +16,8 @@ use Everything::DB; use Everything::Node; use Everything::NodeCache; +use Everything::NodeBase::Workspace; + use Scalar::Util 'reftype'; BEGIN @@ -108,7 +110,8 @@ =head2 C<joinWorkspace> create the $DB-E<gt>{workspace} object if a workspace is specified. If the -sole parameter is 0, then the workspace is deleted. +sole parameter is 0, then the workspace is deleted. Note that this will +re-bless the current object, if the user is in a workspace. =over 4 @@ -128,80 +131,12 @@ return 1 unless $WORKSPACE; - $this->getRef($WORKSPACE); - return -1 unless $WORKSPACE; - $this->{workspace} = $WORKSPACE; - $this->{workspace}{nodes} = $WORKSPACE->getVars; - $this->{workspace}{nodes} ||= {}; - $this->{workspace}{cached_nodes} = {}; + # XXX - ugly workaround; fix soon + bless $this, 'Everything::NodeBase::Workspace'; - 1; + $this->joinWorkspace( $WORKSPACE ); } -=head2 C<getNodeWorkspace> - -Helper funciton for getNode's workspace functionality. Given a $WHERE hash ( -field =E<gt> value, or field =E<gt> [value1, value2, value3]) return a list of -nodes in the workspace which fullfill this query - -=over 4 - -=item * $WHERE - -where hash, similar to getNodeWhere - -=item * $TYPE - -type discrimination (optional) - -=back - -=cut - -sub getNodeWorkspace -{ - my ( $this, $WHERE, $TYPE ) = @_; - my @results; - $TYPE = $this->getType($TYPE) if $TYPE; - - my $cmpval = sub { - my ( $val1, $val2 ) = @_; - - $val1 = $val1->{node_id} if eval { $val1->isa( 'Everything::Node' ) }; - $val2 = $val2->{node_id} if eval { $val2->isa( 'Everything::Node' ) }; - - $val1 eq $val2; - }; - - #we need to iterate through our workspace - foreach my $node ( keys %{ $this->{workspace}{nodes} } ) - { - my $N = $this->getNode($node); - next if $TYPE and $$N{type}{node_id} != $$TYPE{node_id}; - - my $match = 1; - foreach ( keys %$WHERE ) - { - if ( ref $$WHERE{$_} eq 'ARRAY' ) - { - my $matchor = 0; - foreach my $orval ( @{ $$WHERE{$_} } ) - { - $matchor = 1 if $cmpval->( $$N{$_}, $orval ); - } - $match = 0 unless $matchor; - } - else - { - $match = 0 unless $cmpval->( $$N{$_}, $$WHERE{$_} ); - } - } - push @results, $N if $match; - } - - \@results; -} - =head2 C<rebuildNodetypeModules> Call this to account for any new nodetypes that may have been installed. @@ -372,40 +307,10 @@ if ( ref $node eq 'HASH' ) { - # This a "where" select my $nodeArray = $this->getNodeWhere( $node, $ext, $ext2, 1 ) || []; - if ( exists $this->{workspace} ) - { - my $wspaceArray = $this->getNodeWorkspace( $node, $ext ); - - #the nodes we get back are unordered, must be merged - #with the workspace. Also any nodes which were in the - #nodearray, and the workspace, but not the wspace array - #must be removed - - my @results = ( - ( - grep { !exists $this->{workspace}{nodes}{ $_->{node_id} } } - @$nodeArray - ), - @$wspaceArray - ); - - return unless @results; - my $orderby = $ext2 || 'node_id'; - - my $position = ( $orderby =~ /\s+desc/i ) ? -1 : 0; - - @results = sort { $a->{$orderby} cmp $b->{$orderby} } @results; - return $results[$position]; - return shift @results; - } - else - { - return $nodeArray->[0] if @$nodeArray; - return; - } + return $nodeArray->[0] if @$nodeArray; + return; } elsif ( $node =~ /^\d+$/ ) { @@ -450,16 +355,8 @@ return unless $NODE; - $NODE = Everything::Node->new( $NODE, $this, $cache ); + return Everything::Node->new( $NODE, $this, $cache ); - if ( exists $this->{workspace} - and exists $this->{workspace}{nodes}{ $NODE->{node_id} } - and $this->{workspace}{nodes}{ $NODE->{node_id} } ) - { - my $WS = $NODE->getWorkspaced(); - return $WS if $WS; - } - return $NODE; } Added: trunk/ebase/lib/Everything/Test/NodeBase.pm =================================================================== --- trunk/ebase/lib/Everything/Test/NodeBase.pm (rev 0) +++ trunk/ebase/lib/Everything/Test/NodeBase.pm 2006-05-22 23:24:16 UTC (rev 881) @@ -0,0 +1,668 @@ +package Everything::Test::NodeBase; + +use strict; +use warnings; + +use base 'Test::Class'; + +use Test::More; +use Test::MockObject; +use Test::MockObject::Extends; + +use Scalar::Util 'blessed'; + +sub module_class +{ + my $self = shift; + my $name = blessed( $self ); + $name =~ s/Test:://; + return $name; +} + +sub startup :Test( startup => 3 ) +{ + my $self = shift; + my $module = $self->module_class(); + use_ok( $module ) or exit; + + can_ok( $module, 'new' ); + + $self->reset_mock_nb(); + + isa_ok( $self->{nb}, $module ); +} + +sub make_fixture :Test( setup ) +{ + my $self = shift; + my $storage = Test::MockObject->new(); + $self->reset_mock_nb(); + + $self->{storage} = $storage; + $self->{nb}{storage} = $storage; + $self->{errors} = []; +} + +sub reset_mock_nb +{ + my $self = shift; + my $module = $self->module_class(); + + my $mock_db = Test::MockObject->new(); + $mock_db->set_false(qw( getNodeByIdNew getNodeByName )) + ->set_true(qw( databaseConnect buildNodetypeModules )) + ->fake_module( 'Everything::DB::fake_db', 'new', sub { $mock_db }); + + my $nb = $module->new( '', 0, 'fake_db' ); + $self->{nb} = Test::MockObject::Extends->new( $nb ); +} + +sub test_new +{ + # check $db param + # check presence of NodeCache + # check dbname + # check staticNodetypes field + # check storage + # check nodetypeModules + # check if setting type exists + # - check cache settings + # - check cache size +} + +BEGIN +{ + for my $method (qw( + buildNodetypeModules getDatabaseHandle sqlDelete sqlSelect + sqlSelectJoined sqlSelectMany sqlSelectHashref sqlUpdate sqlInsert + _quoteData sqlExecute getNodeByIdNew getNodeByName constructNode + selectNodeWhere getNodeCursor countNodeMatches getAllTypes + dropNodeTable quote genWhereString + )) + { + eval <<" END_SUB"; + sub test_$method :Test( 3 ) + { + my \$self = shift; + my \$nb = \$self->{nb}; + my \$storage = \$self->{storage}; + + \$storage->set_always( $method => 'proxied_$method' ); + can_ok( \$nb, '$method' ); + + my \$result = \$nb->$method(); + + is( \$storage->next_call(), '$method', + '$method should proxy to storage method' ); + is( \$result, 'proxied_$method', '... returning result' ); + } + END_SUB + } +} + +sub test_get_type :Test( 9 ) +{ + my $self = shift; + my $nb = $self->{nb}; + + is( $nb->getType(), undef, + 'getType() should return unless passed a node thing' ); + + is( $nb->getType( '' ), undef, '... or if it is empty' ); + + my $mock_node = Test::MockObject::Extends->new( 'Everything::Node' ); + + is( $nb->getType( $mock_node ), $mock_node, + '... returning node if it is a node' ); + + $nb->set_series( getNode => 'name', 'id' ); + + is( $nb->getType( 'name' ), 'name', + '... returning fetched node, if named' ); + + my ( $method, $args ) = $nb->next_call(); + is( join( '-', @$args ), "$nb-name-1", '... by name for nodetype' ); + + is( $nb->getType( 12345 ), 'id', + '... returning node for positive node_id' ); + + ( $method, $args ) = $nb->next_call(); + is( join( '-', @$args ), "$nb-12345", '... by id alone' ); + + is( $nb->getType( 0 ), undef, '... returning nothing for zero id' ); + is( $nb->getType( -1 ), undef, '... or for negative node_id' ); +} + +1; +__END__ + +can_ok( $package, 'getAllTypes' ); +my @list = ( 1 .. 3 ); +$mock_storage->set_series( sqlSelectMany => undef, $mock_storage ) + ->mock( fetchrow => sub { return shift @list if @list; return; } ) + ->set_series( getNode => 'a', 'b', 'c' ) + ->set_true('finish') + ->clear(); + +ok( !getAllTypes($mock), 'getAllTypes() should return without a cursor' ); + +( $method, $args ) = $mock_storage->next_call(); +is( $method, 'sqlSelectMany', '... selecting several rows' ); +is( + join( '-', @$args ), + "$mock_storage-node_id-node-type_nodetype=1", + '... node_ids of nodetype nodes from node table' +); +my @result = getAllTypes($mock); +is_deeply( \@result, [qw( a b c )], '... returning fetched nodes in order' ); + +can_ok( $package, 'getFields' ); +$mock->set_always( getFieldsHash => 'gfh' )->clear(); + +$result = getFields( $mock, 'table' ); + +( $method, $args ) = $mock->next_call(); +is( $method, 'getFieldsHash', 'getFields() should call getFieldsHash()' ); +is( join( '-', @$args ), "$mock-table-0", '... passing table name' ); +is( $result, 'gfh', '... returning results' ); + +can_ok( $package, 'dropNodeTable' ); +{ + local *Everything::printLog; + my @log; + *Everything::printLog = sub { + push @log, [@_]; + }; + + # lots of nodroppables, but testing them all is tedious + ok( !dropNodeTable( $mock, 'container' ), + 'dropNodeTable() should fail if attempting to drop core table' ); + like( $le[0][1], qr/core table 'container'!/, '... logging an error' ); + + $mock_storage->set_series( tableExists => 0, 1 ) + ->set_always( genTableName => 'tname' ) + ->set_always( do => 'done' ) + ->clear(); + + ok( !dropNodeTable( $mock, 'zapit' ), '... failing unless table exists' ); + + ( $method, $args ) = $mock_storage->next_call(); + is( $method, 'tableExists', '... so should check' ); + is( $args->[1], 'zapit', '... with passed table name' ); + + $mock_storage->{dbh} = $mock_storage; + + $result = dropNodeTable( $mock, 'zapit' ); + like( + $log[0][0], + qr/Dropping table 'zapit'/, + '... should log the drop, if attempted' + ); + + ( $method, $args ) = $mock_storage->next_call(2); + is( $method, 'genTableName', '... generating table name' ); + is( $args->[1], 'zapit', '... from passed name' ); + + ( $method, $args ) = $mock_storage->next_call(); + is( $method, 'do', '... performing a SQL call' ); + is( $args->[1], 'drop table tname', '... dropping table' ); + + is( $result, 'done', '... returning result' ); +} + +can_ok( $package, 'quote' ); +$mock_storage->set_always( quote => 'quoted' )->clear(); +$result = quote( $mock, 'quoteme' ); + +( $method, $args ) = $mock_storage->next_call(); +is( $method, 'quote', 'quote() should call DB quote()' ); +is( $args->[1], 'quoteme', '... on passed string' ); +is( $result, 'quoted', '... returning results' ); + +# this interface sucks. Really sucks. +can_ok( $package, 'getRef' ); + +$mock->set_series( getNode => 'first', 'second', 'not third' )->clear(); + +my ( $first, $second, $third, $u ) = ( 1, 2, bless {}, 'Everything::Node' ); +$result = getRef( $mock, $first, $second, $third, $u ); +is( $first, 'first', 'getRef() should modify references in place' ); +is( $second, 'second', '... for all passed in node_ids' ); +ok( $third->isa( 'Everything::Node' ), '... not mangling existing nodes' ); +is( $u, undef, '... skipping undefined values' ); +is( $result, 'first', '... returning node of first element' ); + +can_ok( $package, 'getId' ); +is( getId(), undef, 'getId() should return without node id' ); +my $node = bless { node_id => 11 }, 'Everything::Node'; +is( getId( $mock, $node ), 11, '... returning node_id of node, if provided' ); +is( getId( $mock, 12 ), 12, '... or node_id, if a number' ); +is( getId( $mock, -13 ), -13, '... or an integer' ); +is( getId( $mock, 'foo' ), undef, '... but undef not an integer' ); + +can_ok( $package, 'hasPermission' ); +$mock->set_series( getNode => 0, { code => 'return 1' } )->clear(); +{ + local *Everything::Security::checkPermissions; + + my @cp; + *Everything::Security::checkPermissions = sub { + push @cp, [@_]; + return 'cp'; + }; + + $result = hasPermission( $mock, 'u', 'p', 'm' ); + + ( $method, $args ) = $mock->next_call(); + is( $method, 'getNode', 'checkPermission() should fetch permission node' ); + is( join( '-', @$args ), + "$mock-p-permission", '... by identifier and type' ); + is( $result, 0, '... returning false without that node' ); + + $result = hasPermission( $mock, 'u', 'p', 'm' ); + is( @cp, 1, '... should check permissions with a perm node' ); + is( join( '-', @{ $cp[0] } ), + '1-m', '... with permissions results and mode' ); + is( $result, 'cp', '... returning results' ); +} + +can_ok( $package, 'joinWorkspace' ); +can_ok( $package, 'joinWorkspace' ); +can_ok( $package, 'buildNodetypeModules' ); + +$mock_storage->set_series( sqlSelectMany => 0, $mock_storage ) + ->set_series( fetchrow_array => qw( user nodetype blah ) ) + ->set_series( loadNodetypeModule => 1, 1, 0 ); + +is( buildNodetypeModules($mock), undef, + 'buildNodetypeModules() should return with no database cursor' ); + +is_deeply( + buildNodetypeModules($mock), + { "Everything::Node::user" => 1, "Everything::Node::nodetype" => 1 }, + '... returning a hashref of available nodetype names' +); + +can_ok( $package, 'loadNodetypeModule' ); +ok( + loadNodetypeModule( $mock, 'Everything::NodeBase' ), + 'loadNodetypeModule() should return true if module is loaded' +); + +@le = (); +ok( loadNodetypeModule( $mock, 'Everything::Node::user' ), + '... or if module can be loaded' ); +ok( !loadNodetypeModule( $mock, 'Everything::Node::blah' ), + '... but false if it cannot' ); + +can_ok( $package, 'getNode' ); + +my ( @ennew, $ennew ); +$mock->set_always( getNodeByIdNew => { title => 'node by id' } ) + ->fake_new( "Everything::Node" => sub { push @ennew, [@_]; $ennew } ); +$mock->clear(); + +$ennew = { node_id => 11 }; + +isnt( getNode( $mock, 0 ), + undef, 'getNode() should return node zero given node_id of 0' ); + +exit; + +can_ok( $package, 'getNodeByName' ); +can_ok( $package, 'getNodeByIdNew' ); +can_ok( $package, 'constructNode' ); +can_ok( $package, 'getNodeCursor' ); +can_ok( $package, 'genWhereString' ); +can_ok( $package, 'getNodetypeTables' ); + +can_ok( $package, 'rebuildNodetypeModules' ); +$mock->set_always( 'buildNodetypeModules', 'bntm' ); +$mock->{nodetypeModules} = ''; +rebuildNodetypeModules($mock); +is( $mock->call_pos(-1), 'buildNodetypeModules', + 'rebuildNodetypeModules() should call buildNodetypeModules' ); +is( $mock->{nodetypeModules}, 'bntm', '... caching results' ); + +can_ok( $package, 'resetNodeCache' ); +$mock->set_true('resetCache')->{cache} = $mock; +$mock->{storage}{cache} = $mock; +resetNodeCache($mock); +is( $mock->call_pos(-1), 'resetCache', + 'resetNodeCache() should call resetCache() on cache' ); + +can_ok( $package, 'getDatabaseHandle' ); +$mock_storage->{dbh} = 'dbh'; +is( getDatabaseHandle($mock), 'dbh', 'getDatabaseHandle() should return dbh' ); + +can_ok( $package, 'getCache' ); +$mock->{cache} = 'cache'; +$mock->{storage}{cache} = 'cache'; +is( getCache($mock), 'cache', 'getCache() should return cache' ); + +can_ok( $package, 'newNode' ); +$mock->set_always( 'getType', 'gt' )->set_always( 'getNode', 'gn' )->clear(); + +$result = newNode( $mock, 'type', 'title' ); + +( $method, $args ) = $mock->next_call(); +is( $method, 'getType', 'newNode() should fetch nodetype node' ); +is( $args->[1], 'type', '... for the requested nodetype' ); + +( $method, $args ) = $mock->next_call(); +is( $method, 'getNode', '... calling getNode()' ); +is( join( '-', @$args[ 1, 2 ] ), + 'title-gt', '... with title and nodetype node' ); +is( $args->[3], 'create force', '... forcing node creation' ); + +newNode( $mock, '' ); + +( $method, $args ) = $mock->next_call(2); +like( $args->[1], qr/^dummy\d+/, + '... using a dummy title if none is provided' ); + +can_ok( $package, 'getNodeZero' ); +$mock->{nodezero} = 'ZERO'; +is( getNodeZero($mock), 'ZERO', + 'getNodeZero() should return cached node if it exists' ); +delete $mock->{nodezero}; +my $zero = {}; +$mock->set_series( 'getNode', $zero, 'author_user' )->clear(); +$result = getNodeZero($mock); +is( $result, $zero, '... and should cache node if it must be created' ); + +( $method, $args ) = $mock->next_call(); +is( $method, 'getNode', '... fetching a node' ); +is( join( '-', @$args ), "$mock-/-location-create force", + '... forcing creation of the root location' ); + +( $method, $args ) = $mock->next_call(); +is( $method, 'getNode', '... fetching another node' ); +is( join( '-', @$args ), "$mock-root-user", '... the root user' ); +is_deeply( + $zero, + { + node_id => 0, + author_user => 'author_user', + guestaccess => '-----', + otheraccess => '-----', + groupaccess => '-----', + }, + '... and zero node attributes should be set correctly' +); +is( $mock->{nodezero}, $result, '... and node should be cached' ); + +can_ok( $package, 'getNodeWhere' ); +$mock->set_series( 'selectNodeWhere', undef, 'foo', [ 1 .. 5 ] ) + ->set_series( 'getNode', 0, 2, 0, 4, 5 )->clear(); + +my @expected = qw( where type orderby limit offset reftotalrows ); +$result = getNodeWhere( $mock, @expected ); + +( $method, $args ) = $mock->next_call(); +is( $method, 'selectNodeWhere', + 'getNodeWhere() should delegate to selectNodeWhere()' ); +is( + join( '-', @$args ), + join( '-', $mock, @expected ), + '... passing most args' +); +is( $result, undef, '... returning if it fails' ); +is( getNodeWhere($mock), undef, '... or if it does not return a listref' ); +$result = getNodeWhere( $mock, @expected ); +is_deeply( + $result, + [ 2, 4, 5 ], + '... fetching and returning a list ref of nodes' +); + +can_ok( $package, 'sqlDelete' ); +$mock->{storage} = $mock_storage; +$mock_storage->{dbh} = $mock_storage; +ok( !sqlDelete( $mock ), + 'sqlDelete() should return false with no where clause' ); + +$mock_storage->set_always( 'genTableName', 'table name' ) + ->set_always( 'prepare', $mock_storage ) + ->set_always( 'execute', 'executed' ) + ->clear(); + +$result = sqlDelete( $mock, 'table', 'clause', [ 'one', 'two' ] ); + +( $method, $args ) = $mock_storage->next_call(); +is( $method, 'genTableName', '... generating correct table name' ); +is( $args->[1], 'table', '... passing the passed table name' ); + +( $method, $args ) = $mock_storage->next_call(); +is( $method, 'prepare', '... preparing a SQL call' ); +is( $args->[1], 'DELETE FROM table name WHERE clause', + '... with the generated name and where clause' ); + +( $method, $args ) = $mock_storage->next_call(); +is( $method, 'execute', '... executing a SQL call' ); +is( join( '-', @$args ), "$mock_storage-one-two", '... with any bound arguments' ); +sqlDelete( $mock, 1, 2 ); +$mock_storage->called_args_string_is( -1, '-', "$mock_storage", + '... or an empty list with no bound args' ); +is( $result, 'executed', '... returning the result of the execution' ); + +can_ok( $package, 'sqlSelect' ); +my @frargs = ( [], ['one'], [ 'two', 'three' ] ); +$mock_storage->set_series( 'sqlSelectMany', undef, ($mock_storage) x 3 ) + ->mock( 'fetchrow', sub { return @{ shift @frargs } } ) + ->set_true('finish') + ->clear(); + +$result = sqlSelect( $mock, 1 .. 10 ); + +( $method, $args ) = $mock_storage->next_call(); +is( $method, 'sqlSelectMany', 'sqlSelect() should call sqlSelectMany()' ); +is( join( '-', @$args ), "$mock_storage-1-2-3-4-5-6-7-8-9-10", + '... passing all args' ); +ok( !$result, '... returning false if call fails' ); + +ok( !sqlSelect($mock), '... or if no rows are selected' ); +is_deeply( sqlSelect($mock), 'one', '... one item if only one is returned' ); +is_deeply( + sqlSelect($mock), + [ 'two', 'three' ], + '... and a list reference if many' +); + +can_ok( $package, 'sqlSelectJoined' ); +$mock_storage->set_always( 'genTableName', 'gentable' ) + ->set_series( 'prepare', ($mock_storage) x 2, 0 ) + ->set_series( 'execute', 1, 0 ) + ->clear(); + +my $joins = { one => 1, two => 2 }; +$result = sqlSelectJoined( $mock, 'select', 'table', $joins, 'where', 'other', + 'bound', 'values' ); + +( $method, $args ) = $mock_storage->next_call(); +is( $method, 'genTableName', 'sqlSelectJoined() should generate table name' ); +is( $args->[1], 'table', '... if provided' ); + +for my $join ( keys %$joins ) +{ + ( $method, $args ) = $mock_storage->next_call(); + is( $method, 'genTableName', '... and genTable name' ); + is( $args->[1], $join, '... for each joined table' ); +} + +( $method, $args ) = $mock_storage->next_call(); +is( $method, 'prepare', '... preparing a SQL call' ); +like( $args->[1], qr/SELECT select/, '... selecting the requested columns' ); +like( $args->[1], qr/FROM gentable/, + '... from the generated table name if supplied' ); +like( $args->[1], qr/LEFT JOIN gentable ON 1/, + '... left joining joined tables' ); +like( $args->[1], qr/LEFT JOIN gentable ON 2/, '... as necessary' ); +like( $args->[1], qr/WHERE where/, '... adding the where clause if present' ); +like( $args->[1], qr/other/, '... and the other clause' ); + +( $method, $args ) = $mock_storage->next_call(); +is( $method, 'execute', '... executing the query' ); +is( join( '-', @$args ), "$mock_storage-bound-values", + '... with bound values' ); + +is( $result, $mock_storage, '... returning the cursor if it executes' ); +$result = sqlSelectJoined( $mock, 'select' ); +is( $result, undef, '... or undef otherwise' ); + +( $method, $args ) = $mock_storage->next_call(1); +is( $method, 'prepare', '... not joining tables if they are not present' ); +is( $args->[1], 'SELECT select ', + '... nor any table, where, or other clauses unless requested' ); +ok( !sqlSelectJoined( $mock, 'select' ), + '... returning false if prepare fails' ); + +can_ok( $package, 'sqlSelectMany' ); +$mock_storage->set_always( 'genTableName', 'gentable' ) + ->set_series( 'prepare', 0, ($mock_storage) x 5 ) + ->set_series( 'execute', (0) x 3, 1 ) + ->unmock( 'sqlSelectMany' ) + ->clear(); + +$result = sqlSelectMany( $mock, 'sel' ); + +( $method, $args ) = $mock_storage->next_call(); +is( $method, 'prepare', 'sqlSelectMany() should prepare a SQL statement' ); +is( $args->[1], 'SELECT sel ', '... with the selected fields' ); +sqlSelectMany( $mock, 'sel', 'tab' ); + +( $method, $args ) = $mock_storage->next_call(); +is( $method, 'genTableName', '... generating a table name, if passed' ); + +is( ( $mock_storage->next_call() )[1]->[1], 'SELECT sel FROM gentable ', + '... using it in the SQL statement' ); +sqlSelectMany( $mock, 'sel', '', 'whe' ); + +is( ( $mock_storage->next_call(2) )[1]->[1], 'SELECT sel WHERE whe ', + '... adding a where clause if needed' ); +sqlSelectMany( $mock, 'sel', '', '', 'oth' ); + +is( ( $mock_storage->next_call(2) )[1]->[1], 'SELECT sel oth', + '... and an other clause as necessary' ); +ok( !$result, '... returning false if prepare fails' ); +is( sqlSelectMany( $mock, '' ), $mock_storage, + '... the cursor if it succeeds' ); +$mock_storage->called_args_string_is( -1, '-', "$mock_storage", + '... using no bound values by default' ); +sqlSelectMany( $mock, ('') x 4, [ 'hi', 'there' ] ); +$mock_storage->called_args_string_is( -1, '-', "$mock_storage-hi-there", + '... or any bounds passed' ); + +can_ok( $package, 'sqlSelectHashref' ); +$mock_storage->set_series( 'sqlSelectMany', 0, $mock_storage ) + ->set_always( 'fetchrow_hashref', 'hash' ) + ->set_true('finish') + ->clear(); + +$result = sqlSelectHashref( $mock, 'foo', 'bar', 'baz', 'quux', 'qiix' ); + +( $method, $args ) = $mock_storage->next_call(); +is( $method, 'sqlSelectMany', + 'sqlSelectHashref() should call sqlSelectMany()' ); +is( join( '-', @$args ), "$mock_storage-foo-bar-baz-quux-qiix", + '... passing all args' ); +ok( !$result, '... returning false if that fails' ); +is( sqlSelectHashref($mock), 'hash', '... or a fetched hashref on success' ); + +is( $mock_storage->next_call(3), 'finish', + '... finishing the statement handle' ); + +can_ok( $package, 'sqlUpdate' ); +$mock_storage->mock( _quoteData => sub { + [ 'n', 'm', 's' ], [ '?', 1, 8 ], ['foo'] + } ) + ->set_always( 'genTableName', 'gentable' ) + ->set_always( 'sqlExecute', 'executed' ) + ->clear(); + +ok( !sqlUpdate( $mock, 'table', {} ), + 'sqlUpdate() should return false without update data' ); + +my $data = { foo => 'bar' }; +$result = sqlUpdate( $mock, 'table', $data ); + +( $method, $args ) = $mock_storage->next_call(); +is( $method, '_quoteData', '... quoting data, if present' ); +is( $args->[1], $data, '... passing in the data argument' ); + +( $method, $args ) = $mock_storage->next_call(); +is( $method, 'genTableName', '... quoting the table name' ); +is( $args->[1], 'table', '... passing in the table argument' ); + +( $method, $args ) = $mock_storage->next_call(); +is( $method, 'sqlExecute', '... and should execute query' ); +is( $args->[1], "UPDATE gentable SET n = ?,\nm = 1,\ns = 8", + '... with names and values quoted appropriately' ); +is_deeply( $args->[2], ['foo'], '.. and bound args as appropriate' ); + +$mock->clear(); +sqlUpdate( $mock, 'table', $data, 'where clause' ); + +( $method, $args ) = $mock_storage->next_call(3); +like( $args->[1], qr/\nWHERE where clause\n/m, + '... adding the where clause as necessary' ); + +can_ok( $package, 'sqlInsert' ); + +$data = { foo => 'bar' }; +$result = sqlInsert( $mock, 'table', $data ); + +( $method, $args ) = $mock_storage->next_call(); +is( $method, '_quoteData', 'sqlInsert() should quote data, if present' ); +is( $args->[1], $data, '... passing in the data argument' ); + +( $method, $args ) = $mock_storage->next_call(); +is( $method, 'genTableName', '... quoting the table name' ); +is( $args->[1], 'table', '... passing in the table argument' ); + +( $method, $args ) = $mock_storage->next_call(); +is( $method, 'sqlExecute', '... and should execute query' ); +is( $args->[1], "INSERT INTO gentable (n, m, s) VALUES(?, 1, 8)", + '... with names and values quoted appropriately' ); +is_deeply( $args->[2], ['foo'], '.. and bound args as appropriate' ); + +can_ok( $package, '_quoteData' ); +$mock_storage->unmock( '_quoteData' ); + +my ( $names, $values, $bound ) = + $mock_storage->_quoteData( { foo => 'bar', -baz => 'quux' } ); +is( join( '|', sort @$names ), + 'baz|foo', '_quoteData() should remove leading minus from names' ); +ok( ( grep { /quux/ } @$values ), '... treating unquoted values literally' ); +ok( ( grep { /\?/, } @$values ), '... and using placeholders for quoted ones' ); +is( join( '|', @$bound ), 'bar', '... returning quoted values in bound arg' ); + +can_ok( $package, 'sqlExecute' ); +{ + my $log; + + local *Everything::printLog; + *Everything::printLog = sub { $log = shift }; + + $mock_storage->set_series( 'prepare', $mock_storage, 0 ) + ->set_always( 'execute', 'success' ) + ->unmock( 'sqlExecute' ) + ->clear(); + + $result = sqlExecute( $mock, 'sql here', [ 1, 2, 3 ] ); + + ( $method, $args ) = $mock_storage->next_call(); + is( $method, 'prepare', 'sqlExecute() should prepare a statement' ); + is( $args->[1], 'sql here', '... with the passed in SQL' ); + + ( $method, $args ) = $mock_storage->next_call(); + is( $method, 'execute', '... executing the statement' ); + is( join( '-', @$args ), "$mock_storage-1-2-3", + '... with bound variables' ); + is( $result, 'success', '... returning the results' ); + + @le = (); + ok( !sqlExecute( $mock, 'bad', [ 6, 5, 4 ] ), '... or false on failure' ); + is( $le[0][1], "SQL failed: bad [6 5 4]\n", + '... logging SQL and bound values as error' ); +} Property changes on: trunk/ebase/lib/Everything/Test/NodeBase.pm ___________________________________________________________________ Name: svn:mime-type + text/plain; charset=UTF-8 Name: svn:eol-style + native Modified: trunk/ebase/t/NodeBase.t =================================================================== --- trunk/ebase/t/NodeBase.t 2006-05-20 01:01:56 UTC (rev 880) +++ trunk/ebase/t/NodeBase.t 2006-05-22 23:24:16 UTC (rev 881) @@ -1,8 +1,14 @@ #! perl -use strict; -use warnings; +=cut +use Everything::Test::NodeBase; +Everything::Test::NodeBase->runtests(); + +__END__ + +=cut + use strict; use vars qw( $AUTOLOAD ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-05-24 00:27:43
|
Revision: 883 Author: chromatic Date: 2006-05-23 17:27:31 -0700 (Tue, 23 May 2006) ViewCVS: http://svn.sourceforge.net/everydevel/?rev=883&view=rev Log Message: ----------- r17450@windwheel: chromatic | 2006-05-23 17:27:12 -0700 Added the first step to tests for Everything::NodeBase::Workspace. Modified Paths: -------------- trunk/ebase/MANIFEST trunk/ebase/lib/Everything/NodeBase/Workspace.pm Added Paths: ----------- trunk/ebase/lib/Everything/Test/NodeBase/ trunk/ebase/lib/Everything/Test/NodeBase/Workspace.pm trunk/ebase/t/NodeBase/Workspace.t Property Changed: ---------------- trunk/ebase/ Property changes on: trunk/ebase ___________________________________________________________________ Name: svk:merge - a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:17448 + a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:17450 Modified: trunk/ebase/MANIFEST =================================================================== --- trunk/ebase/MANIFEST 2006-05-24 00:17:08 UTC (rev 882) +++ trunk/ebase/MANIFEST 2006-05-24 00:27:31 UTC (rev 883) @@ -124,6 +124,7 @@ lib/Everything/NodeCache.pm lib/Everything/Security.pm lib/Everything/Test/NodeBase.pm +lib/Everything/Test/NodeBase/Workspace.pm lib/Everything/Util.pm lib/Everything/XML.pm Makefile.PL @@ -189,6 +190,7 @@ t/Node/workspace.t t/NodeBase.t t/NodeBase/mysql.t +t/NodeBase/Workspace.t t/NodeCache.t t/Security.t t/Util.t Modified: trunk/ebase/lib/Everything/NodeBase/Workspace.pm =================================================================== --- trunk/ebase/lib/Everything/NodeBase/Workspace.pm 2006-05-24 00:17:08 UTC (rev 882) +++ trunk/ebase/lib/Everything/NodeBase/Workspace.pm 2006-05-24 00:27:31 UTC (rev 883) @@ -156,12 +156,10 @@ sub getNode { my ( $this, $node, $ext, $ext2 ) = @_; - warn "<$node>\n"; return unless defined $node and $node ne ''; # it may already be a node return $node if eval { $node->isa( 'Everything::Node' ) }; - warn "Not a node\n"; my $cache = ""; Added: trunk/ebase/lib/Everything/Test/NodeBase/Workspace.pm =================================================================== --- trunk/ebase/lib/Everything/Test/NodeBase/Workspace.pm (rev 0) +++ trunk/ebase/lib/Everything/Test/NodeBase/Workspace.pm 2006-05-24 00:27:31 UTC (rev 883) @@ -0,0 +1,5 @@ +package Everything::Test::NodeBase::Workspace; + +use base 'Everything::Test::NodeBase'; + +1; Property changes on: trunk/ebase/lib/Everything/Test/NodeBase/Workspace.pm ___________________________________________________________________ Name: svn:mime-type + text/plain; charset=UTF-8 Name: svn:eol-style + native Added: trunk/ebase/t/NodeBase/Workspace.t =================================================================== --- trunk/ebase/t/NodeBase/Workspace.t (rev 0) +++ trunk/ebase/t/NodeBase/Workspace.t 2006-05-24 00:27:31 UTC (rev 883) @@ -0,0 +1,4 @@ +#! perl + +use Everything::Test::NodeBase::Workspace; +Everything::Test::NodeBase::Workspace->runtests(); Property changes on: trunk/ebase/t/NodeBase/Workspace.t ___________________________________________________________________ Name: svn:mime-type + text/plain; charset=UTF-8 Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-05-24 23:33:44
|
Revision: 884 Author: chromatic Date: 2006-05-24 16:32:30 -0700 (Wed, 24 May 2006) ViewCVS: http://svn.sourceforge.net/everydevel/?rev=884&view=rev Log Message: ----------- r17483@windwheel: chromatic | 2006-05-24 16:32:21 -0700 Finished tests for Everything::Node::Workspace. Modified Paths: -------------- trunk/ebase/lib/Everything/NodeBase/Workspace.pm trunk/ebase/lib/Everything/Test/NodeBase/Workspace.pm Property Changed: ---------------- trunk/ebase/ Property changes on: trunk/ebase ___________________________________________________________________ Name: svk:merge - a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:17450 + a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:17483 Modified: trunk/ebase/lib/Everything/NodeBase/Workspace.pm =================================================================== --- trunk/ebase/lib/Everything/NodeBase/Workspace.pm 2006-05-24 00:27:31 UTC (rev 883) +++ trunk/ebase/lib/Everything/NodeBase/Workspace.pm 2006-05-24 23:32:30 UTC (rev 884) @@ -13,8 +13,6 @@ use base 'Everything::NodeBase'; -use File::Spec; - =head2 C<joinWorkspace> create the $DB-E<gt>{workspace} object if a workspace is specified. If the @@ -33,9 +31,6 @@ sub joinWorkspace { my ( $this, $WORKSPACE ) = @_; - - delete $this->{workspace} if exists $this->{workspace}; - return 1 unless $WORKSPACE; $this->getRef($WORKSPACE); @@ -51,9 +46,9 @@ =head2 C<getNodeWorkspace> -Helper funciton for getNode's workspace functionality. Given a $WHERE hash ( -field =E<gt> value, or field =E<gt> [value1, value2, value3]) return a list of -nodes in the workspace which fullfill this query +Helper function for getNode's workspace functionality. Given a $WHERE hash +(field =E<gt> value, or field =E<gt> [value1, value2, value3]) return a list of +nodes in the workspace which fulfill this query. =over 4 @@ -75,7 +70,9 @@ my @results; $TYPE = $this->getType($TYPE) if $TYPE; - my $cmpval = sub { + # compare node ids + my $cmpval = sub + { my ( $val1, $val2 ) = @_; $val1 = $val1->{node_id} if eval { $val1->isa( 'Everything::Node' ) }; @@ -84,33 +81,36 @@ $val1 eq $val2; }; - #we need to iterate through our workspace - foreach my $node ( keys %{ $this->{workspace}{nodes} } ) + # iterate through the workspace + for my $node ( keys %{ $this->{workspace}{nodes} } ) { my $N = $this->getNode($node); - next if $TYPE and $$N{type}{node_id} != $$TYPE{node_id}; + next if $TYPE and $N->{type}{node_id} != $TYPE->{node_id}; my $match = 1; - foreach ( keys %$WHERE ) + + for my $where ( keys %$WHERE ) { - if ( ref $$WHERE{$_} eq 'ARRAY' ) + if ( ref $WHERE->{$where} eq 'ARRAY' ) { - my $matchor = 0; - foreach my $orval ( @{ $$WHERE{$_} } ) + $match = 0; + + for my $orval ( @{ $WHERE->{$where} } ) { - $matchor = 1 if $cmpval->( $$N{$_}, $orval ); + next unless $cmpval->( $N->{$where}, $orval ); + $match = 1; + last; } - $match = 0 unless $matchor; } else { - $match = 0 unless $cmpval->( $$N{$_}, $$WHERE{$_} ); + $match = 0 unless $cmpval->( $N->{$where}, $WHERE->{$where} ); } } push @results, $N if $match; } - \@results; + return \@results; } =head2 C<getNode> @@ -181,7 +181,7 @@ return unless @results; my $orderby = $ext2 || 'node_id'; - my $position = ( $orderby =~ /\s+desc/i ) ? -1 : 0; + my $position = ( $orderby =~ s/\s+desc//i ) ? -1 : 0; @results = sort { $a->{$orderby} cmp $b->{$orderby} } @results; return $results[$position]; } Modified: trunk/ebase/lib/Everything/Test/NodeBase/Workspace.pm =================================================================== --- trunk/ebase/lib/Everything/Test/NodeBase/Workspace.pm 2006-05-24 00:27:31 UTC (rev 883) +++ trunk/ebase/lib/Everything/Test/NodeBase/Workspace.pm 2006-05-24 23:32:30 UTC (rev 884) @@ -1,5 +1,145 @@ package Everything::Test::NodeBase::Workspace; +use strict; +use warnings; + use base 'Everything::Test::NodeBase'; +use SUPER; +use Test::More; + +sub test_join_workspace :Test( 7 ) +{ + my $self = shift; + my $nb = $self->{nb}; + my $storage = $self->{storage}; + + is( $nb->joinWorkspace(), 1, + 'joinWorkspace() should return 1 without workspace to join' ); + + $nb->mock( getRef => sub { $_[1] = 0 } ); + is( $nb->joinWorkspace( 'foo' ), -1, + '... or -1 unless workspace is a valid node' ); + + $nb->set_true( 'getRef' ); + $storage->set_series( getVars => 'vars' ); + + is( $nb->joinWorkspace( $storage ), 1, + '... or 1 if joining workspace works' ); + + is( $nb->{workspace}, $storage, '... setting workspace attribute' ); + is( $storage->{nodes}, 'vars', '... setting workspace nodes' ); + is_deeply( $storage->{cached_nodes}, {}, '... and cache' ); + + $nb->joinWorkspace( $storage ); + is_deeply( $storage->{nodes}, {}, + '... using default nodes unless present' ); +} + +sub test_get_node_workspace :Test( 5 ) +{ + my $self = shift; + my $nb = $self->{nb}; + my $storage = $self->{storage}; + + my $nodes = + { + 2 => { node_id => 2, title => 'foo', type => { node_id => 1 } }, + 3 => { node_id => 3, title => 'bar', type => { node_id => 1 } }, + 4 => { node_id => 4, title => 'baz', type => { node_id => 2 } }, + }; + + $nb->{workspace}{nodes} = $nodes; + $nb->mock( getType => sub { return { node_id => $_[1] } } ) + ->mock( getNode => sub { return $nodes->{$_[1]} } ); + + my $result = [ sort @{ $nb->getNodeWorkspace() } ]; + is_deeply( $result, [ map { $nodes->{$_} } 2 .. 4 ], + 'getNodeWorkspace() should return all nodes without criteria' ); + + $result = [ sort @{ $nb->getNodeWorkspace( {}, 1 ) } ]; + is_deeply( $result, [ map { $nodes->{$_} } 2, 3 ], + '... or only nodes of the specific type' ); + + $nodes->{5} = { node_id => 5, title => 'foo', type => { node_id => 2 } }; + $result = [ sort @{ $nb->getNodeWorkspace( { title => 'foo' } ) } ]; + is_deeply( $result, [ map { $nodes->{$_} } 2, 5 ], + '... or only nodes matching a single criterion' ); + + $result = [sort @{ $nb->getNodeWorkspace({ title => [qw( bar baz )]} )} ]; + is_deeply( $result, [ map { $nodes->{$_} } 3, 4 ], + '... or only nodes matching a multi-value criterion' ); + + $nodes->{6} = bless { node_id => 6, type => { node_id => 3 } }, + 'Everything::Node'; + $nb->mock( getNode => sub { { node => bless { + node_id => $_[1], type => { node_id => 3 } }, 'Everything::Node' + }}); + + my $selector = bless { node_id => 6 }, 'Everything::Node'; + + $result = [sort @{ $nb->getNodeWorkspace( { node => $selector } ) } ]; + is_deeply( $result, [ { node => $nodes->{6} } ], + '... or blessed nodes with matching node ids' ); +} + +sub test_get_node :Test( +5 ) +{ + my $self = shift; + my $nb = $self->{nb}; + my $storage = $self->{storage}; + + $self->SUPER(); + + $nb->set_false( 'SUPER' ); + is( $nb->getNode( 100 ), undef, + 'getNode() should return false unless SUPER() call returns a node' ); + + $nb->set_always( SUPER => $storage ); + $storage->{node_id} = 100; + $storage->set_series( getWorkspaced => 0, 'workspaced' ); + is( $nb->getNode( 102 ), $storage, + '... and should return non-workspaced node, if not in workspace' ); + + $nb->{workspace}{nodes}{100} = 0; + is( $nb->getNode( 102 ), $storage, + '... or if workspaced node has no value' ); + + $nb->{workspace}{nodes}{100} = 1; + is( $nb->getNode( 102 ), $storage, + '... even when fetched from workspace' ); + + is( $nb->getNode( 102 ), 'workspaced', + '... but should return it if it does exist' ); +} + +sub test_get_node_with_where :Test( 4 ) +{ + my $self = shift; + my $nb = $self->{nb}; + my $storage = $self->{storage}; + + $nb->{workspace}{nodes} = { map { $_ => { node_id => $_, w => $_ } } 1..3 }; + + $nb->set_series( getNodeWhere => 0, + [ map { { node_id => $_, w => $_ } } 1 .. 3 ] ) + ->set_always( getNodeWorkspace => [] ); + + my $result = $nb->getNode( { node_id => 10 } ); + + is( $result, undef, + 'getNode() with where should return nothing with no node to find' ); + + is( $nb->getNode( { node_id => 10 } ), undef, + '... or nothing with no nodes in workspace' ); + + $nb->set_always( getNodeWorkspace => [values %{ $nb->{workspace}{nodes} }]); + is_deeply( $nb->getNode( { node_id => 11 } ), { node_id => 1, w => 1 }, + '... or the workspaced node, if there is a match' ); + + is_deeply( $nb->getNode( { node_id => 11 }, '', 'w desc' ), + { node_id => 3, w => 3 }, + '... ordered by secondary field, if provided' ); +} + 1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-05-25 22:42:12
|
Revision: 885 Author: chromatic Date: 2006-05-25 15:42:03 -0700 (Thu, 25 May 2006) ViewCVS: http://svn.sourceforge.net/everydevel/?rev=885&view=rev Log Message: ----------- r17512@windwheel: chromatic | 2006-05-25 15:41:49 -0700 Changed block comments to real POD. (File still needs more documentation.) Modified Paths: -------------- trunk/ebase/lib/Everything/DB/mysql.pm Property Changed: ---------------- trunk/ebase/ Property changes on: trunk/ebase ___________________________________________________________________ Name: svk:merge - a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:17483 + a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:17512 Modified: trunk/ebase/lib/Everything/DB/mysql.pm =================================================================== --- trunk/ebase/lib/Everything/DB/mysql.pm 2006-05-24 23:32:30 UTC (rev 884) +++ trunk/ebase/lib/Everything/DB/mysql.pm 2006-05-25 22:42:03 UTC (rev 885) @@ -1,33 +1,47 @@ +=head1 Everything::DB::mysql + +MySQL database support. + +Copyright 2002 - 2003, 2006 Everything Development Inc. + +=cut + package Everything::DB::mysql; -############################################################################# -# Everything::DB::mysql -# MySQL database support. -# -# Copyright 2002 - 2003, 2006 Everything Development Inc. -# Format: tabs = 4 spaces -# -############################################################################# - use strict; use warnings; use DBI; use base 'Everything::DB'; -############################################################################# -# Sub -# databaseConnect -# -# Purpose -# Connect to the database. -# -# Parameters -# dbname - the database name -# host - the hostname of the database server -# user - the username to use to connect -# pass - the password to use to connect -# +=head2 C<databaseConnect> + +Connect to the database. + +=over 4 + +=item * dbname + +the database name + +=item * $host + +the hostname of the database server + +=item * $user + +the username to use to connect + +=item * $pass + +the password to use to connect + +=back + +This will throw an exception if the connection fails. + +=cut + sub databaseConnect { my ( $this, $dbname, $host, $user, $pass ) = @_; @@ -36,22 +50,25 @@ or die "Unable to get database connection!"; } -############################################################################# -# Sub -# lastValue -# -# Purpose -# Return the last sequence/auto_increment value inserted into the -# database. -# -# Parameters -# table - the table (this MUST be the table used in the last query) -# field - the auto_increment field -# -# Returns -# The last sequence/auto_increment value inserted into the database by -# this process/connection. undef if error. -# +=head2 C<lastValue> + +Returns the last sequence/auto_increment value inserted into the +database. This will return undef on error. + +=over 4 + +=item * $table + +the table (this MUST be the table used in the last query) + +=item * $field + +the auto_increment field + +=back + +=cut + sub lastValue { my ( $this, $table, $field ) = @_; @@ -59,22 +76,26 @@ return $this->sqlSelect("LAST_INSERT_ID()"); } -############################################################################# -# Sub -# getFieldsHash -# -# Purpose -# Given a table name, returns a list of the fields or a hash. -# -# Parameters -# $table - the name of the table to get fields for -# $getHash - set to 1 if you would also like the entire field hash -# instead of just the field name. (set to 1 by default) -# -# Returns -# Array of field names, if getHash is 1, it will be an array of -# hashrefs of the fields. -# +=head2 C<getFieldsHash> + +Given a table name, returns the names of fields. If C<$getHash> is true, it +will be an array of hashrefs of the fields. + +=over 4 + +=item * $table + +the name of the table to get fields for + +=item * $getHash + +Set to 1 if you would also like the entire field hash instead of just the field +name. (By default, true.) + +=back + +=cut + sub getFieldsHash { my ( $this, $table, $getHash ) = @_; @@ -99,19 +120,21 @@ return map { $$_{Field} } @{ $$DBTABLE{Fields} }; } -############################################################################# -# Sub -# tableExists -# -# Purpose -# Check to see if a table of the given name exists in this database. -# -# Parameters -# $tableName - the table to check for. -# -# Returns -# 1 if it exists, 0 if not. -# +=head2 C<tableExists> + +Check to see if a table of the given name exists in this database. Returns 1 +if it exists, 0 if not. + +=over 4 + +=item * $tableName + +The table to check. + +=back + +=cut + sub tableExists { my ( $this, $tableName ) = @_; @@ -130,21 +153,24 @@ return 0; } -############################################################################# -# Sub -# createNodeTable -# -# Purpose -# Create a new database table for a node, if it does not already exist. -# This creates a new table with one field for the id of the node in the -# form of tablename_id. -# -# Parameters -# $tableName - the name of the table to create -# -# Returns -# 1 if successful, 0 if failure, -1 if it already exists. -# +=head2 C<createNodeTable> + +Create a new database table for a node, if it does not already exist. This +creates a new table with one field for the id of the node in the form of +tablename_id. + +Returns 1 if successful, 0 if failure, -1 if table already exists. + +=over 4 + +=item * $tableName + +the name of the table to create + +=back + +=cut + sub createNodeTable { my ( $this, $table ) = @_; @@ -157,16 +183,21 @@ . "PRIMARY KEY($tableid))" ); } -############################################################################# -# Sub -# createGroupTable -# -# Purpose -# Creates a new group table if it does not already exist. -# -# Returns -# 1 if successful, 0 if failure, -1 if it already exists. -# +=head2 C<createGroupTable> + +Creates a new group table if it does not already exist. Returns 1 if +successful, 0 if failure, or -1 if table already exists. + +=over 4 + +=item * $tableName + +the name of the table to create + +=back + +=cut + sub createGroupTable { my ( $this, $table ) = @_; @@ -189,20 +220,24 @@ return $dbh->do($sql); } -############################################################################# -# Sub -# dropFieldFromTable -# -# Purpose -# Remove a field from the given table. -# -# Parameters -# $table - the table to remove the field from -# $field - the field to drop -# -# Returns -# 1 if successful, 0 if failure -# +=head2 C<dropFieldFromTable> + +Removes a field from the given table. Returns 1 if successful, 0 on failure. + +=over 4 + +=item * $table + +the table to remove the field from + +=item * $field + +the field to drop + +=back + +=cut + sub dropFieldFromTable { my ( $this, $table, $field ) = @_; @@ -210,23 +245,37 @@ return $this->{dbh}->do("alter table $table drop $field"); } -############################################################################# -# Sub -# addFieldToTable -# -# Purpose -# Add a new field to an existing database table. -# -# Parameters -# $table - the table to add the new field to. -# $fieldname - the name of the field to add -# $type - the type of the field (ie int(11), char(32), etc) -# $primary - (optional) is this field a primary key? Defaults to no. -# $default - (optional) the default value of the field. -# -# Returns -# 1 if successful, 0 if failure. -# +=head2 C<addFieldToTable> + +Adds a new field to an existing database table. Returns 1 if successful, 0 on +failure. + +=over 4 + +=item * $table + +the table to add the new field to. + +=item * $fieldname + +the name of the field to add + +=item * $type + +the type of the field (ie int(11), char(32), etc) + +=item * $primary + +(optional) is this field a primary key? Defaults to no. + +=item * $default + +(optional) the default value of the field. + +=back + +=cut + sub addFieldToTable { my ( $this, $table, $fieldname, $type, $primary, $default ) = @_; @@ -273,56 +322,41 @@ return 1; } -############################################################################# -# Sub -# startTransaction -# -# Purpose -# Start a database transaction. -# -# Parameters -# None. -# -# Returns -# 0 if a transaction is already in progress, 1 otherwise. -# +=head2 C<startTransaction> + +Starts a database transaction. + +Returns 0 if a transaction is already in progress, 1 otherwise. + +=cut + sub startTransaction { return 1; } -############################################################################# -# Sub -# commitTransaction -# -# Purpose -# Commit a database transaction. -# -# Parameters -# None. -# -# Returns -# 1 if a transaction isn't already in progress, 0 otherwise. -# +=head2 commitTransaction + +Commits a database transaction. + +Returns 1 if a transaction isn't already in progress, 0 otherwise. + +=cut + sub commitTransaction { return 1; } -############################################################################# -# Sub -# rollbackTransaction -# -# Purpose -# Rollback a database transaction. This isn't guaranteed to work, -# due to lack of implementation in certain DBMs. Don't depend on it. -# -# Parameters -# None. -# -# Returns -# 1 if a transaction isn't already in progress, 0 otherwise. -# +=head2 C<rollbackTransaction> + +Rolls back a database transaction. This isn't guaranteed to work, +due to lack of implementation in certain DBMs. Don't depend on it. + +Returns 1 if a transaction isn't already in progress, 0 otherwise. + +=cut + sub rollbackTransaction { return 1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-05-25 22:47:37
|
Revision: 886 Author: chromatic Date: 2006-05-25 15:47:28 -0700 (Thu, 25 May 2006) ViewCVS: http://svn.sourceforge.net/everydevel/?rev=886&view=rev Log Message: ----------- r17514@windwheel: chromatic | 2006-05-25 15:47:15 -0700 Moved Everything::DB::mysql test to the right place. Modified Paths: -------------- trunk/ebase/MANIFEST Added Paths: ----------- trunk/ebase/t/DB/ trunk/ebase/t/DB/mysql.t Removed Paths: ------------- trunk/ebase/t/NodeBase/mysql.t Property Changed: ---------------- trunk/ebase/ Property changes on: trunk/ebase ___________________________________________________________________ Name: svk:merge - a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:17512 + a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:17514 Modified: trunk/ebase/MANIFEST =================================================================== --- trunk/ebase/MANIFEST 2006-05-25 22:42:03 UTC (rev 885) +++ trunk/ebase/MANIFEST 2006-05-25 22:47:28 UTC (rev 886) @@ -135,6 +135,7 @@ REDHAT_SETUP scripts/removePod t/CacheQueue.t +t/DB/mysql.t t/Everything.t t/Everything/Auth.t t/Everything/Mail.t @@ -189,7 +190,6 @@ t/Node/usergroup.t t/Node/workspace.t t/NodeBase.t -t/NodeBase/mysql.t t/NodeBase/Workspace.t t/NodeCache.t t/Security.t Added: trunk/ebase/t/DB/mysql.t =================================================================== --- trunk/ebase/t/DB/mysql.t (rev 0) +++ trunk/ebase/t/DB/mysql.t 2006-05-25 22:47:28 UTC (rev 886) @@ -0,0 +1,244 @@ +#! perl + +use strict; +use warnings; + +use Test::More tests => 79; +use Test::Exception; +use Test::MockObject; + +# temporarily avoid sub redefined warnings +my $mock = Test::MockObject->new(); +$mock->fake_module('Everything'); +$mock->fake_module('DBI'); + +my $package = 'Everything::DB::mysql'; + +use_ok($package) or exit; + +can_ok( $package, 'databaseConnect' ); +my $fake = {}; +my @args = ( 0, 'new dbh' ); +my @dconn; +$mock->fake_module( 'DBI', connect => sub { push @dconn, [@_]; shift @args } ); +throws_ok { Everything::DB::mysql::databaseConnect( $fake, 1, 2, 3, 4 ) } + qr/^Unable to get database connection!/, + 'databaseConnect() should fail if db connection fails'; +lives_ok { Everything::DB::mysql::databaseConnect( $fake, 1, 2, 3, 4 ) } + '... but not if connection succeeds'; +is( @dconn, 2, '... calling DBI->connect' ); +is( + join( '-', @{ $dconn[1] } ), + 'DBI-DBI:mysql:1:2-3-4', + '... passing args correctly' +); +is( $fake->{dbh}, 'new dbh', '... setting dbh field if connection succeeds' ); + +can_ok( $package, 'lastValue' ); +$mock->set_always( 'sqlSelect', 'insert id' ); +my $result = Everything::DB::mysql::lastValue($mock); +my ( $method, $args ) = $mock->next_call(); +is( $method, 'sqlSelect', 'lastValue() should fetch from the database' ); +is( $args->[1], 'LAST_INSERT_ID()', '... the last inserted id' ); +is( $result, 'insert id', '... returning the results' ); + +my $fields = [ { Field => 'foo', foo => 1 }, { Field => 'bar', bar => 2 } ]; + +can_ok( $package, 'getFieldsHash' ); +$mock->{dbh} = $mock; +$mock->set_always( 'getNode', $mock )->set_always( 'prepare_cached', $mock ) + ->set_true('execute')->set_series( 'fetchrow_hashref', @$fields ); + +my @result = Everything::DB::mysql::getFieldsHash( $mock, 'table' ); +( $method, $args ) = $mock->next_call(); +is( $method, 'getNode', 'getFieldsHash() should fetch node' ); +is( join( '-', @$args[ 1, 2 ] ), + 'table-dbtable', '... by name, of dbtable type' ); +( $method, $args ) = $mock->next_call(); +is( $method, 'prepare_cached', '... displaying the table columns' ); +is( $args->[1], 'show columns from table', '... for the appropriate table' ); +is_deeply( $mock->{Fields}, $fields, '... caching the results' ); +is_deeply( \@result, $fields, '... defaulting to return complete hashrefs' ); + +$mock->clear(); +@result = Everything::DB::mysql::getFieldsHash( $mock, '', 0 ); +is( $mock->call_pos(-1), 'getNode', + 'getFieldsHash() should respect fields cached in node' ); +( $method, $args ) = $mock->next_call(); +is( $args->[1], 'node', '... using the node table by default' ); +is_deeply( + \@result, + [ 'foo', 'bar' ], + '... returning only fields if getHash is false' +); + +can_ok( $package, 'tableExists' ); +$mock->set_always( prepare => $mock )->set_true('execute') + ->set_series( 'fetchrow', 1, 2, 'target' )->set_true('finish'); + +$result = Everything::DB::mysql::tableExists( $mock, 'target' ); +( $method, $args ) = $mock->next_call(); +is( $method, 'prepare', 'tableExists should check with the database' ); +is( $args->[1], 'show tables', '... fetching available table names' ); +ok( $result, '... returning true if table exists' ); +is( $mock->call_pos(-1), 'finish', '... and closing the cursor' ); + +$mock->mock( 'fetchrow', sub { } ); +ok( + !Everything::DB::mysql::tableExists( $mock, 'target' ), + '... returning false if table name is not found' +); + +can_ok( $package, 'createNodeTable' ); +$mock->clear(); +$mock->set_series( 'tableExists', 1, 0 )->set_always( 'do', 'done' ); + +$result = Everything::DB::mysql::createNodeTable( $mock, 'elbat' ); +( $method, $args ) = $mock->next_call(); +is( $method, 'tableExists', 'createNodeTable() should check if table exists' ); +is( $args->[1], 'elbat', '... by name' ); +is( $result, -1, '... returning -1 if so' ); + +$result = Everything::DB::mysql::createNodeTable( $mock, 'elbat' ); +( $method, $args ) = $mock->next_call(2); +is( $method, 'do', '... performing a SQL create otherwise' ); +like( $args->[1], qr/create table elbat/, '.. of the right name' ); +like( $args->[1], qr/\(elbat_id int4/, '... with an id column' ); +like( $args->[1], qr/.+KEY\(elbat_id\)/, '... as the primary key' ); +is( $result, 'done', '... returning the results' ); + +can_ok( $package, 'createGroupTable' ); +$mock->clear(); +$mock->set_series( 'tableExists', 1, 0 )->set_always( 'do', 'done' ) + ->set_always( 'getDatabaseHandle', $mock ); + +$result = Everything::DB::mysql::createGroupTable( $mock, 'elbat' ); +( $method, $args ) = $mock->next_call(); +is( $method, 'tableExists', 'createGroupTable() should check if table exists' ); +is( $args->[1], 'elbat', '... by name' ); +is( $result, -1, '... returning -1 if so' ); + +$result = Everything::DB::mysql::createGroupTable( $mock, 'elbat' ); +( $method, $args ) = $mock->next_call(3); +is( $method, 'do', '... performing a SQL create otherwise' ); +like( $args->[1], qr/create table elbat/, '.. of the right name' ); +like( $args->[1], qr/elbat_id int4/, '... with an id column' ); +like( + $args->[1], + qr/rank .+node_id .+orderby/s, + '... rank, node_id, and orderby columns' +); +like( $args->[1], qr/.+KEY\(elbat_id,rank\)/, '... as the primary key' ); +is( $result, 'done', '... returning the results' ); + +can_ok( $package, 'dropFieldFromTable' ); +$mock->clear(); +$result = Everything::DB::mysql::dropFieldFromTable( $mock, 't', 'f' ); +( $method, $args ) = $mock->next_call(); +is( $method, 'do', 'dropFieldFromTable() should do a SQL statement' ); +is( + $args->[1], + 'alter table t drop f', + '... altering the table, dropping the column' +); +is( $result, 'done', '... returning the results' ); + +can_ok( $package, 'addFieldToTable' ); +ok( + !Everything::DB::mysql::addFieldToTable( $mock, '' ), + 'addFieldToTable() should return false if table is blank' +); +ok( !Everything::DB::mysql::addFieldToTable( $mock, 't', '' ), + '... or if fieldname is blank' ); +ok( !Everything::DB::mysql::addFieldToTable( $mock, 't', 'f', '' ), + '... or if type is blank' ); + +$mock->clear(); +Everything::DB::mysql::addFieldToTable( $mock, 't', 'f', 'text', 0 ); +( $method, $args ) = $mock->next_call(); +is( $method, 'do', 'addFieldToTable() should execute SQL statement' ); +like( + $args->[1], + qr/^alter table t add f text/, + '... altering proper table to add proper field and type' +); +like( + $args->[1], + qr/default "" not null/, + '... with a blank default for text fields' +); +Everything::DB::mysql::addFieldToTable( $mock, 't', 'f', 'int', 0 ); +( $method, $args ) = $mock->next_call(); +like( + $args->[1], + qr/default "0" not null/, + '... a zero default for int fields' +); +Everything::DB::mysql::addFieldToTable( $mock, 't', 'f', 'something else', + 0 ); +( $method, $args ) = $mock->next_call(); +like( + $args->[1], + qr/default "" not null/, + '... a blank default for all other fields' +); +Everything::DB::mysql::addFieldToTable( $mock, 't', 'f', 'something else', + 0, 'default' ); +( $method, $args ) = $mock->next_call(); +like( + $args->[1], + qr/default "default" not null/, + '... and the given default, if given' +); + +$mock->mock( 'getFieldsHash', sub { } )->clear(); +Everything::DB::mysql::addFieldToTable( $mock, 't', 'f', 'something else', + 1, 'default' ); +( $method, $args ) = $mock->next_call(2); +is( $method, 'getFieldsHash', '... getting node fields if adding primary key' ); +is( $args->[1], 't', '... for table' ); +( $method, $args ) = $mock->next_call(); +is( $method, 'do', '... altering the table' ); +is( + $args->[1], + 'alter table t add primary key(f)', + '... adding a key for the field' +); + +$mock->mock( + 'getFieldsHash', + sub { + { Field => 'foo', Key => 'PRI' }, { Field => 'bar', Key => '' }, + { Field => 'baz', Key => 'PRI' }; + } +)->clear(); +$result = + Everything::DB::mysql::addFieldToTable( $mock, 't', 'f', + 'something else', + 1, 'default' ); +( $method, $args ) = $mock->next_call(3); +is( $method, 'do', '... dropping an existing primary key' ); +is( $args->[1], 'alter table t drop primary key', '... if it exists' ); +( $method, $args ) = $mock->next_call(); +is( + $args->[1], + 'alter table t add primary key(foo,baz,f)', + '... adding existing fields and new field as primary key' +); +ok( $result, '... returning true' ); + +foreach my $meth (qw(startTransaction commitTransaction rollbackTransaction)) +{ + can_ok( $package, $meth ); + ok( $package->$meth(), "$method() should return true" ); +} + +can_ok( $package, 'genLimitString' ); +is( $package->genLimitString( 10, 20 ), + 'LIMIT 10, 20', 'genLimitString() should return a valid limit' ); +is( $package->genLimitString( undef, 20 ), + 'LIMIT 0, 20', '... defaulting to an offset of zero' ); + +can_ok( $package, 'genTableName' ); +is( $package->genTableName('foo'), + 'foo', 'genTableName() should return first arg' ); Property changes on: trunk/ebase/t/DB/mysql.t ___________________________________________________________________ Name: svn:mime-type + text/plain; charset=UTF-8 Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Deleted: trunk/ebase/t/NodeBase/mysql.t =================================================================== --- trunk/ebase/t/NodeBase/mysql.t 2006-05-25 22:42:03 UTC (rev 885) +++ trunk/ebase/t/NodeBase/mysql.t 2006-05-25 22:47:28 UTC (rev 886) @@ -1,249 +0,0 @@ -#!/usr/bin/perl -w - -use strict; - -BEGIN -{ - chdir 't' if -d 't'; - unshift @INC, '../blib/lib', 'lib/', '..'; -} - -use Test::More tests => 79; -use Test::Exception; -use Test::MockObject; - -# temporarily avoid sub redefined warnings -my $mock = Test::MockObject->new(); -$mock->fake_module('Everything'); -$mock->fake_module('DBI'); - -my $package = 'Everything::NodeBase::mysql'; - -use_ok($package); - -can_ok( $package, 'databaseConnect' ); -my $fake = {}; -my @args = ( 0, 'new dbh' ); -my @dconn; -$mock->fake_module( 'DBI', connect => sub { push @dconn, [@_]; shift @args } ); -throws_ok { Everything::NodeBase::mysql::databaseConnect( $fake, 1, 2, 3, 4 ) } - qr/^Unable to get database connection!/, - 'databaseConnect() should fail if db connection fails'; -lives_ok { Everything::NodeBase::mysql::databaseConnect( $fake, 1, 2, 3, 4 ) } - '... but not if connection succeeds'; -is( @dconn, 2, '... calling DBI->connect' ); -is( - join( '-', @{ $dconn[1] } ), - 'DBI-DBI:mysql:1:2-3-4', - '... passing args correctly' -); -is( $fake->{dbh}, 'new dbh', '... setting dbh field if connection succeeds' ); - -can_ok( $package, 'lastValue' ); -$mock->set_always( 'sqlSelect', 'insert id' ); -my $result = Everything::NodeBase::mysql::lastValue($mock); -my ( $method, $args ) = $mock->next_call(); -is( $method, 'sqlSelect', 'lastValue() should fetch from the database' ); -is( $args->[1], 'LAST_INSERT_ID()', '... the last inserted id' ); -is( $result, 'insert id', '... returning the results' ); - -my $fields = [ { Field => 'foo', foo => 1 }, { Field => 'bar', bar => 2 } ]; - -can_ok( $package, 'getFieldsHash' ); -$mock->{dbh} = $mock; -$mock->set_always( 'getNode', $mock )->set_always( 'prepare_cached', $mock ) - ->set_true('execute')->set_series( 'fetchrow_hashref', @$fields ); - -my @result = Everything::NodeBase::mysql::getFieldsHash( $mock, 'table' ); -( $method, $args ) = $mock->next_call(); -is( $method, 'getNode', 'getFieldsHash() should fetch node' ); -is( join( '-', @$args[ 1, 2 ] ), - 'table-dbtable', '... by name, of dbtable type' ); -( $method, $args ) = $mock->next_call(); -is( $method, 'prepare_cached', '... displaying the table columns' ); -is( $args->[1], 'show columns from table', '... for the appropriate table' ); -is_deeply( $mock->{Fields}, $fields, '... caching the results' ); -is_deeply( \@result, $fields, '... defaulting to return complete hashrefs' ); - -$mock->clear(); -@result = Everything::NodeBase::mysql::getFieldsHash( $mock, '', 0 ); -is( $mock->call_pos(-1), 'getNode', - 'getFieldsHash() should respect fields cached in node' ); -( $method, $args ) = $mock->next_call(); -is( $args->[1], 'node', '... using the node table by default' ); -is_deeply( - \@result, - [ 'foo', 'bar' ], - '... returning only fields if getHash is false' -); - -can_ok( $package, 'tableExists' ); -$mock->set_always( prepare => $mock )->set_true('execute') - ->set_series( 'fetchrow', 1, 2, 'target' )->set_true('finish'); - -$result = Everything::NodeBase::mysql::tableExists( $mock, 'target' ); -( $method, $args ) = $mock->next_call(); -is( $method, 'prepare', 'tableExists should check with the database' ); -is( $args->[1], 'show tables', '... fetching available table names' ); -ok( $result, '... returning true if table exists' ); -is( $mock->call_pos(-1), 'finish', '... and closing the cursor' ); - -$mock->mock( 'fetchrow', sub { } ); -ok( - !Everything::NodeBase::mysql::tableExists( $mock, 'target' ), - '... returning false if table name is not found' -); - -can_ok( $package, 'createNodeTable' ); -$mock->clear(); -$mock->set_series( 'tableExists', 1, 0 )->set_always( 'do', 'done' ); - -$result = Everything::NodeBase::mysql::createNodeTable( $mock, 'elbat' ); -( $method, $args ) = $mock->next_call(); -is( $method, 'tableExists', 'createNodeTable() should check if table exists' ); -is( $args->[1], 'elbat', '... by name' ); -is( $result, -1, '... returning -1 if so' ); - -$result = Everything::NodeBase::mysql::createNodeTable( $mock, 'elbat' ); -( $method, $args ) = $mock->next_call(2); -is( $method, 'do', '... performing a SQL create otherwise' ); -like( $args->[1], qr/create table elbat/, '.. of the right name' ); -like( $args->[1], qr/\(elbat_id int4/, '... with an id column' ); -like( $args->[1], qr/.+KEY\(elbat_id\)/, '... as the primary key' ); -is( $result, 'done', '... returning the results' ); - -can_ok( $package, 'createGroupTable' ); -$mock->clear(); -$mock->set_series( 'tableExists', 1, 0 )->set_always( 'do', 'done' ) - ->set_always( 'getDatabaseHandle', $mock ); - -$result = Everything::NodeBase::mysql::createGroupTable( $mock, 'elbat' ); -( $method, $args ) = $mock->next_call(); -is( $method, 'tableExists', 'createGroupTable() should check if table exists' ); -is( $args->[1], 'elbat', '... by name' ); -is( $result, -1, '... returning -1 if so' ); - -$result = Everything::NodeBase::mysql::createGroupTable( $mock, 'elbat' ); -( $method, $args ) = $mock->next_call(3); -is( $method, 'do', '... performing a SQL create otherwise' ); -like( $args->[1], qr/create table elbat/, '.. of the right name' ); -like( $args->[1], qr/elbat_id int4/, '... with an id column' ); -like( - $args->[1], - qr/rank .+node_id .+orderby/s, - '... rank, node_id, and orderby columns' -); -like( $args->[1], qr/.+KEY\(elbat_id,rank\)/, '... as the primary key' ); -is( $result, 'done', '... returning the results' ); - -can_ok( $package, 'dropFieldFromTable' ); -$mock->clear(); -$result = Everything::NodeBase::mysql::dropFieldFromTable( $mock, 't', 'f' ); -( $method, $args ) = $mock->next_call(); -is( $method, 'do', 'dropFieldFromTable() should do a SQL statement' ); -is( - $args->[1], - 'alter table t drop f', - '... altering the table, dropping the column' -); -is( $result, 'done', '... returning the results' ); - -can_ok( $package, 'addFieldToTable' ); -ok( - !Everything::NodeBase::mysql::addFieldToTable( $mock, '' ), - 'addFieldToTable() should return false if table is blank' -); -ok( !Everything::NodeBase::mysql::addFieldToTable( $mock, 't', '' ), - '... or if fieldname is blank' ); -ok( !Everything::NodeBase::mysql::addFieldToTable( $mock, 't', 'f', '' ), - '... or if type is blank' ); - -$mock->clear(); -Everything::NodeBase::mysql::addFieldToTable( $mock, 't', 'f', 'text', 0 ); -( $method, $args ) = $mock->next_call(); -is( $method, 'do', 'addFieldToTable() should execute SQL statement' ); -like( - $args->[1], - qr/^alter table t add f text/, - '... altering proper table to add proper field and type' -); -like( - $args->[1], - qr/default "" not null/, - '... with a blank default for text fields' -); -Everything::NodeBase::mysql::addFieldToTable( $mock, 't', 'f', 'int', 0 ); -( $method, $args ) = $mock->next_call(); -like( - $args->[1], - qr/default "0" not null/, - '... a zero default for int fields' -); -Everything::NodeBase::mysql::addFieldToTable( $mock, 't', 'f', 'something else', - 0 ); -( $method, $args ) = $mock->next_call(); -like( - $args->[1], - qr/default "" not null/, - '... a blank default for all other fields' -); -Everything::NodeBase::mysql::addFieldToTable( $mock, 't', 'f', 'something else', - 0, 'default' ); -( $method, $args ) = $mock->next_call(); -like( - $args->[1], - qr/default "default" not null/, - '... and the given default, if given' -); - -$mock->mock( 'getFieldsHash', sub { } )->clear(); -Everything::NodeBase::mysql::addFieldToTable( $mock, 't', 'f', 'something else', - 1, 'default' ); -( $method, $args ) = $mock->next_call(2); -is( $method, 'getFieldsHash', '... getting node fields if adding primary key' ); -is( $args->[1], 't', '... for table' ); -( $method, $args ) = $mock->next_call(); -is( $method, 'do', '... altering the table' ); -is( - $args->[1], - 'alter table t add primary key(f)', - '... adding a key for the field' -); - -$mock->mock( - 'getFieldsHash', - sub { - { Field => 'foo', Key => 'PRI' }, { Field => 'bar', Key => '' }, - { Field => 'baz', Key => 'PRI' }; - } -)->clear(); -$result = - Everything::NodeBase::mysql::addFieldToTable( $mock, 't', 'f', - 'something else', - 1, 'default' ); -( $method, $args ) = $mock->next_call(3); -is( $method, 'do', '... dropping an existing primary key' ); -is( $args->[1], 'alter table t drop primary key', '... if it exists' ); -( $method, $args ) = $mock->next_call(); -is( - $args->[1], - 'alter table t add primary key(foo,baz,f)', - '... adding existing fields and new field as primary key' -); -ok( $result, '... returning true' ); - -foreach my $meth (qw(startTransaction commitTransaction rollbackTransaction)) -{ - can_ok( $package, $meth ); - ok( $package->$meth(), "$method() should return true" ); -} - -can_ok( $package, 'genLimitString' ); -is( $package->genLimitString( 10, 20 ), - 'LIMIT 10, 20', 'genLimitString() should return a valid limit' ); -is( $package->genLimitString( undef, 20 ), - 'LIMIT 0, 20', '... defaulting to an offset of zero' ); - -can_ok( $package, 'genTableName' ); -is( $package->genTableName('foo'), - 'foo', 'genTableName() should return first arg' ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-05-25 23:39:36
|
Revision: 887 Author: chromatic Date: 2006-05-25 16:39:26 -0700 (Thu, 25 May 2006) ViewCVS: http://svn.sourceforge.net/everydevel/?rev=887&view=rev Log Message: ----------- r17516@windwheel: chromatic | 2006-05-25 16:38:52 -0700 Moved C<lastValue()> method up into Everything::DB. Modified Paths: -------------- trunk/ebase/lib/Everything/DB/Pg.pm trunk/ebase/lib/Everything/DB/mysql.pm trunk/ebase/lib/Everything/DB.pm trunk/ebase/t/DB/mysql.t Property Changed: ---------------- trunk/ebase/ Property changes on: trunk/ebase ___________________________________________________________________ Name: svk:merge - a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:17514 + a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:17516 Modified: trunk/ebase/lib/Everything/DB/Pg.pm =================================================================== --- trunk/ebase/lib/Everything/DB/Pg.pm 2006-05-25 22:47:28 UTC (rev 886) +++ trunk/ebase/lib/Everything/DB/Pg.pm 2006-05-25 23:39:26 UTC (rev 887) @@ -39,31 +39,6 @@ } ############################################################################# -# Sub -# lastValue -# -# Purpose -# Return the last sequence/auto_increment value inserted into -# the database. -# -# Parameters -# table - the table (this MUST be the table used in the last query) -# field - the auto_increment field -# -# Returns -# The last sequence/auto_increment value inserted into the -# database by this process/connection. undef if error. -# -sub lastValue -{ - my ( $this, $table, $field ) = @_; - - return $this->{dbh} - ->do( "SELECT currval(\'$table" . "_" . $field . "_seq\')" ) - ->fetchrow(); -} - -############################################################################# # Sub # getFieldsHash # Modified: trunk/ebase/lib/Everything/DB/mysql.pm =================================================================== --- trunk/ebase/lib/Everything/DB/mysql.pm 2006-05-25 22:47:28 UTC (rev 886) +++ trunk/ebase/lib/Everything/DB/mysql.pm 2006-05-25 23:39:26 UTC (rev 887) @@ -50,32 +50,6 @@ or die "Unable to get database connection!"; } -=head2 C<lastValue> - -Returns the last sequence/auto_increment value inserted into the -database. This will return undef on error. - -=over 4 - -=item * $table - -the table (this MUST be the table used in the last query) - -=item * $field - -the auto_increment field - -=back - -=cut - -sub lastValue -{ - my ( $this, $table, $field ) = @_; - - return $this->sqlSelect("LAST_INSERT_ID()"); -} - =head2 C<getFieldsHash> Given a table name, returns the names of fields. If C<$getHash> is true, it Modified: trunk/ebase/lib/Everything/DB.pm =================================================================== --- trunk/ebase/lib/Everything/DB.pm 2006-05-25 22:47:28 UTC (rev 886) +++ trunk/ebase/lib/Everything/DB.pm 2006-05-25 23:39:26 UTC (rev 887) @@ -66,6 +66,32 @@ return $this->{dbh}; } +=head2 C<lastValue> + +Returns the last sequence/auto_increment value inserted into the +database. This will return undef on error. + +=over 4 + +=item * $table + +the table (this MUST be the table used in the last query) + +=item * $field + +the auto_increment field + +=back + +=cut + +sub lastValue +{ + my ( $this, $table, $field ) = @_; + + return $this->getDatabaseHandle()->last_insert_id(); +} + =head2 C<sqlDelete> Quickie wrapper for deleting a row or rows from a specified table. Modified: trunk/ebase/t/DB/mysql.t =================================================================== --- trunk/ebase/t/DB/mysql.t 2006-05-25 22:47:28 UTC (rev 886) +++ trunk/ebase/t/DB/mysql.t 2006-05-25 23:39:26 UTC (rev 887) @@ -3,9 +3,10 @@ use strict; use warnings; -use Test::More tests => 79; +use Test::More tests => 77; use Test::Exception; use Test::MockObject; +use Test::MockObject::Extends; # temporarily avoid sub redefined warnings my $mock = Test::MockObject->new(); @@ -35,13 +36,15 @@ is( $fake->{dbh}, 'new dbh', '... setting dbh field if connection succeeds' ); can_ok( $package, 'lastValue' ); -$mock->set_always( 'sqlSelect', 'insert id' ); -my $result = Everything::DB::mysql::lastValue($mock); -my ( $method, $args ) = $mock->next_call(); -is( $method, 'sqlSelect', 'lastValue() should fetch from the database' ); -is( $args->[1], 'LAST_INSERT_ID()', '... the last inserted id' ); -is( $result, 'insert id', '... returning the results' ); +{ + my $mock = Test::MockObject::Extends->new( Everything::DB::mysql->new() ); + $mock->set_always( getDatabaseHandle => $mock ) + ->set_always( last_insert_id => 'insert id' ); + my $result = $mock->lastValue(); + is( $result, 'insert id', 'lastValue() should fetch the last inserted id' ); +} + my $fields = [ { Field => 'foo', foo => 1 }, { Field => 'bar', bar => 2 } ]; can_ok( $package, 'getFieldsHash' ); @@ -50,7 +53,7 @@ ->set_true('execute')->set_series( 'fetchrow_hashref', @$fields ); my @result = Everything::DB::mysql::getFieldsHash( $mock, 'table' ); -( $method, $args ) = $mock->next_call(); +my ( $method, $args ) = $mock->next_call(); is( $method, 'getNode', 'getFieldsHash() should fetch node' ); is( join( '-', @$args[ 1, 2 ] ), 'table-dbtable', '... by name, of dbtable type' ); @@ -76,7 +79,7 @@ $mock->set_always( prepare => $mock )->set_true('execute') ->set_series( 'fetchrow', 1, 2, 'target' )->set_true('finish'); -$result = Everything::DB::mysql::tableExists( $mock, 'target' ); +my $result = Everything::DB::mysql::tableExists( $mock, 'target' ); ( $method, $args ) = $mock->next_call(); is( $method, 'prepare', 'tableExists should check with the database' ); is( $args->[1], 'show tables', '... fetching available table names' ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-05-25 23:39:46
|
Revision: 888 Author: chromatic Date: 2006-05-25 16:39:40 -0700 (Thu, 25 May 2006) ViewCVS: http://svn.sourceforge.net/everydevel/?rev=888&view=rev Log Message: ----------- r17517@windwheel: chromatic | 2006-05-25 16:39:11 -0700 Added Everything::DB::sqlite. Modified Paths: -------------- trunk/ebase/MANIFEST Added Paths: ----------- trunk/ebase/lib/Everything/DB/sqlite.pm Property Changed: ---------------- trunk/ebase/ Property changes on: trunk/ebase ___________________________________________________________________ Name: svk:merge - a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:17516 + a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:17517 Modified: trunk/ebase/MANIFEST =================================================================== --- trunk/ebase/MANIFEST 2006-05-25 23:39:26 UTC (rev 887) +++ trunk/ebase/MANIFEST 2006-05-25 23:39:40 UTC (rev 888) @@ -40,6 +40,7 @@ lib/Everything/DB.pm lib/Everything/DB/mysql.pm lib/Everything/DB/Pg.pm +lib/Everything/DB/sqlite.pm lib/Everything/HTML.pm lib/Everything/HTML/FormObject.pm lib/Everything/HTML/FormObject/AuthorMenu.pm Added: trunk/ebase/lib/Everything/DB/sqlite.pm =================================================================== --- trunk/ebase/lib/Everything/DB/sqlite.pm (rev 0) +++ trunk/ebase/lib/Everything/DB/sqlite.pm 2006-05-25 23:39:40 UTC (rev 888) @@ -0,0 +1,389 @@ +=head1 Everything::DB::sqlite + +SQLite database support. + +Copyright 2006 Everything Development Inc. + +=cut + +package Everything::DB::sqlite; + +use strict; +use warnings; + +use DBI; +use base 'Everything::DB'; + +=head2 C<databaseConnect> + +Connect to the database. + +=over 4 + +=item * dbname + +the database name + +=item * $host + +the hostname of the database server + +=item * $user + +the username to use to connect + +=item * $pass + +the password to use to connect + +=back + +This will throw an exception if the connection fails. + +=cut + +sub databaseConnect +{ + my ( $this, $dbname, $host, $user, $pass ) = @_; + + $this->{dbname} = $dbname; + $this->{dbh} = DBI->connect( "dbi:SQLite:dbname=$dbname", $user, $pass ) + or die "Unable to get database connection!"; + +} + +=head2 C<getFieldsHash> + +Given a table name, returns the names of fields. If C<$getHash> is true, it +will be an array of hashrefs of the fields. + +=over 4 + +=item * $table + +the name of the table to get fields for + +=item * $getHash + +Set to 1 if you would also like the entire field hash instead of just the field +name. (By default, true.) + +=back + +=cut + +sub getFieldsHash +{ + my ( $this, $table, $getHash ) = @_; + + $getHash = 1 unless defined $getHash; + $table ||= "node"; + + my $DBTABLE = $this->getNode( $table, 'dbtable' ) || {}; + + unless ( exists $DBTABLE->{Fields} ) + { + my $sth = $this->{dbh}->prepare_cached( "SELECT * FROM $table" ); + $sth->execute(); + + my $href = $sth->fetchrow_hashref(); + $sth->finish(); + + @{ $DBTABLE->{Fields} } = map { { Field => $_ } } keys %$href; + } + + return @{ $DBTABLE->{Fields} } if $getHash; + return map { $_->{Field} } @{ $DBTABLE->{Fields} }; +} + +=head2 C<tableExists> + +Check to see if a table of the given name exists in this database. Returns 1 +if it exists, 0 if not. + +=over 4 + +=item * $tableName + +The table to check. + +=back + +=cut + +sub tableExists +{ + my ( $this, $tableName ) = @_; + my $sth = $this->{dbh}->prepare( + "SELECT count(*) FROM sqlite_master WHERE type='table' AND name=?" + ); + + $sth->execute( $tableName ); + + my ($result) = $sth->fetch(); + return $result; +} + +=head2 C<createNodeTable> + +Create a new database table for a node, if it does not already exist. This +creates a new table with one field for the id of the node in the form of +tablename_id. + +Returns 1 if successful, 0 if failure, -1 if table already exists. + +=over 4 + +=item * $tableName + +the name of the table to create + +=back + +=cut + +sub createNodeTable +{ + my ( $this, $table ) = @_; + my $tableid = $table . '_id'; + + return -1 if $this->tableExists($table); + + return $this->{dbh}->do( + "create table $table ($tableid int4 DEFAULT '0' NOT NULL PRIMARY KEY"); +} + +=head2 C<createGroupTable> + +Creates a new group table if it does not already exist. Returns 1 if +successful, 0 if failure, or -1 if table already exists. + +=over 4 + +=item * $tableName + +the name of the table to create + +=back + +=cut + +sub createGroupTable +{ + my ( $this, $table ) = @_; + + return -1 if $this->tableExists($table); + + my $dbh = $this->getDatabaseHandle(); + my $tableid = $table . "_id"; + + my $sql = <<" SQLEND"; + create table $table ( + $tableid int4 DEFAULT '0' NOT NULL PRIMARY KEY, + rank int4 DEFAULT '0' NOT NULL PRIMARY KEY, + node_id int4 DEFAULT '0' NOT NULL, + orderby int4 DEFAULT '0' NOT NULL, + ) + SQLEND + + return $dbh->do($sql); +} + +=head2 C<dropFieldFromTable> + +Removes a field from the given table. Returns 1 if successful, 0 on failure. + +=over 4 + +=item * $table + +the table to remove the field from + +=item * $field + +the field to drop + +=back + +=cut + +sub dropFieldFromTable +{ + my ( $this, $table, $field ) = @_; + + die "XXX: Unimplemented; fix soon\n"; +=cut + +BEGIN TRANSACTION; +CREATE TABLE t1_backup(a,b); +INSERT INTO t1_backup SELECT a,b FROM t1; +DROP TABLE t1; +INSERT INTO t1 SELECT a,b FROM t1_backup; +ALTER TABLE t1_backup RENAME TO t1; +COMMIT; + +=cut +} + +=head2 C<addFieldToTable> + +Adds a new field to an existing database table. Returns 1 if successful, 0 on +failure. + +=over 4 + +=item * $table + +the table to add the new field to. + +=item * $fieldname + +the name of the field to add + +=item * $type + +the type of the field (ie int(11), char(32), etc) + +=item * $primary + +(optional) is this field a primary key? Defaults to no. + +=item * $default + +(optional) the default value of the field. + +=back + +=cut + +sub addFieldToTable +{ + my ( $this, $table, $fieldname, $type, $primary, $default ) = @_; + + return 0 if ( ( $table eq '' ) || ( $fieldname eq '' ) || ( $type eq '' ) ); + + # Text blobs cannot have default strings. They need to be empty. + $default = '' if ( $type =~ /^text/i ); + + unless ( defined $default ) + { + $default = $type =~ /^int/i ? 0 : ''; + } + + my $sql = + qq|alter table $table add $fieldname $type default "$default" | + . "not null"; + + $this->{dbh}->do($sql); + + if ($primary) + { + # This requires a little bit of work. Recreate the table instead. + die "XXX: Unimplemented primary key editing\n"; + } + + return 1; +} + +=head2 C<startTransaction> + +Starts a database transaction. + +Returns 0 if a transaction is already in progress, 1 otherwise. + +=cut + +sub startTransaction +{ + my $self = shift; + $self->getDatabaseHandle->begin_work(); +} + +=head2 commitTransaction + +Commits a database transaction. + +Returns 1 if a transaction isn't already in progress, 0 otherwise. + +=cut + +sub commitTransaction +{ + my $self = shift; + $self->getDatabaseHandle->commit(); +} + +=head2 C<rollbackTransaction> + +Rolls back a database transaction. This isn't guaranteed to work, +due to lack of implementation in certain DBMs. Don't depend on it. + +Returns 1 if a transaction isn't already in progress, 0 otherwise. + +=cut + +sub rollbackTransaction +{ + my $self = shift; + $self->getDatabaseHandle->rollback(); +} + +sub genLimitString +{ + my ( $this, $offset, $limit ) = @_; + + $offset ||= 0; + + return "LIMIT $offset, $limit"; +} + +sub genTableName +{ + my ( $this, $table ) = @_; + + return $table; +} + +=head2 C<databaseExists> + +Purpose: + See if a database exists + +Takes: + C<$database>, the name of the database for which to check + +Returns: + true or false, if the database exists + +=cut + +sub databaseExists +{ + my ( $this, $database ) = @_; + + return $this->{dbname} eq $database; +} + +sub list_tables +{ + my ($this) = @_; + my $sth = $this->{dbh}->prepare( + 'SELECT name FROM sqlite_master WHERE type="table"' ); + + $sth->execute(); + + my @tables; + + while ( my ($table) = $sth->fetchrow() ) + { + push @tables, $table; + } + + return @tables; +} + +sub now { return time() } + +sub timediff { "$_[1] - $_[2]" } + +1; Property changes on: trunk/ebase/lib/Everything/DB/sqlite.pm ___________________________________________________________________ Name: svn:mime-type + text/plain; charset=UTF-8 Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-06-14 21:17:25
|
Revision: 889 Author: chromatic Date: 2006-06-14 14:17:13 -0700 (Wed, 14 Jun 2006) ViewCVS: http://svn.sourceforge.net/everydevel/?rev=889&view=rev Log Message: ----------- r17843@windwheel: chromatic | 2006-06-14 14:16:56 -0700 Removed comments from base nodes SQL file so it's reusable between MySQL and SQLite, at least. Modified Paths: -------------- trunk/ebase/tables/basenodes.in Property Changed: ---------------- trunk/ebase/ Property changes on: trunk/ebase ___________________________________________________________________ Name: svk:merge - a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:17517 + a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:17843 Modified: trunk/ebase/tables/basenodes.in =================================================================== --- trunk/ebase/tables/basenodes.in 2006-05-25 23:39:40 UTC (rev 888) +++ trunk/ebase/tables/basenodes.in 2006-06-14 21:17:13 UTC (rev 889) @@ -1,11 +1,8 @@ - -# Create the nodes that we need to start the system INSERT INTO node VALUES (1,1,'nodetype',-1,'0000-00-00 00:00:00','0000-00-00 00:00:00',0,0,0,0,'0000-00-00 00:00:00','rwxd','-----','-----','-----',0,0,0,0,0); INSERT INTO node VALUES (2,1,'node',-1,'0000-00-00 00:00:00','0000-00-00 00:00:00',0,0,0,0,'0000-00-00 00:00:00','rwxd','-----','-----','-----',0,0,0,0,0); INSERT INTO node VALUES (3,1,'setting',-1,'0000-00-00 00:00:00','0000-00-00 00:00:00',0,0,0,0,'0000-00-00 00:00:00','rwxd','-----','-----','-----',0,0,0,0,0); -# Insert the nodetype information INSERT INTO nodetype VALUES (1,0,2,1,'nodetype','','rwxd','-----','-----','-----',0,0,0,0,0,-1,0); INSERT INTO nodetype VALUES (2,0,0,1,'','','rwxd','-----','-----','-----',0,0,0,0,0,1000,1); INSERT INTO nodetype VALUES (3,0,2,1,'setting','','rwxd','-----','-----','-----',0,0,0,0,0,-1,-1); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |