Changeset 13980 for trunk/tests/phpunit/includes/factory.php
- Timestamp:
- 07/27/2024 04:30:23 PM (2 years ago)
- File:
-
- 1 edited
-
trunk/tests/phpunit/includes/factory.php (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/includes/factory.php
r13874 r13980 2 2 #[AllowDynamicProperties] 3 3 class BP_UnitTest_Factory extends WP_UnitTest_Factory { 4 public $activity = null; 5 6 function __construct() { 4 public function __construct() { 7 5 parent::__construct(); 8 6 9 $this->user = new BP_UnitTest_Factory_For_User( $this );10 $this->activity = new BP_UnitTest_Factory_For_Activity( $this );11 $this->group = new BP_UnitTest_Factory_For_Group( $this );12 $this->message = new BP_UnitTest_Factory_For_Message( $this );7 $this->user = new BP_UnitTest_Factory_For_User( $this ); 8 $this->activity = new BP_UnitTest_Factory_For_Activity( $this ); 9 $this->group = new BP_UnitTest_Factory_For_Group( $this ); 10 $this->message = new BP_UnitTest_Factory_For_Message( $this ); 13 11 $this->xprofile_group = new BP_UnitTest_Factory_For_XProfileGroup( $this ); 14 12 $this->xprofile_field = new BP_UnitTest_Factory_For_XProfileField( $this ); 15 $this->notification = new BP_UnitTest_Factory_For_Notification( $this );16 $this->signup = new BP_UnitTest_Factory_For_Signup( $this );17 $this->friendship = new BP_UnitTest_Factory_For_Friendship( $this );13 $this->notification = new BP_UnitTest_Factory_For_Notification( $this ); 14 $this->signup = new BP_UnitTest_Factory_For_Signup( $this ); 15 $this->friendship = new BP_UnitTest_Factory_For_Friendship( $this ); 18 16 } 19 17 } … … 52 50 class BP_UnitTest_Factory_For_Activity extends WP_UnitTest_Factory_For_Thing { 53 51 54 function __construct( $factory = null ) {52 public function __construct( $factory = null ) { 55 53 parent::__construct( $factory ); 56 54 … … 64 62 } 65 63 66 function create_object( $args ) {67 if ( ! isset( $args['user_id'] ) ) 64 public function create_object( $args ) { 65 if ( ! isset( $args['user_id'] ) ) { 68 66 $args['user_id'] = get_current_user_id(); 67 } 69 68 70 69 return bp_activity_add( $args ); 71 70 } 72 71 73 function update_object( $activity_id, $fields ) {72 public function update_object( $activity_id, $fields ) { 74 73 $activity = new BP_Activity_Activity( $activity_id ); 75 74 76 75 foreach ( $fields as $field_name => $value ) { 77 if ( isset( $activity->$field_name ) ) 76 if ( isset( $activity->$field_name ) ) { 78 77 $activity->$field_name = $value; 78 } 79 79 } 80 80 81 81 $activity->save(); 82 82 83 return $activity; 83 84 } 84 85 85 function get_object_by_id( $user_id ) {86 public function get_object_by_id( $user_id ) { 86 87 return new BP_Activity_Activity( $user_id ); 87 88 } … … 90 91 class BP_UnitTest_Factory_For_Group extends WP_UnitTest_Factory_For_Thing { 91 92 92 function __construct( $factory = null ) {93 public function __construct( $factory = null ) { 93 94 parent::__construct( $factory ); 94 95 … … 104 105 } 105 106 106 function create_object( $args ) {107 public function create_object( $args ) { 107 108 if ( ! isset( $args['creator_id'] ) ) { 108 109 if ( is_user_logged_in() ) { … … 112 113 } else { 113 114 $last_activity = date( 'Y-m-d H:i:s', strtotime( bp_core_current_time() ) - 60 * 60 * 24 * 365 ); 114 $user_factory = new WP_UnitTest_Factory_For_User();115 115 $args['creator_id'] = $this->factory->user->create( array( 'role' => 'subscriber' ) ); 116 116 … … 138 138 } 139 139 140 function update_object( $group_id, $fields ) {140 public function update_object( $group_id, $fields ) { 141 141 $group = new BP_Groups_Group( $group_id ); 142 142 143 143 foreach ( $fields as $field_name => $value ) { 144 if ( isset( $group->field_name ) ) 144 if ( isset( $group->field_name ) ) { 145 145 $group->field_name = $value; 146 } 146 147 } 147 148 148 149 $group->save(); 150 149 151 return $group; 150 152 } 151 153 152 function get_object_by_id( $group_id ) {154 public function get_object_by_id( $group_id ) { 153 155 return new BP_Groups_Group( $group_id ); 154 156 } … … 157 159 class BP_UnitTest_Factory_For_Message extends WP_UnitTest_Factory_For_Thing { 158 160 159 function __construct( $factory = null ) {161 public function __construct( $factory = null ) { 160 162 parent::__construct( $factory ); 161 163 … … 169 171 } 170 172 171 function create_object( $args ) {173 public function create_object( $args ) { 172 174 if ( empty( $args['sender_id'] ) ) { 173 175 $args['sender_id'] = $this->factory->user->create(); … … 185 187 } 186 188 187 function update_object( $message_id, $fields ) { 188 // todo 189 } 190 191 function get_object_by_id( $message_id ) { 189 public function update_object( $message_id, $fields ) {} 190 191 public function get_object_by_id( $message_id ) { 192 192 return new BP_Messages_Message( $message_id ); 193 193 } … … 196 196 class BP_UnitTest_Factory_For_XProfileGroup extends WP_UnitTest_Factory_For_Thing { 197 197 198 function __construct( $factory = null ) {198 public function __construct( $factory = null ) { 199 199 parent::__construct( $factory ); 200 200 … … 206 206 } 207 207 208 function create_object( $args ) { 209 $group_id = xprofile_insert_field_group( $args ); 210 return $group_id; 211 } 212 213 function update_object( $group_id, $fields ) { 214 } 215 216 function get_object_by_id( $group_id ) { 208 public function create_object( $args ) { 209 return xprofile_insert_field_group( $args ); 210 } 211 212 public function update_object( $group_id, $fields ) {} 213 214 public function get_object_by_id( $group_id ) { 217 215 return new BP_XProfile_Group( $group_id ); 218 216 } … … 221 219 class BP_UnitTest_Factory_For_XProfileField extends WP_UnitTest_Factory_For_Thing { 222 220 223 function __construct( $factory = null ) {221 public function __construct( $factory = null ) { 224 222 parent::__construct( $factory ); 225 223 … … 231 229 } 232 230 233 function create_object( $args ) { 234 $field_id = xprofile_insert_field( $args ); 235 return $field_id; 236 } 237 238 function update_object( $field_id, $fields ) { 239 } 240 241 function get_object_by_id( $field_id ) { 231 public function create_object( $args ) { 232 return xprofile_insert_field( $args ); 233 } 234 235 public function update_object( $field_id, $fields ) {} 236 237 public function get_object_by_id( $field_id ) { 242 238 return new BP_XProfile_Field( $field_id ); 243 239 } … … 245 241 246 242 class BP_UnitTest_Factory_For_Notification extends WP_UnitTest_Factory_For_Thing { 247 public function __construct( $factory = null ) {248 parent::__construct( $factory );249 }250 251 243 public function create_object( $args ) { 252 244 return bp_notifications_add_notification( $args ); … … 261 253 262 254 class BP_UnitTest_Factory_For_Signup extends WP_UnitTest_Factory_For_Thing { 263 public function __construct( $factory = null ) {264 parent::__construct( $factory );265 }266 267 255 public function create_object( $args ) { 268 256 return BP_Signup::add( $args ); … … 282 270 */ 283 271 class BP_UnitTest_Factory_For_Friendship extends WP_UnitTest_Factory_For_Thing { 284 /** 285 * Constructor. 286 * 287 * @since 2.7.0 288 * 289 * @param $factory WP_UnitTest_Factory 290 */ 291 public function __construct( $factory = null ) { 292 parent::__construct( $factory ); 293 } 294 295 /** 296 * Create friendship object. 297 * 298 * @since 2.7.0 299 * 300 * @param array $args Array of arguments. 301 * @return int Friendship ID. 302 */ 272 303 273 public function create_object( $args ) { 304 274 $friendship = new BP_Friends_Friendship(); … … 323 293 } 324 294 325 /**326 * Update a friendship object.327 *328 * @since 2.7.0329 *330 * @todo Implement.331 *332 * @param int $id ID of the friendship.333 * @param array $fields Fields to update.334 */335 295 public function update_object( $id, $fields ) {} 336 296 337 /**338 * Get a friendship object by its ID.339 *340 * @since 2.7.0341 *342 * @param int $id343 * @return BP_Friends_Friendship344 */345 297 public function get_object_by_id( $id ) { 346 298 return new BP_Friends_Friendship( $id );
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)