@@ 133-181 (lines=49) @@ | ||
130 | /** |
|
131 | * Test that a page with a past publish date creates the correct jobs |
|
132 | */ |
|
133 | public function testPastPublishThenUnpublish() { |
|
134 | $page = new Page(); |
|
135 | $page->Title = 'My Page'; |
|
136 | $page->write(); |
|
137 | ||
138 | // No publish |
|
139 | $this->assertEmpty($page->PublishJobID); |
|
140 | $this->assertEmpty($page->UnPublishJobID); |
|
141 | ||
142 | // Set a past publish date |
|
143 | $page->PublishOnDate = '2010-01-01 00:00:00'; |
|
144 | $page->write(); |
|
145 | ||
146 | // We should still have a job to publish this page, but not unpublish |
|
147 | $this->assertNotEmpty($page->PublishJobID); |
|
148 | $this->assertEmpty($page->UnPublishJobID); |
|
149 | ||
150 | // Check that this job is set for immediate run |
|
151 | $publish = strtotime($page->PublishJob()->StartAfter); |
|
152 | $this->assertEmpty($publish); |
|
153 | ||
154 | // Now add an expiry date in the past, but after the current publish job, |
|
155 | // and ensure that this correctly overrides the open publish request |
|
156 | $page->UnPublishOnDate = '2010-01-02 00:00:00'; |
|
157 | $page->write(); |
|
158 | ||
159 | // Now we should have an unpublish job, but the publish job is noticably absent |
|
160 | $this->assertEmpty($page->PublishJobID); |
|
161 | $this->assertNotEmpty($page->UnPublishJobID); |
|
162 | ||
163 | // Check that this unpublish job is set for immediate run |
|
164 | $unpublish = strtotime($page->UnPublishJob()->StartAfter); |
|
165 | $this->assertEmpty($unpublish); |
|
166 | ||
167 | // Now add an expiry date in the future, and ensure that we get the correct combination of |
|
168 | // publish and unpublish jobs |
|
169 | $page->UnPublishOnDate = '2015-01-01 12:00:00'; |
|
170 | $page->write(); |
|
171 | ||
172 | // Both jobs exist |
|
173 | $this->assertNotEmpty($page->PublishJobID); |
|
174 | $this->assertNotEmpty($page->UnPublishJobID); |
|
175 | ||
176 | // Check that this unpublish job is set for immediate run and the unpublish for future |
|
177 | $publish = strtotime($page->PublishJob()->StartAfter); |
|
178 | $unpublish = strtotime($page->UnPublishJob()->StartAfter); |
|
179 | $this->assertEmpty($publish); // for immediate run |
|
180 | $this->assertGreaterThan(strtotime(SS_Datetime::now()->getValue()), $unpublish); // for later run |
|
181 | } |
|
182 | ||
183 | /** |
|
184 | * Test that a page with a past unpublish date creates the correct jobs |
|
@@ 186-234 (lines=49) @@ | ||
183 | /** |
|
184 | * Test that a page with a past unpublish date creates the correct jobs |
|
185 | */ |
|
186 | public function testPastUnPublishThenPublish() { |
|
187 | $page = new Page(); |
|
188 | $page->Title = 'My Page'; |
|
189 | $page->write(); |
|
190 | ||
191 | // No publish |
|
192 | $this->assertEmpty($page->PublishJobID); |
|
193 | $this->assertEmpty($page->UnPublishJobID); |
|
194 | ||
195 | // Set a past unpublish date |
|
196 | $page->UnPublishOnDate = '2010-01-01 00:00:00'; |
|
197 | $page->write(); |
|
198 | ||
199 | // We should still have a job to unpublish this page, but not publish |
|
200 | $this->assertEmpty($page->PublishJobID); |
|
201 | $this->assertNotEmpty($page->UnPublishJobID); |
|
202 | ||
203 | // Check that this job is set for immediate run |
|
204 | $unpublish = strtotime($page->UnPublishJob()->StartAfter); |
|
205 | $this->assertEmpty($unpublish); |
|
206 | ||
207 | // Now add an publish date in the past, but after the unpublish job, |
|
208 | // and ensure that this correctly overrides the open unpublish request |
|
209 | $page->PublishOnDate = '2010-01-02 00:00:00'; |
|
210 | $page->write(); |
|
211 | ||
212 | // Now we should have an publish job, but the unpublish job is noticably absent |
|
213 | $this->assertNotEmpty($page->PublishJobID); |
|
214 | $this->assertEmpty($page->UnPublishJobID); |
|
215 | ||
216 | // Check that this publish job is set for immediate run |
|
217 | $publish = strtotime($page->PublishJob()->StartAfter); |
|
218 | $this->assertEmpty($publish); |
|
219 | ||
220 | // Now add a publish date in the future, and ensure that we get the correct combination of |
|
221 | // publish and unpublish jobs |
|
222 | $page->PublishOnDate = '2015-01-01 12:00:00'; |
|
223 | $page->write(); |
|
224 | ||
225 | // Both jobs exist |
|
226 | $this->assertNotEmpty($page->PublishJobID); |
|
227 | $this->assertNotEmpty($page->UnPublishJobID); |
|
228 | ||
229 | // Check that this unpublish job is set for immediate run and the unpublish for future |
|
230 | $publish = strtotime($page->PublishJob()->StartAfter); |
|
231 | $unpublish = strtotime($page->UnPublishJob()->StartAfter); |
|
232 | $this->assertEmpty($unpublish); // for immediate run |
|
233 | $this->assertGreaterThan(strtotime(SS_Datetime::now()->getValue()), $publish); // for later run |
|
234 | } |
|
235 | ||
236 | public function testPastPublishWithWorkflowInEffect() { |
|
237 | $definition = $this->createDefinition(); |