@@ -35,23 +35,28 @@ private function set_up_dashboard_screen() {
3535 * @param string $title Post title.
3636 * @param int $years_ago Number of years before today.
3737 * @param string $time Post time.
38+ * @param array $post_args Additional post arguments.
3839 * @return int Post ID.
3940 */
4041 private function create_matching_post (
4142 $ author_id ,
4243 $ title = 'A memory from last year ' ,
4344 $ years_ago = 1 ,
44- $ time = '12:00:00 '
45+ $ time = '12:00:00 ' ,
46+ $ post_args = array ()
4547 ) {
4648 $ post_date = current_datetime ()->modify ( '- ' . $ years_ago . ' years ' )->format ( 'Y-m-d ' ) . ' ' . $ time ;
4749
4850 return self ::factory ()->post ->create (
49- array (
50- 'post_author ' => $ author_id ,
51- 'post_date ' => $ post_date ,
52- 'post_date_gmt ' => get_gmt_from_date ( $ post_date ),
53- 'post_status ' => 'publish ' ,
54- 'post_title ' => $ title ,
51+ array_merge (
52+ array (
53+ 'post_author ' => $ author_id ,
54+ 'post_date ' => $ post_date ,
55+ 'post_date_gmt ' => get_gmt_from_date ( $ post_date ),
56+ 'post_status ' => 'publish ' ,
57+ 'post_title ' => $ title ,
58+ ),
59+ $ post_args
5560 )
5661 );
5762 }
@@ -309,6 +314,67 @@ public function test_widget_groups_posts_by_year() {
309314 $ this ->assertStringContainsString ( 'Late-night shipping log ' , $ output );
310315 }
311316
317+ /**
318+ * @covers ::wp_dashboard_on_this_day
319+ * @covers ::_wp_dashboard_on_this_day_get_no_title_excerpt
320+ */
321+ public function test_widget_includes_trimmed_excerpt_for_untitled_posts () {
322+ $ user_id = self ::factory ()->user ->create ( array ( 'role ' => 'author ' ) );
323+ wp_set_current_user ( $ user_id );
324+
325+ $ words = array ();
326+ for ( $ n = 1 ; $ n <= 20 ; $ n ++ ) {
327+ $ words [] = 'word ' . $ n ;
328+ }
329+
330+ $ this ->create_matching_post (
331+ $ user_id ,
332+ '' ,
333+ 1 ,
334+ '12:00:00 ' ,
335+ array (
336+ 'post_excerpt ' => implode ( ' ' , $ words ),
337+ )
338+ );
339+
340+ ob_start ();
341+ wp_dashboard_on_this_day ();
342+ $ output = ob_get_clean ();
343+
344+ $ this ->assertStringContainsString ( '(no title) ' , $ output );
345+ $ this ->assertStringContainsString ( 'class="trimmed-post-excerpt" ' , $ output );
346+ $ this ->assertStringContainsString ( 'word15 ' , $ output , 'The 15th word should be present. ' );
347+ $ this ->assertStringNotContainsString ( 'word16 ' , $ output , 'The 16th word should be trimmed. ' );
348+ $ this ->assertStringContainsString ( '… ' , $ output , 'The excerpt should end with an ellipsis. ' );
349+ }
350+
351+ /**
352+ * @covers ::wp_dashboard_on_this_day
353+ * @covers ::_wp_dashboard_on_this_day_get_no_title_excerpt
354+ */
355+ public function test_widget_hides_untitled_post_excerpt_for_password_protected_posts () {
356+ $ user_id = self ::factory ()->user ->create ( array ( 'role ' => 'author ' ) );
357+ wp_set_current_user ( $ user_id );
358+
359+ $ this ->create_matching_post (
360+ $ user_id ,
361+ '' ,
362+ 1 ,
363+ '12:00:00 ' ,
364+ array (
365+ 'post_excerpt ' => 'Private anniversary memory. ' ,
366+ 'post_password ' => 'secret ' ,
367+ )
368+ );
369+
370+ ob_start ();
371+ wp_dashboard_on_this_day ();
372+ $ output = ob_get_clean ();
373+
374+ $ this ->assertStringNotContainsString ( 'Private anniversary memory. ' , $ output );
375+ $ this ->assertStringNotContainsString ( 'class="trimmed-post-excerpt" ' , $ output );
376+ }
377+
312378 /**
313379 * @covers ::wp_dashboard_on_this_day
314380 * @covers ::wp_dashboard_on_this_day_get_posts
0 commit comments