Bug 17501: Introduce Koha::Object[s] classes for UploadedFile(s)
authorMarcel de Rooy <m.de.rooy@rijksmuseum.nl>
Sat, 19 Nov 2016 16:24:11 +0000 (17:24 +0100)
committerKyle M Hall <kyle@bywatersolutions.com>
Fri, 20 Jan 2017 14:20:03 +0000 (14:20 +0000)
In the next set of patches we will start using these new classes in
Koha::Upload, and scripts using it.
This is just the starting point of that migration.

Test plan:
[1] Run t/db_dependent/Upload.t

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Koha/UploadedFile.pm [new file with mode: 0644]
Koha/UploadedFiles.pm [new file with mode: 0644]
t/db_dependent/Upload.t

diff --git a/Koha/UploadedFile.pm b/Koha/UploadedFile.pm
new file mode 100644 (file)
index 0000000..5e573ba
--- /dev/null
@@ -0,0 +1,73 @@
+package Koha::UploadedFile;
+
+# Copyright Rijksmuseum 2016
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 3 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+use Modern::Perl;
+
+#use Koha::Database;
+
+use parent qw(Koha::Object);
+
+=head1 NAME
+
+Koha::UploadedFile - Koha::Object class for single uploaded file
+
+=head1 SYNOPSIS
+
+use Koha::UploadedFile;
+
+=head1 DESCRIPTION
+
+Description
+
+=head1 METHODS
+
+=head2 INSTANCE METHODS
+
+=head3 delete
+
+Delete uploaded file (to be extended)
+
+=cut
+
+sub delete {
+    my ( $self, $params ) = @_;
+    $self->SUPER::delete( $params );
+}
+
+=head2 CLASS METHODS
+
+=head3 _type
+
+Returns name of corresponding DBIC resultset
+
+=cut
+
+sub _type {
+    return 'UploadedFile';
+}
+
+=head1 AUTHOR
+
+Marcel de Rooy (Rijksmuseum)
+
+Koha Development Team
+
+=cut
+
+1;
diff --git a/Koha/UploadedFiles.pm b/Koha/UploadedFiles.pm
new file mode 100644 (file)
index 0000000..23bb52a
--- /dev/null
@@ -0,0 +1,84 @@
+package Koha::UploadedFiles;
+
+# Copyright Rijksmuseum 2016
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 3 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+use Modern::Perl;
+
+#use Koha::Database;
+use Koha::UploadedFile;
+
+use parent qw(Koha::Objects);
+
+=head1 NAME
+
+Koha::UploadedFiles - Koha::Objects class for uploaded files
+
+=head1 SYNOPSIS
+
+use Koha::UploadedFiles;
+
+=head1 DESCRIPTION
+
+Description
+
+=head1 METHODS
+
+=head2 INSTANCE METHODS
+
+=head3 delete
+
+Delete uploaded files
+
+=cut
+
+sub delete {
+    my ( $self, $params ) = @_;
+    $self->SUPER::delete( $params );
+}
+
+=head2 CLASS METHODS
+
+=head3 _type
+
+Returns name of corresponding DBIC resultset
+
+=cut
+
+sub _type {
+    return 'UploadedFile';
+}
+
+=head3 object_class
+
+Returns name of corresponding Koha object class
+
+=cut
+
+sub object_class {
+    return 'Koha::UploadedFile';
+}
+
+=head1 AUTHOR
+
+Marcel de Rooy (Rijksmuseum)
+
+Koha Development Team
+
+=cut
+
+1;
index 20791f3..6c69521 100644 (file)
@@ -2,7 +2,7 @@
 
 use Modern::Perl;
 use File::Temp qw/ tempdir /;
-use Test::More tests => 8;
+use Test::More tests => 9;
 
 use Test::MockModule;
 use t::lib::Mocks;
@@ -11,6 +11,7 @@ use t::lib::TestBuilder;
 use C4::Context;
 use Koha::Database;
 use Koha::Upload;
+use Koha::UploadedFiles;
 
 my $schema  = Koha::Database->new->schema;
 $schema->storage->txn_begin;
@@ -204,6 +205,23 @@ sub test08 { # allows_add_by
         1, 'Patron is still allowed to add uploaded files' );
 }
 
+# Additional tests for Koha::UploadedFiles
+# TODO Rearrange the tests after this migration
+subtest 'Some basic CRUD testing' => sub {
+    plan tests => 2;
+
+    # Test find and attribute id, delete and search
+    my $builder = t::lib::TestBuilder->new;
+    my $upload01 = $builder->build({ source => 'UploadedFile' });
+    my $found = Koha::UploadedFiles->find( $upload01->{id} );
+    is( $found->id, $upload01->{id}, 'Koha::Object returns id' );
+    $found->delete;
+    $found = Koha::UploadedFiles->search(
+        { id => $upload01->{id} },
+    );
+    is( $found->count, 0, 'Delete seems successful' );
+};
+
 sub newCGI {
     my ( $class, $hook ) = @_;
     my $read = 0;