-
Notifications
You must be signed in to change notification settings - Fork 42
/
Thread.t
117 lines (97 loc) · 4.5 KB
/
Thread.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use strict;
use WebGUI::Test;
use WebGUI::Session;
use Test::More tests => 17; # increment this value for each test you create
use Test::MockObject::Extends;
use Test::Exception;
use WebGUI::Asset::Wobject::Collaboration;
use WebGUI::Asset::Post::Thread;
my $session = WebGUI::Test->session;
# Do our work in the import node
my $node = WebGUI::Asset->getImportNode($session);
# Grab a named version tag
my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->set({name=>"Collab setup"});
WebGUI::Test->addToCleanup($versionTag);
# Need to create a Collaboration system in which the post lives.
my @addArgs = ( undef, undef, { skipNotification => 1 } );
my $collab = $node->addChild({
className => 'WebGUI::Asset::Wobject::Collaboration',
editTimeout => '1',
threadsPerPage => 3,
status => "pending",
tagId => $versionTag->getId,
},
@addArgs);
# finally, add the post to the collaboration system
my $props = {
className => 'WebGUI::Asset::Post::Thread',
content => 'hello, world!',
ownerUserId => 1,
status => "pending",
tagId => $versionTag->getId,
};
my $thread = $collab->addChild($props, @addArgs);
$thread->setSkipNotification;
$versionTag->commit();
$collab = $collab->cloneFromDb;
$thread = $thread->cloneFromDb;
my $uncommittedThread = $collab->addChild($props, @addArgs);
$uncommittedThread->setSkipNotification;
# Test for a sane object type
isa_ok($thread, 'WebGUI::Asset::Post::Thread');
$session->user({userId => 3});
$thread->rate(1);
$thread->trash;
is($thread->get('threadRating'), 0, 'trash does not die, and updates the threadRating to 0');
note 'getThreadLinkUrl';
unlike $thread->getThreadLinkUrl, qr/\?pn=\d+/, 'threads do not need pagination url query fragments';
unlike $uncommittedThread->getThreadLinkUrl, qr/\?pn=\d+/, 'uncommitted threads, too';
like $uncommittedThread->getThreadLinkUrl, qr/\?revision=\d+/, 'uncommitted threads do have a revision query param';
$collab->update({threadsPerPage => 0, postsPerPage => 0,});
lives_ok { $uncommittedThread->getThreadLinkUrl } '... works when pagination set to 0';
$collab->update({threadsPerPage => 3, postsPerPage => 10,});
note 'getCSLinkUrl';
my @newThreads;
my $threadCount = 15;
my $versionTag2 = WebGUI::VersionTag->getWorking($session);
WebGUI::Test->addToCleanup( $versionTag2 );
$props->{tagId} = $versionTag2->getId;
while ($threadCount--) {
push @newThreads, $collab->addChild($props, @addArgs);
}
$_->setSkipNotification for @newThreads;
$versionTag2->commit;
my $csUrl = $collab->get('url');
like $newThreads[-1]->getCSLinkUrl, qr/^$csUrl/, 'getCsLinkUrl returns URL of the parent CS with no gateway';
like $newThreads[-1]->getCSLinkUrl, qr/\?pn=1/, '... and has the right page number';
like $newThreads[-1]->getCSLinkUrl, qr/\?pn=1;sortBy=lineage;sortOrder=desc/, 'and has the right sort parameters';
like $newThreads[-2]->getCSLinkUrl, qr/\?pn=1/, '... second to last has right page number';
like $newThreads[-3]->getCSLinkUrl, qr/\?pn=1/, '... and third to last';
like $newThreads[-4]->getCSLinkUrl, qr/\?pn=2/, '... and fourth to last';
$thread->restore();
like $thread->getCSLinkUrl, qr/\?pn=6/, 'checking 2nd thread on another page';
$newThreads[0]->archive;
$newThreads[1]->archive;
$newThreads[2]->archive;
like $thread->getCSLinkUrl, qr/\?pn=5/, 'checking thread on another page, with archived threads';
$collab->update({threadsPerPage => 0, postsPerPage => 0,});
lives_ok { $uncommittedThread->getCSLinkUrl } '... works when pagination set to 0';
######################################################################
#
# duplicate
#
######################################################################
my $thread_copy = $thread->duplicate();
ok $thread_copy->get('subscriptionGroupId'), 'duplicate: copied thread got a subscription group';
isnt $thread_copy->get('subscriptionGroupId'), $thread->get('subscriptionGroupId'), '... and it is different from the original thread';
# vim: syntax=perl filetype=perl