[ Index ] |
PHP Cross Reference of BBPress |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * Tests for the user component favorite functions. 5 * 6 * @group users 7 * @group functions 8 * @group favorites 9 */ 10 class BBP_Tests_Users_Functions_Favorites extends BBP_UnitTestCase { 11 12 /** 13 * @covers ::bbp_get_topic_favoriters 14 */ 15 public function test_bbp_get_topic_favoriters() { 16 $u = $this->factory->user->create_many( 3 ); 17 $t = $this->factory->topic->create(); 18 19 // Add topic favorites. 20 bbp_add_user_favorite( $u[0], $t ); 21 bbp_add_user_favorite( $u[1], $t ); 22 23 $expected = array( $u[0], $u[1] ); 24 $favoriters = bbp_get_topic_favoriters( $t ); 25 26 $this->assertEqualSets( $expected, $favoriters ); 27 28 // Add topic favorites. 29 bbp_add_user_favorite( $u[2], $t ); 30 31 $expected = array( $u[0], $u[1], $u[2] ); 32 $favoriters = bbp_get_topic_favoriters( $t ); 33 34 $this->assertEqualSets( $expected, $favoriters ); 35 36 // Remove user favorite. 37 bbp_remove_user_favorite( $u[1], $t ); 38 39 $expected = array( $u[0], $u[2] ); 40 $favoriters = bbp_get_topic_favoriters( $t ); 41 42 $this->assertEqualSets( $expected, $favoriters ); 43 } 44 45 /** 46 * @covers ::bbp_get_user_favorites 47 */ 48 public function test_bbp_get_user_favorites() { 49 $u = $this->factory->user->create(); 50 $t = $this->factory->topic->create_many( 3 ); 51 52 // Add topic favorites. 53 bbp_add_user_favorite( $u, $t[0] ); 54 bbp_add_user_favorite( $u, $t[1] ); 55 bbp_add_user_favorite( $u, $t[2] ); 56 57 $expected = bbp_has_topics( array( 'post__in' => array( $t[0], $t[1], $t[2] ) ) ); 58 $favorites = bbp_get_user_favorites( $u ); 59 60 $this->assertEquals( $expected, $favorites ); 61 62 // Remove user favorite. 63 bbp_remove_user_favorite( $u, $t[1] ); 64 65 $expected = bbp_has_topics( array( 'post__in' => array( $t[0], $t[2] ) ) ); 66 $favorites = bbp_get_user_favorites( $u ); 67 68 $this->assertEquals( $expected, $favorites ); 69 } 70 71 /** 72 * @covers ::bbp_get_user_favorites_topic_ids 73 */ 74 public function test_bbp_get_user_favorites_topic_ids() { 75 $u = $this->factory->user->create(); 76 $t = $this->factory->topic->create_many( 3 ); 77 78 // Add topic favorites. 79 bbp_add_user_favorite( $u, $t[0] ); 80 bbp_add_user_favorite( $u, $t[1] ); 81 bbp_add_user_favorite( $u, $t[2] ); 82 83 $favorites = bbp_get_user_favorites_topic_ids( $u ); 84 85 $this->assertEqualSets( array( $t[0], $t[1], $t[2] ), $favorites ); 86 87 // Remove user favorite. 88 bbp_remove_user_favorite( $u, $t[1] ); 89 90 $favorites = bbp_get_user_favorites_topic_ids( $u ); 91 92 $this->assertEqualSets( array( $t[0], $t[2] ), $favorites ); 93 } 94 95 /** 96 * @covers ::bbp_is_user_favorite 97 */ 98 public function test_bbp_is_user_favorite() { 99 $u = $this->factory->user->create(); 100 $t = $this->factory->topic->create(); 101 102 $favorite = bbp_is_user_favorite( $u, $t ); 103 104 $this->assertFalse( $favorite ); 105 106 // Add topic favorite. 107 bbp_add_user_favorite( $u, $t ); 108 109 $favorite = bbp_is_user_favorite( $u, $t ); 110 111 $this->assertTrue( $favorite ); 112 } 113 114 /** 115 * @covers ::bbp_add_user_favorite 116 */ 117 public function test_bbp_add_user_favorite() { 118 $u = $this->factory->user->create(); 119 $t = $this->factory->topic->create_many( 3 ); 120 121 // Add topic favorites. 122 add_post_meta( $t[0], '_bbp_favorite', $u, false ); 123 124 // Add user favorite. 125 bbp_add_user_favorite( $u, $t[1] ); 126 127 $favorites = bbp_get_user_favorites_topic_ids( $u ); 128 129 $this->assertEqualSets( array( $t[0], $t[1] ), $favorites ); 130 131 // Add user favorite. 132 bbp_add_user_favorite( $u, $t[2] ); 133 134 $favorites = bbp_get_user_favorites_topic_ids( $u ); 135 136 $this->assertEqualSets( array( $t[0], $t[1], $t[2] ), $favorites ); 137 } 138 139 /** 140 * @covers ::bbp_remove_user_favorite 141 */ 142 public function test_bbp_remove_user_favorite() { 143 $u = $this->factory->user->create(); 144 $t = $this->factory->topic->create_many( 3 ); 145 146 // Add topic favorites. 147 foreach ( $t as $topic ) { 148 add_post_meta( $topic, '_bbp_favorite', $u ); 149 } 150 151 // Remove user favorite. 152 bbp_remove_user_favorite( $u, $t[2] ); 153 154 $favorites = bbp_get_user_favorites_topic_ids( $u ); 155 156 $this->assertEqualSets( array( $t[0], $t[1] ), $favorites ); 157 158 // Remove user favorite. 159 bbp_remove_user_favorite( $u, $t[1] ); 160 161 $favorites = bbp_get_user_favorites_topic_ids( $u ); 162 163 $this->assertEqualSets( array( $t[0] ), $favorites ); 164 } 165 166 /** 167 * @covers ::bbp_favorites_handler 168 * @todo Implement test_bbp_favorites_handler(). 169 */ 170 public function test_bbp_favorites_handler() { 171 // Remove the following lines when you implement this test. 172 $this->markTestIncomplete( 173 'This test has not been implemented yet.' 174 ); 175 } 176 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Oct 4 01:00:52 2024 | Cross-referenced by PHPXref 0.7.1 |