[ Index ] |
PHP Cross Reference of BBPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Tests for the `bbp_update_topic_last_*()` functions. 4 * 5 * @group topics 6 * @group functions 7 * @group update_last_thing 8 */ 9 10 class BBP_Tests_Topics_Functions_Update_Topic_Last_Thing extends BBP_UnitTestCase { 11 12 /** 13 * @covers ::bbp_update_topic_last_active_id 14 */ 15 public function test_bbp_update_topic_last_active_id() { 16 $f = $this->factory->forum->create(); 17 $t = $this->factory->topic->create( array( 18 'post_parent' => $f, 19 'topic_meta' => array( 20 'forum_id' => $f, 21 ), 22 ) ); 23 $r1 = $this->factory->reply->create( array( 24 'post_parent' => $t, 25 'reply_meta' => array( 26 'forum_id' => $f, 27 'topic_id' => $t, 28 ), 29 ) ); 30 31 // Pass both the topic id and reply id to bbp_update_topic_last_active_id(). 32 bbp_update_topic_last_active_id( $t, $r1 ); 33 $last_active_id = bbp_get_topic_last_active_id( $t ); 34 $this->assertSame( $r1, $last_active_id ); 35 36 $r2 = $this->factory->reply->create( array( 37 'post_parent' => $t, 38 'reply_meta' => array( 39 'forum_id' => $f, 40 'topic_id' => $t, 41 ), 42 ) ); 43 44 // Pass the topic id to bbp_update_topic_last_active_id(). 45 bbp_update_topic_last_active_id( $t ); 46 $last_active_id = bbp_get_topic_last_active_id( $t ); 47 $this->assertSame( $r2, $last_active_id ); 48 49 // Create a couple of replies. 50 $r3 = $this->factory->reply->create_many( 2, array( 51 'post_parent' => $t, 52 'reply_meta' => array( 53 'forum_id' => $f, 54 'topic_id' => $t, 55 ), 56 ) ); 57 58 // Pass both the topic id and reply id of the array. 59 bbp_update_topic_last_active_id( $t, $r3[1] ); 60 $last_active_id = bbp_get_topic_last_active_id( $t ); 61 $this->assertSame( $r3[1], $last_active_id ); 62 } 63 64 /** 65 * @covers ::bbp_update_topic_last_active_time 66 */ 67 public function test_bbp_update_topic_last_active_time() { 68 $f = $this->factory->forum->create(); 69 $t = $this->factory->topic->create( array( 70 'post_parent' => $f, 71 'topic_meta' => array( 72 'forum_id' => $f, 73 ), 74 ) ); 75 $r1 = $this->factory->reply->create( array( 76 'post_parent' => $t, 77 'reply_meta' => array( 78 'forum_id' => $f, 79 'topic_id' => $t, 80 ), 81 ) ); 82 83 $r1_time_raw = get_post_field( 'post_date', $r1 ); 84 $r1_time_formatted = bbp_get_time_since( bbp_convert_date( $r1_time_raw ) ); 85 86 $time = bbp_update_topic_last_active_time( $t, $r1_time_raw ); 87 $this->assertSame( $r1_time_raw, $time ); 88 89 $time = bbp_get_topic_last_active_time( $t ); 90 $this->assertSame( $r1_time_formatted, $time ); 91 92 $r2 = $this->factory->reply->create_many( 2, array( 93 'post_parent' => $t, 94 'reply_meta' => array( 95 'forum_id' => $f, 96 'topic_id' => $t, 97 ), 98 ) ); 99 100 $r2_time_raw = get_post_field( 'post_date', $r2[1] ); 101 $r2_time_formatted = bbp_get_time_since( bbp_convert_date( $r2_time_raw ) ); 102 103 bbp_update_topic_last_active_time( $t ); 104 $time = bbp_get_topic_last_active_time( $t ); 105 $this->assertSame( $r2_time_formatted, $time ); 106 } 107 108 /** 109 * @covers ::bbp_update_topic_last_reply_id 110 */ 111 public function test_bbp_update_topic_last_reply_id() { 112 $f = $this->factory->forum->create(); 113 $t = $this->factory->topic->create( array( 114 'post_parent' => $f, 115 'topic_meta' => array( 116 'forum_id' => $f, 117 ), 118 ) ); 119 $r1 = $this->factory->reply->create( array( 120 'post_parent' => $t, 121 'reply_meta' => array( 122 'forum_id' => $f, 123 'topic_id' => $t, 124 ), 125 ) ); 126 127 $id = bbp_update_topic_last_reply_id( $t, $r1 ); 128 $this->assertSame( $r1, $id ); 129 130 $id = bbp_get_topic_last_reply_id( $t ); 131 $this->assertSame( $r1, $id ); 132 133 $r2 = $this->factory->reply->create_many( 2, array( 134 'post_parent' => $t, 135 'reply_meta' => array( 136 'forum_id' => $f, 137 'topic_id' => $t, 138 ), 139 ) ); 140 141 bbp_update_topic_last_reply_id( $t, $r2[1] ); 142 $id = bbp_get_topic_last_reply_id( $t ); 143 $this->assertSame( $r2[1], $id ); 144 } 145 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Sep 15 01:00:50 2024 | Cross-referenced by PHPXref 0.7.1 |