forked from movabletype/movabletype
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path92-pubqueue.t
144 lines (124 loc) · 3.74 KB
/
92-pubqueue.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/perl
use strict;
use warnings;
use lib 't/lib', 'lib', 'extlib';
use Test::More tests => 69;
use MT;
use MT::Blog;
use MT::Entry;
use MT::Log;
use MT::PublishOption;
use MT::Template;
use MT::TemplateMap;
use MT::Test qw( :db :data );
use MT::TheSchwartz::Error;
my @blogs = MT::Blog->load();
foreach my $blog (@blogs) {
my $job_count = 0;
my @tmpls = MT::Template->load({ blog_id => $blog->id });
ok (@tmpls, "Templates exist for this blog");
for (my $i = 0; $i < scalar(@tmpls); $i++) {
my $tmpl = $tmpls[$i];
ok ($tmpl, "Template i : $i id: " . $tmpl->id . " name: " . $tmpl->name);
$tmpl->build_type(MT::PublishOption::ASYNC);
if ($tmpl->name eq "Main Index") {
my $text = $tmpl->text;
$tmpl->text($text . '<mt:SomeDummyTag>');
}
$tmpl->save;
}
my $mt = MT->new or die MT->errstr;
$mt->rebuild(
BlogID => $blog->id,
Force => 1
) || print "Rebuild error: ", $mt->errstr;
my @jobs = MT::TheSchwartz::Job->load();
ok (@jobs, "Jobs were found");
$job_count = scalar(@jobs);
ok ($job_count > 1, "There are new jobs");
for my $job (@jobs) {
my $fi = MT::FileInfo->load({ id => $job->uniqkey });
my $at = $fi->archive_type || '';
my $priority = $job->priority;
if (($at eq 'Individual') || ($at eq 'Page')) {
my $map = MT::TemplateMap->load($fi->templatemap_id);
if ($map && $map->is_preferred) {
is ($priority, 10, "Priority is correct");
}
else {
is ($priority, 10, "Priority is correct");
}
}
elsif ($at eq 'index') {
if ($fi->file_path =~ m!/(index|default|atom|feed)!i) {
is ($priority, 9, "Priority is correct");
}
else {
is ($priority, 8, "Priority is correct");
}
}
elsif ($at =~ m/Category|Author/) {
is ($priority, 1, "Priority is correct");
}
elsif ($at =~ m/Yearly/) {
is ($priority, 1, "Priority is correct");
}
elsif ($at =~ m/Monthly/) {
is ($priority, 2, "Priority is correct");
}
elsif ($at =~ m/Weekly/) {
is ($priority, 3, "Priority is correct");
}
elsif ($at =~ m/Daily/) {
is ($priority, 4, "Priority is correct");
}
}
my $entry = MT::Entry->new;
$entry->set_values({
blog_id => $blog->id,
title => 'It\'s dark',
text => 'You may be eaten by a grue.',
keywords => 'keywords',
created_on => '19780131074500',
authored_on => '19780131074500',
modified_on => '19780131074600',
authored_on => '19780131074500',
author_id => 1,
allow_comments => 1,
allow_pings => 1,
status => MT::Entry::FUTURE(),
});
$entry->save;
my $entry_id = $entry->id;
ok ($entry_id, "Future post saves correctly" );
is ($entry->status, MT::Entry::FUTURE(), "Future post has status FUTURE");
_run_rpt();
my @errors = MT::TheSchwartz::Error->load();
ok (@errors, "Error should have been found");
@jobs = MT::TheSchwartz::Job->load();
ok (! @jobs, "Jobs were not found, everything went through");
## need reload for getting latest status, since rpt run as other process.
require MT::ObjectDriver::Driver::Cache::RAM;
MT::ObjectDriver::Driver::Cache::RAM->clear_cache();
my $current_entry = MT::Entry->load($entry_id);
is ($current_entry->status, MT::Entry::RELEASE(), "Running publish_future_post publishes future post; status is now RELEASE");
for (my $i = 0; $i < scalar(@tmpls); $i++) {
my $tmpl = $tmpls[$i];
$tmpl->build_type(MT::PublishOption::ONDEMAND);
$tmpl->save;
if ($tmpl->name eq "Main Index") {
my $text = $tmpl->text;
$text =~ s/<mt:SomeDummyTag>//g;
$tmpl->text($text);
$tmpl->save;
}
}
my $rebuild = $mt->rebuild(
BlogID => $blog->id,
Force => 1
) || 0;
ok ($rebuild, "Rebuilt all without the publish queue");
@jobs = MT::TheSchwartz::Job->load();
$job_count = scalar(@jobs);
ok ($job_count == 0, "There are no new jobs");
}