OSDN Git Service

* Util::Test: add create/delete comment/journal methods
authorhylom <hylom@users.sourceforge.jp>
Sun, 8 Oct 2017 17:51:36 +0000 (02:51 +0900)
committerhylom <hylom@users.sourceforge.jp>
Sun, 8 Oct 2017 17:51:36 +0000 (02:51 +0900)
src/newslash_web/lib/Newslash/Util/Test.pm

index b146286..0a111db 100644 (file)
@@ -13,7 +13,9 @@ our @EXPORT_OK = qw(create_user delete_user
                     create_story delete_story
                     create_admin_user
                     create_comments
+                    create_comment delete_comment
                     create_users
+                    create_journal delete_journal
                     update_user_passwd
                     get_anonymous_user
                     srcid
@@ -204,6 +206,11 @@ sub create_story {
     my $args = {@_};
 
     my $stories = $app->model('stories');
+    if ($args->{params}) {
+        my $p = $args->{params};
+        delete $args->{params};
+        $args = {%$args, %$p};
+    }
 
     return if !$app;
     return if !$user;
@@ -263,6 +270,39 @@ sub delete_story{
     return 1;
 }
 
+sub create_journal {
+    my $app = shift;
+    my $user = shift;
+    my $args = {@_};
+
+    my $journals = $app->model('journals');
+    if ($args->{params}) {
+        my $p = $args->{params};
+        delete $args->{params};
+        $args = {%$args, %$p};
+    }
+
+    return if !$app;
+    return if !$user;
+    my $id = $journals->create(user => $user,
+                               description => $args->{title} || "test title",
+                               article => $args->{intro_text} || $args->{introtext} || "test journal",
+                               commentstatus => $args->{commentstatus} || $args->{comment_status} || "enabled",
+                               posttype => 2);
+    if (!$id) {
+        warn($journals->last_error);
+        return;
+    }
+    my $journal = $journals->select(journal_id => $id);
+    return $journal;
+}
+
+sub delete_journal {
+    my ($app, $id) = @_;
+    my $rs = $app->model('journals')->hard_delete(id => $id);
+    return $rs;
+}
+
 sub create_comment {
     my ($app, $user, $discussion_id, $title, $comment, $pid) = @_;
     my $params = {
@@ -277,6 +317,12 @@ sub create_comment {
     return $comm;
 }
 
+sub delete_comment {
+    my ($app, $cid) = @_;
+    my $rs = $app->model('comments')->hard_delete(cid => $cid);
+    return $rs;
+}
+
 sub create_comments {
     my ($app, $discussion_id, $comms, $pid) = @_;
     my $rs = {};