--- /dev/null
+package Newslash::Util::Test;
+
+use strict;
+use warnings;
+use utf8;
+use feature ':5.10';
+
+use Exporter 'import';
+
+our @EXPORT_OK = qw(create_user delete_user
+ create_story delete_story
+ );
+
+use Data::Dumper;
+
+my $fake_ipid = "0123456789abcdef0123456789abcdef";
+my $fake_subnetid = "0123456789abcdef0123456789abcdef";
+
+
+=head2 create_user($app, $user_name)
+
+create user for test.
+
+=over 4
+
+=item Parameters
+
+=over 4
+
+=item $app
+
+application / test object
+
+=back
+
+=item $user_name
+
+user name to create
+
+=back
+
+=item Return value
+
+user hashref
+
+=back
+
+=cut
+
+sub create_user {
+ my ($app, $user_name) = @_;
+ my $users = $app->model('users');
+ my $user_id = $users->create($user_name, $user_name . '@example.com');
+ if (!$user_id) {
+ $user_id = $users->select(nickname => $user_name);
+ }
+ return if !$user_id;
+ my $user = $users->select(uid => $user_id);
+ $user->{ipid} = $fake_ipid;
+ $user->{subnetid} = $fake_subnetid;
+
+ return $user;
+}
+
+=head2 delete_user($app, $user_name)
+
+delete user for test.
+
+=over 4
+
+=item Parameters
+
+=over 4
+
+=item $app
+
+application / test object
+
+=back
+
+=item $user_name
+
+user name to delete
+
+=back
+
+=item Return value
+
+user hashref
+
+=back
+
+=cut
+
+sub delete_user {
+ my ($app, $user_name) = @_;
+ my $users = $app->model('users');
+ my $user = $users->select(nickname => $user_name);
+ return if !$user;
+
+ $users->hard_delete($user->{uid});
+ return $user;
+}
+
+=head2 create_story($app, $user, @params)
+
+create user for test.
+
+=over 4
+
+=item Parameters
+
+=over 4
+
+=item $app
+
+application / test object
+
+=back
+
+=over 4
+
+=item $user
+
+user hashref
+
+=back
+
+=over 4
+
+=item @params
+
+foo => bar style parameters
+
+=back
+
+=item Return value
+
+story hashref
+
+=back
+
+=cut
+
+sub create_story {
+ my $app = shift;
+ my $user = shift;
+ my $args = {@_};
+
+ my $stories = $app->model('stories');
+
+ return if !$app;
+ return if !$user;
+ my $params = {
+ uid => $user->{uid},
+ title => $args->{title} || "test story",
+ introtext => $args->{introtext} || '<p>foo bar hoge</p>',
+ bodytext => $args->{bodytext} || '',
+ topics_chosen => $args->{topics} || {49 => 10, 2271 => 20},
+ commentstatus => '',
+ tid => $args->{tid} || 49,
+ };
+ my $stoid = $stories->create($params, $user->{uid});
+ return if !$stoid;
+ my $story = $stories->select(stoid => $stoid);
+ return $story;
+}
+
+=head2 delete_story($app, $sid)
+
+delete story for test.
+
+=over 4
+
+=item Parameters
+
+=over 4
+
+=item $app
+
+application / test object
+
+=back
+
+=item $stoid
+
+story id to delete
+
+=back
+
+=item Return value
+
+undef / 1
+
+=back
+
+=cut
+
+sub delete_story{
+ my ($app, $stoid) = @_;
+ my $stories = $app->model('stories');
+ $stories->hard_delete(stoid => $stoid);
+
+ return 1;
+}
+
+
+1;