[dw-free] move bin/test/* files into t/*
[commit: http://hg.dwscoalition.org/dw-free/rev/099e36e57f4f]
http://bugs.dwscoalition.org/show_bug.cgi?id=2227
More cleanup: standardize testing framework (content filters)
Patch by
kareila.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=2227
More cleanup: standardize testing framework (content filters)
Patch by
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Files modified:
- bin/test/test-filters
- t/content-filters.t
-------------------------------------------------------------------------------- diff -r fb4153b9aa7c -r 099e36e57f4f bin/test/test-filters --- a/bin/test/test-filters Fri Apr 23 11:50:13 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,147 +0,0 @@ -#!/usr/bin/perl -# yes, there are so many better testing modules than just doing this in a crappy -# half-ass way. - -use strict; -use lib "$ENV{LJHOME}/cgi-bin"; -require 'ljlib.pl'; - -use Data::Dumper; - -# much time passes ... -my $u1 = LJ::load_user( 'tester0394' ) or die 'no tester0394'; -my $u2 = LJ::load_user( 'tester0395' ) or die 'no tester0395'; -my $uc = LJ::load_user( 'testcomm' ) or die 'no testcomm'; -$uc->is_community or die 'testcomm not a community :('; - -my @tests; -print "Beginning tests...\n"; -print " u1 = " . $u1->user . '(' . $u1->id . ")\n"; -print " u2 = " . $u2->user . '(' . $u2->id . ")\n"; -print " uc = " . $uc->user . '(' . $uc->id . ")\n\n"; - -my $dbh = LJ::get_db_writer(); - -# reset, delete, etc -sub rst { - foreach my $u ( $u1, $u2, $uc ) { - foreach my $tbl ( qw/ content_filters content_filter_data / ) { - $u->do( "DELETE FROM $tbl WHERE userid = ?", undef, $u->id ); - } - - foreach my $mc ( qw/ content_filters / ) { - LJ::memcache_kill( $u, $mc ); - } - } -} - -################################################################################ -push @tests, [ 'no filters', sub -{ - rst(); - my @f = $u1->content_filters; - return $#f == -1; # empty list -} ]; - - -################################################################################ -push @tests, [ 'make empty filter', sub -{ - my $fid = $u1->create_content_filter( name => 'foob', public => 1, sortorder => 13 ); - return $fid > 0; -} ]; - - -################################################################################ -push @tests, [ 'get empty filter', sub -{ - my $filter = $u1->content_filters( name => 'foob' ); - return $filter->name eq 'foob'; -} ]; - - -################################################################################ -push @tests, [ 'make another filter', sub -{ - my $fid = $u1->create_content_filter( name => 'isfd', public => 0, sortorder => 31 ); - my $f = $u1->content_filters( id => $fid ); - return $fid > 0 && $f->name eq 'isfd'; -} ]; - - -################################################################################ -push @tests, [ 'get second filter', sub -{ - my $filter = $u1->content_filters( name => 'isfd' ); - return $filter->name eq 'isfd'; -} ]; - - -################################################################################ -push @tests, [ 'get bogus filter', sub -{ - my $filter = $u1->content_filters( name => 'sodf' ); - return ! defined $filter; -} ]; - - -################################################################################ -push @tests, [ 'get both filters', sub -{ - my @filters = $u1->content_filters; - return $#filters == 1; -} ]; - - -################################################################################ -push @tests, [ 'get data, is empty', sub -{ - my $f = $u1->content_filters( name => 'foob' ); - my $data = $f->data; - return defined $data && ref $data eq 'HASH' && scalar keys %$data == 0; -} ]; - - -################################################################################ -push @tests, [ 'add a row', sub -{ - my $f = $u1->content_filters( name => 'foob' ); - my $rv = $f->add_row( userid => $u2->id ); - return $rv == 1; -} ]; - - -################################################################################ -push @tests, [ 'get data, has u2', sub -{ - my $f = $u1->content_filters( name => 'foob' ); - my $data = $f->data; - return $data && exists $data->{$u2->id}; -} ]; - - -################################################################################ -push @tests, [ 'delete filter', sub -{ - my $f = $u1->delete_content_filter( name => 'foob' ); - return $f > 0; -} ]; - - -################################################################################ -$| = 1; -my $id = 1; -foreach my $test ( @tests ) { - print "Test #$id: $test->[0]: "; - my $rv = 0; - eval { - $rv = $test->[1]->(); - }; - if ( $@ || $rv == 0 ) { - print "failure!\n\n\$@ = $@\n\$! = $!\nrv = $rv\n\n"; - die; - } else { - print "success\n"; - } - $id++; -} diff -r fb4153b9aa7c -r 099e36e57f4f t/content-filters.t --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/t/content-filters.t Fri Apr 23 22:40:12 2010 -0700 @@ -0,0 +1,75 @@ +#!/usr/bin/perl + +use strict; +use Test::More; +use lib "$ENV{LJHOME}/cgi-bin"; +require 'ljlib.pl'; +use LJ::Test qw (temp_user); + +plan tests => 12; + +my $u1 = temp_user(); +my $u2 = temp_user(); + +my ( $filter, $fid, $data, @f ); + +# reset, delete, etc +sub rst { + foreach my $u ( $u1, $u2 ) { + foreach my $tbl ( qw/ content_filters content_filter_data / ) { + $u->do( "DELETE FROM $tbl WHERE userid = ?", undef, $u->id ); + } + + foreach my $mc ( qw/ content_filters / ) { + LJ::memcache_kill( $u, $mc ); + } + } +} + +################################################################################ +rst(); +@f = $u1->content_filters; +ok( $#f == -1, 'no filters' ); # empty list + +$fid = $u1->create_content_filter( name => 'foob', public => 1, sortorder => 13 ); +ok( $fid > 0, 'make empty filter' ); + +$filter = $u1->content_filters( name => 'foob' ); +is( $filter->name, 'foob', 'lookup filter 1 by name' ); + +################################################################################ +$fid = $u1->create_content_filter( name => 'isfd', public => 0, sortorder => 31 ); +ok( $fid > 0, 'make another filter' ); + +$filter = $u1->content_filters( id => $fid ); +is( $filter->name, 'isfd', 'lookup filter 2 by id' ); + +$filter = $u1->content_filters( name => 'isfd' ); +is( $filter->name, 'isfd', 'lookup filter 2 by name' ); + +################################################################################ +$filter = $u1->content_filters( name => 'sodf' ); +ok( ! defined $filter, 'get bogus filter' ); + +@f = $u1->content_filters; +ok( $#f == 1, 'get both filters' ); + +################################################################################ +$filter = $u1->content_filters( name => 'foob' ); +$data = $filter->data; +ok( defined $data && ref $data eq 'HASH' && scalar keys %$data == 0, + 'get data, is empty' ); + +################################################################################ +$filter = $u1->content_filters( name => 'foob' ); +ok( $filter->add_row( userid => $u2->id ) == 1, 'add a row' ); + +$filter = $u1->content_filters( name => 'foob' ); +$data = $filter->data; +ok( $data && exists $data->{$u2->id}, 'get data, has u2' ); + +################################################################################ +$fid = $u1->delete_content_filter( name => 'foob' ); +ok( $fid > 0, 'delete filter' ); + +################################################################################ --------------------------------------------------------------------------------